Sha256: ebb22bdda955215182756a12ad4a752c8b99ddbe6102eb46693944ac5d75f36b

Contents?: true

Size: 1.77 KB

Versions: 48

Compression:

Stored size: 1.77 KB

Contents

require 'hash_validator'

module Kontena::Cli::Stacks
  module YAML
    class ValidatorV3
      require_relative 'validations'
      include Validations

      def initialize
        @schema = common_validations
        @schema['build'] = optional('stacks_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

      ##
      # @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

48 entries across 48 versions & 1 rubygems

Version Path
kontena-cli-1.1.6 lib/kontena/cli/stacks/yaml/validator_v3.rb
kontena-cli-1.2.0.pre1 lib/kontena/cli/stacks/yaml/validator_v3.rb
kontena-cli-1.1.5 lib/kontena/cli/stacks/yaml/validator_v3.rb
kontena-cli-1.1.5.rc3 lib/kontena/cli/stacks/yaml/validator_v3.rb
kontena-cli-1.1.5.rc2 lib/kontena/cli/stacks/yaml/validator_v3.rb
kontena-cli-1.1.5.rc1 lib/kontena/cli/stacks/yaml/validator_v3.rb
kontena-cli-1.1.4 lib/kontena/cli/stacks/yaml/validator_v3.rb
kontena-cli-1.2.0.dev1 lib/kontena/cli/stacks/yaml/validator_v3.rb
kontena-cli-1.1.3 lib/kontena/cli/stacks/yaml/validator_v3.rb
kontena-cli-1.1.2 lib/kontena/cli/stacks/yaml/validator_v3.rb
kontena-cli-1.1.2.rc2 lib/kontena/cli/stacks/yaml/validator_v3.rb
kontena-cli-1.1.2.rc1 lib/kontena/cli/stacks/yaml/validator_v3.rb
kontena-cli-1.1.1 lib/kontena/cli/stacks/yaml/validator_v3.rb
kontena-cli-1.1.1.rc1 lib/kontena/cli/stacks/yaml/validator_v3.rb
kontena-cli-1.1.0 lib/kontena/cli/stacks/yaml/validator_v3.rb
kontena-cli-1.1.0.rc2 lib/kontena/cli/stacks/yaml/validator_v3.rb
kontena-cli-1.1.0.rc1 lib/kontena/cli/stacks/yaml/validator_v3.rb
kontena-cli-1.1.0.pre1 lib/kontena/cli/stacks/yaml/validator_v3.rb
kontena-cli-1.0.6 lib/kontena/cli/stacks/yaml/validator_v3.rb
kontena-cli-1.0.6.rc1 lib/kontena/cli/stacks/yaml/validator_v3.rb