Sha256: 39903ea3b1e9a4555f22943d440cdc0c81d18290f656b105edcf1d2fd8354520

Contents?: true

Size: 1.08 KB

Versions: 86

Compression:

Stored size: 1.08 KB

Contents

require 'hash_validator'
module Kontena::Cli::Apps
  module YAML
    class Validator
      require_relative 'validations'
      include Validations

      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

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

Version data entries

86 entries across 86 versions & 2 rubygems

Version Path
kontena-cli-1.3.5 lib/kontena/cli/apps/yaml/validator.rb
kontena-cli-1.3.5.rc1 lib/kontena/cli/apps/yaml/validator.rb
kontena-plugin-app-command-0.1.0 lib/kontena/cli/apps/yaml/validator.rb
kontena-plugin-app-command-0.1.0.rc1 lib/kontena/cli/apps/yaml/validator.rb
kontena-cli-1.4.0.pre6 lib/kontena/cli/apps/yaml/validator.rb
kontena-cli-1.4.0.pre5 lib/kontena/cli/apps/yaml/validator.rb
kontena-cli-1.4.0.pre4 lib/kontena/cli/apps/yaml/validator.rb
kontena-cli-1.4.0.pre3 lib/kontena/cli/apps/yaml/validator.rb
kontena-cli-1.4.0.pre2 lib/kontena/cli/apps/yaml/validator.rb
kontena-cli-1.4.0.pre1 lib/kontena/cli/apps/yaml/validator.rb
kontena-cli-1.3.4 lib/kontena/cli/apps/yaml/validator.rb
kontena-cli-1.3.4.rc1 lib/kontena/cli/apps/yaml/validator.rb
kontena-cli-1.3.3 lib/kontena/cli/apps/yaml/validator.rb
kontena-cli-1.3.3.rc1 lib/kontena/cli/apps/yaml/validator.rb
kontena-cli-1.3.2 lib/kontena/cli/apps/yaml/validator.rb
kontena-cli-1.3.2.rc2 lib/kontena/cli/apps/yaml/validator.rb
kontena-cli-1.3.2.rc1 lib/kontena/cli/apps/yaml/validator.rb
kontena-cli-1.3.1 lib/kontena/cli/apps/yaml/validator.rb
kontena-cli-1.3.1.rc2 lib/kontena/cli/apps/yaml/validator.rb
kontena-cli-1.3.1.rc1 lib/kontena/cli/apps/yaml/validator.rb