Sha256: ca338dd1555ae79f65ad2e968639d2d6e51ff0fb1ca9ec81e0f77d9a4eb83cfc

Contents?: true

Size: 1.81 KB

Versions: 8

Compression:

Stored size: 1.81 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
      ).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').maybe(:str?)
          optional('dockerfile') { str? }
          optional('net') { inclusion?(%w(host bridge)) }
          optional('log_driver') { str? }
          optional('log_opts') { 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

8 entries across 8 versions & 1 rubygems

Version Path
kontena-cli-0.14.7 lib/kontena/cli/apps/yaml/validator.rb
kontena-cli-0.14.6 lib/kontena/cli/apps/yaml/validator.rb
kontena-cli-0.14.5 lib/kontena/cli/apps/yaml/validator.rb
kontena-cli-0.14.4 lib/kontena/cli/apps/yaml/validator.rb
kontena-cli-0.14.3 lib/kontena/cli/apps/yaml/validator.rb
kontena-cli-0.14.2 lib/kontena/cli/apps/yaml/validator.rb
kontena-cli-0.14.1 lib/kontena/cli/apps/yaml/validator.rb
kontena-cli-0.14.0 lib/kontena/cli/apps/yaml/validator.rb