class Kontena::Cli::Apps::YAML::Validator

Public Class Methods

new(need_image=false) click to toggle source
# 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

Public Instance Methods

validate(yaml) click to toggle source

@param [Hash] yaml @return [Array] validation_errors

# 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