Sha256: a315c23caf3fd94a43248561ff6954a5cfdc7879f5168e531ddbede5cee292cc

Contents?: true

Size: 1 KB

Versions: 36

Compression:

Stored size: 1 KB

Contents

module Ufo::TaskDefinition::Helpers::Ssm
  class Fetcher
    include Ufo::AwsServices
    include Ufo::Utils::Logging
    include Ufo::Concerns::Names

    def initialize(options={})
      @options = options
      @base64 = options[:base64]
    end

    def fetch(name)
      name = names.expansion(name, dasherize: false)
      parameter = fetch_parameter(name)
      return unless parameter
      value = parameter.value
      value = Base64.strict_encode64(value).strip if base64?(parameter.type)
      value
    end

    def base64?(type)
      if @base64.nil?
        type == "SecureString"
      else
        @base64
      end
    end

    # Note: Cannot use logger if since if ssm helper is used in config it'll cause an infinite loop
    def fetch_parameter(name)
      resp = ssm_client.get_parameter(name: name, with_decryption: true)
      resp.parameter
    rescue Aws::SSM::Errors::ParameterNotFound => e
      puts "WARN: name #{name} not found".color(:yellow)
      puts e.message
      nil
    end
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
ufo-6.3.13 lib/ufo/task_definition/helpers/ssm/fetcher.rb
ufo-6.3.12 lib/ufo/task_definition/helpers/ssm/fetcher.rb
ufo-6.3.11 lib/ufo/task_definition/helpers/ssm/fetcher.rb
ufo-6.3.10 lib/ufo/task_definition/helpers/ssm/fetcher.rb
ufo-6.3.9 lib/ufo/task_definition/helpers/ssm/fetcher.rb
ufo-6.3.8 lib/ufo/task_definition/helpers/ssm/fetcher.rb
ufo-6.3.7 lib/ufo/task_definition/helpers/ssm/fetcher.rb
ufo-6.3.6 lib/ufo/task_definition/helpers/ssm/fetcher.rb
ufo-6.3.5 lib/ufo/task_definition/helpers/ssm/fetcher.rb
ufo-6.3.4 lib/ufo/task_definition/helpers/ssm/fetcher.rb
ufo-6.3.3 lib/ufo/task_definition/helpers/ssm/fetcher.rb
ufo-6.3.2 lib/ufo/task_definition/helpers/ssm/fetcher.rb
ufo-6.3.1 lib/ufo/task_definition/helpers/ssm/fetcher.rb
ufo-6.3.0 lib/ufo/task_definition/helpers/ssm/fetcher.rb
ufo-6.2.5 lib/ufo/task_definition/helpers/ssm/fetcher.rb
ufo-6.2.4 lib/ufo/task_definition/helpers/ssm/fetcher.rb
ufo-6.2.3 lib/ufo/task_definition/helpers/ssm/fetcher.rb
ufo-6.2.2 lib/ufo/task_definition/helpers/ssm/fetcher.rb
ufo-6.2.1 lib/ufo/task_definition/helpers/ssm/fetcher.rb
ufo-6.2.0 lib/ufo/task_definition/helpers/ssm/fetcher.rb