Class: KeyRestrictionValidator

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

Constant Summary collapse

FORBIDDEN =
-1
ALLOWED =
0

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.supported_key_restrictions(type) ⇒ Object


11
12
13
14
15
16
17
# File 'app/validators/key_restriction_validator.rb', line 11

def self.supported_key_restrictions(type)
  if Gitlab::FIPS.enabled?
    [*supported_sizes(type), FORBIDDEN]
  else
    [ALLOWED, *supported_sizes(type), FORBIDDEN]
  end
end

.supported_sizes(type) ⇒ Object


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

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

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object


19
20
21
22
23
# File 'app/validators/key_restriction_validator.rb', line 19

def validate_each(record, attribute, value)
  unless valid_restriction?(value)
    record.errors.add(attribute, "must be #{supported_sizes_message}")
  end
end