Class: KubesAws::SSM::Fetcher

Inherits:
Object
  • Object
show all
Includes:
Logging, KubesAws::Services
Defined in:
lib/kubes_aws/ssm/fetcher.rb

Instance Method Summary collapse

Methods included from KubesAws::Services

#eks, #iam, #secrets, #ssm

Methods included from Logging

#logger

Constructor Details

#initialize(options = {}) ⇒ Fetcher

Returns a new instance of Fetcher.



6
7
8
9
# File 'lib/kubes_aws/ssm/fetcher.rb', line 6

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

Instance Method Details

#base64?(type) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
21
22
23
24
# File 'lib/kubes_aws/ssm/fetcher.rb', line 18

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

#fetch(name) ⇒ Object



11
12
13
14
15
16
# File 'lib/kubes_aws/ssm/fetcher.rb', line 11

def fetch(name)
  parameter = fetch_parameter(name)
  value = parameter.value
  value = Base64.strict_encode64(value).strip if base64?(parameter.type)
  value
end

#fetch_parameter(name) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/kubes_aws/ssm/fetcher.rb', line 26

def fetch_parameter(name)
  resp = ssm.get_parameter(name: name, with_decryption: true)
  resp.parameter
rescue Aws::SSM::Errors::ParameterNotFound => e
  logger.info "WARN: name #{name} not found".color(:yellow)
  logger.info e.message
  "NOT FOUND #{name}" # simple string so Kubernetes YAML is valid
end