Module: Autosign::Validator

Defined in:
lib/autosign/validator.rb,
lib/autosign/validator/jwt.rb,
lib/autosign/validator/multiplexer.rb,
lib/autosign/validator/passwordlist.rb,
lib/autosign/validator/validator_base.rb

Defined Under Namespace

Classes: JWT, Multiplexer, Passwordlist, ValidatorBase

Class Method Summary collapse

Class Method Details

.any_validator(challenge_password, certname, raw_csr, settings = Autosign::Config.new.settings) ⇒ Boolean

Class method to attempt validation of a request against all validators which inherit from this class. The request is considered to be validated if any one validator succeeds. The first validator to pass shorts the validation process so other validators are not called.



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/autosign/validator.rb', line 34

def self.any_validator(challenge_password, certname, raw_csr, settings = Autosign::Config.new.settings)
  @log = Logging.logger[self.class]
  # find the first validator that passes and return the class
  validator = validation_order(settings).find { |c| c.new(settings).validate(challenge_password, certname, raw_csr) }
  if validator
    @log.info "Successfully validated using #{validator::NAME}"
    true
  else
    @log.info 'unable to validate using any validator'
    false
  end
end

.validation_order(settings = Autosign::Config.new.settings, list = nil) ⇒ Array

This returns a list of validators that were specified by the user and the exact order they want the validation to procede.



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/autosign/validator.rb', line 12

def self.validation_order(settings = Autosign::Config.new.settings, list = nil)
  validation_order = list || settings['general']['validation_order']
  # create a key pair where the key is the name of the validator and value is the class
  validator_list = validator_classes.each_with_object({}) do |klass, acc|
    acc[klass::NAME] = klass
    acc
  end
  # filter out validators that do not exist
  order = validation_order.map { |v| validator_list.fetch(v, nil) }.compact
  @log = Logging.logger[self.class]
  @log.debug("Validator order: #{order.inspect}")
  order
end

.validator_classesArray

Find other classes that inherit from this class. Used to discover autosign validators. There is probably no reason to use this directly.



53
54
55
56
# File 'lib/autosign/validator.rb', line 53

def self.validator_classes
  validators = Dir.glob(File.join(__dir__, 'validator', '*')).sort.each {|k| require k }
  ObjectSpace.each_object(Class).select { |klass| klass < Autosign::Validator::ValidatorBase }
end