Sha256: 12b6360308020f559a2519a735f098ef85c2007e977b2ad666780f998df6e845

Contents?: true

Size: 1.75 KB

Versions: 14

Compression:

Stored size: 1.75 KB

Contents

require 'hash_validator'
require_relative 'validator'

module Kontena::Cli::Apps
  module YAML
    class ValidatorV2
      require_relative 'validations'
      include Validations

      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) })
          })
      end

      ##
      # @param [Hash] yaml
      # @param [TrueClass|FalseClass] strict
      # @return [Array] validation_errors
      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
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
kontena-cli-0.16.3 lib/kontena/cli/apps/yaml/validator_v2.rb
kontena-cli-0.16.3.rc1 lib/kontena/cli/apps/yaml/validator_v2.rb
kontena-cli-0.16.2 lib/kontena/cli/apps/yaml/validator_v2.rb
kontena-cli-0.16.2.rc1 lib/kontena/cli/apps/yaml/validator_v2.rb
kontena-cli-0.16.1 lib/kontena/cli/apps/yaml/validator_v2.rb
kontena-cli-0.16.1.rc3 lib/kontena/cli/apps/yaml/validator_v2.rb
kontena-cli-0.16.1.rc2 lib/kontena/cli/apps/yaml/validator_v2.rb
kontena-cli-0.16.1.rc1 lib/kontena/cli/apps/yaml/validator_v2.rb
kontena-cli-0.16.0 lib/kontena/cli/apps/yaml/validator_v2.rb
kontena-cli-0.16.0.rc3 lib/kontena/cli/apps/yaml/validator_v2.rb
kontena-cli-0.16.0.rc2 lib/kontena/cli/apps/yaml/validator_v2.rb
kontena-cli-0.16.0.rc1 lib/kontena/cli/apps/yaml/validator_v2.rb
kontena-cli-0.16.0.pre9 lib/kontena/cli/apps/yaml/validator_v2.rb
kontena-cli-0.16.0.pre8 lib/kontena/cli/apps/yaml/validator_v2.rb