Sha256: d3725df662557b3f4cd1ae488e261e9cfa13724e13a1d8cf23f4dbfe8e390c0d

Contents?: true

Size: 1.39 KB

Versions: 8

Compression:

Stored size: 1.39 KB

Contents

require 'yaml'

module Kontena::Cli::Apps
  module YAML
    class ServiceExtender
      attr_reader :service_config

      # @param [Hash] service_config
      def initialize(service_config)
        @service_config = service_config
      end

      # @param [Hash] from
      # @return [Hash]
      def extend(from)
        service_config['environment'] = extend_env_vars(
          from['environment'],
          service_config['environment']
        )
        service_config['secrets'] = extend_secrets(
          from['secrets'],
          service_config['secrets']
        )
        from.merge(service_config)
      end

      private

      # @param [Array] from
      # @param [Array] to
      # @return [Array]
      def extend_env_vars(from, to)
        env_vars = to || []
        if from
          from.each do |env|
            env_vars << env unless to && to.find do |key|
              key.split('=').first == env.split('=').first
            end
          end
        end
        env_vars
      end

      # @param [Array] from
      # @param [Array] to
      # @return [Array]
      def extend_secrets(from, to)
        secrets = to || []
        if from
          from.each do |from_secret|
            secrets << from_secret unless to && to.any? do |to_secret|
              to_secret['secret'] == from_secret['secret']
            end
          end
        end
        secrets
      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/service_extender.rb
kontena-cli-0.14.6 lib/kontena/cli/apps/yaml/service_extender.rb
kontena-cli-0.14.5 lib/kontena/cli/apps/yaml/service_extender.rb
kontena-cli-0.14.4 lib/kontena/cli/apps/yaml/service_extender.rb
kontena-cli-0.14.3 lib/kontena/cli/apps/yaml/service_extender.rb
kontena-cli-0.14.2 lib/kontena/cli/apps/yaml/service_extender.rb
kontena-cli-0.14.1 lib/kontena/cli/apps/yaml/service_extender.rb
kontena-cli-0.14.0 lib/kontena/cli/apps/yaml/service_extender.rb