Class: Kontena::Cli::Apps::YAML::ValidatorV2

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

Instance Method Summary collapse

Methods included from Validations

#common_validations, #optional, #validate_options

Constructor Details

#initializeValidatorV2

Returns a new instance of ValidatorV2.



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/kontena/cli/apps/yaml/validator_v2.rb', line 10

def initialize
  @schema = common_validations
  @schema['build'] = optional('valid_build')
  @schema['depends_on'] = optional('array')
  @schema['network_mode'] = optional(%w(host bridge))
  @schema['logging'] = optional({
    'driver' => optional('string'),
    'options' => optional(-> (value) { value.is_a?(Hash) })
    })
  Validations::CustomValidators.load
end

Instance Method Details

#validate(yaml) ⇒ Array

Returns validation_errors.

Parameters:

  • yaml (Hash)
  • strict (TrueClass|FalseClass)

Returns:

  • (Array)

    validation_errors



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/kontena/cli/apps/yaml/validator_v2.rb', line 26

def validate(yaml)
  result = {
    errors: [],
    notifications: []
  }
  if yaml.key?('services')
    yaml['services'].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
  else
    result[:errors] << { 'file' => 'services missing' }
  end
  if yaml.key?('volumes')
    result[:notifications] << { 'volumes' => 'Kontena does not support volumes yet. To persist data just define service as stateful (stateful: true)' }
  end
  if yaml.key?('networks')
    result[:notifications] << { 'networks' => 'Kontena does not support multiple networks yet. You can reference services with Kontena\'s internal DNS (service_name.kontena.local)' }
  end
  result
end