Class: Kontena::Cli::Apps::YAML::Validator

Inherits:
Object
  • Object
show all
Includes:
Validations
Defined in:
lib/kontena/cli/apps/yaml/validator.rb

Instance Method Summary collapse

Methods included from Validations

#common_validations, #optional, #validate_options

Constructor Details

#initialize(need_image = false) ⇒ Validator

Returns a new instance of Validator.



8
9
10
11
12
13
14
15
16
# File 'lib/kontena/cli/apps/yaml/validator.rb', line 8

def initialize(need_image=false)
  @schema = common_validations
  @schema['build'] = optional('string')
  @schema['dockerfile'] = optional('string')
  @schema['net'] = optional(%w(host bridge))
  @schema['log_driver'] = optional('string')
  @schema['log_opts'] = optional({})
  Validations::CustomValidators.load
end

Instance Method Details

#validate(yaml) ⇒ Array

Returns validation_errors.

Parameters:

  • yaml (Hash)

Returns:

  • (Array)

    validation_errors



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/kontena/cli/apps/yaml/validator.rb', line 21

def validate(yaml)
  result = {
    errors: [],
    notifications: []
  }
  yaml.each do |service, options|
    unless options.is_a?(Hash)
      result[:errors] << { service => { 'options' => 'must be a mapping not a string'}  }
      next
    end
    option_errors = validate_options(options)
    result[:errors] << { service => option_errors.errors } unless option_errors.valid?
  end
  result
end