Sha256: 6948cdecaa4cbd60d35bca99a179221ca72100927d05b8d40c9459be6f671ccb

Contents?: true

Size: 1.84 KB

Versions: 16

Compression:

Stored size: 1.84 KB

Contents

require 'dry-validation'
module Kontena::Cli::Apps
  module YAML
    class Validator
      require_relative 'validations'
      include Validations

      VALID_KEYS = %w(
      affinity build dockerfile cap_add cap_drop command deploy env_file environment extends external_links
      image links log_driver log_opt net pid ports volumes volumes_from cpu_shares
      mem_limit memswap_limit privileged stateful user instances hooks secrets health_check
      ).freeze

      UNSUPPORTED_KEYS = %w(
      cgroup_parent container_name devices depends_on dns dns_search tmpfs entrypoint
      expose extra_hosts labels logging network_mode networks security_opt stop_signal ulimits volume_driver
      cpu_quota cpuset domainname hostname ipc mac_address
      read_only restart shm_size stdin_open tty working_dir
      ).freeze

      ##
      # rubocop:disable Metrics/MethodLength,Metrics/AbcSize
      def initialize(need_image=false)
        base = self
        @yaml_schema = Dry::Validation.Schema do
          base.append_common_validations(self)

          optional('build').value(:str?)
          optional('dockerfile').value(:str?)
          optional('net').value(included_in?: (%w(host bridge)))
          optional('log_driver').value(:str?)
          optional('log_opts').value(type?: Hash)
        end
      end

      ##
      # @param [Hash] yaml
      # @return [Array] validation_errors
      def validate(yaml)
        result = {
          errors: [],
          notifications: []
        }

        yaml.each do |service, options|
          key_errors = validate_keys(options)
          option_errors = validate_options(options)
          result[:errors] << { service => option_errors.messages } if option_errors.failure?
          result[:notifications] << { service => key_errors } if key_errors.size > 0
        end
        result
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
kontena-cli-0.16.0.pre5 lib/kontena/cli/apps/yaml/validator.rb
kontena-cli-0.16.0.pre4 lib/kontena/cli/apps/yaml/validator.rb
kontena-cli-0.16.0.pre3 lib/kontena/cli/apps/yaml/validator.rb
kontena-cli-0.16.0.pre2 lib/kontena/cli/apps/yaml/validator.rb
kontena-cli-0.16.0.pre1 lib/kontena/cli/apps/yaml/validator.rb
kontena-cli-0.15.4 lib/kontena/cli/apps/yaml/validator.rb
kontena-cli-0.15.4.rc2 lib/kontena/cli/apps/yaml/validator.rb
kontena-cli-0.15.4.rc1 lib/kontena/cli/apps/yaml/validator.rb
kontena-cli-0.15.4.pre1 lib/kontena/cli/apps/yaml/validator.rb
kontena-cli-0.15.3 lib/kontena/cli/apps/yaml/validator.rb
kontena-cli-0.15.2 lib/kontena/cli/apps/yaml/validator.rb
kontena-cli-0.15.1 lib/kontena/cli/apps/yaml/validator.rb
kontena-cli-0.15.0 lib/kontena/cli/apps/yaml/validator.rb
kontena-cli-0.15.0.rc3 lib/kontena/cli/apps/yaml/validator.rb
kontena-cli-0.15.0.rc2 lib/kontena/cli/apps/yaml/validator.rb
kontena-cli-0.15.0.rc1 lib/kontena/cli/apps/yaml/validator.rb