Class: Kontena::Cli::Apps::YAML::ValidatorV2
- Inherits:
-
Object
- Object
- Kontena::Cli::Apps::YAML::ValidatorV2
- Includes:
- Validations
- Defined in:
- lib/kontena/cli/apps/yaml/validator_v2.rb
Instance Method Summary collapse
-
#initialize ⇒ ValidatorV2
constructor
A new instance of ValidatorV2.
-
#validate(yaml) ⇒ Array
Validation_errors.
Methods included from Validations
#common_validations, #optional, #validate_options
Constructor Details
#initialize ⇒ ValidatorV2
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.
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, | unless .is_a?(Hash) result[:errors] << { service => { 'options' => 'must be a mapping not a string'} } next end option_errors = () 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 |