Class: KeyRestrictionValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
app/validators/key_restriction_validator.rb

Constant Summary collapse

FORBIDDEN =
-1

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.supported_key_restrictions(type) ⇒ Object


10
11
12
# File 'app/validators/key_restriction_validator.rb', line 10

def self.supported_key_restrictions(type)
  [0, *supported_sizes(type), FORBIDDEN]
end

.supported_sizes(type) ⇒ Object


6
7
8
# File 'app/validators/key_restriction_validator.rb', line 6

def self.supported_sizes(type)
  Gitlab::SSHPublicKey.supported_sizes(type)
end

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object


14
15
16
17
18
# File 'app/validators/key_restriction_validator.rb', line 14

def validate_each(record, attribute, value)
  unless valid_restriction?(value)
    record.errors.add(attribute, "must be forbidden, allowed, or one of these sizes: #{supported_sizes_message}")
  end
end