Class: KubesAws::Secrets::Fetcher

Inherits:
Object
  • Object
show all
Includes:
Logging, KubesAws::Services
Defined in:
lib/kubes_aws/secrets/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/secrets/fetcher.rb', line 6

def initialize(options={})
  @options = options
  @base64 = options[:base64].nil? ? true : options[:base64]
end

Instance Method Details

#fetch(secret_id) ⇒ Object



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

def fetch(secret_id)
  value = fetch_value(secret_id)
  value = Base64.strict_encode64(value).strip if @base64
  value
end

#fetch_value(secret_id) ⇒ Object



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

def fetch_value(secret_id)
  secret_value = secrets.get_secret_value(secret_id: secret_id)
  secret_value.secret_string
rescue Aws::SecretsManager::Errors::ResourceNotFoundException => e
  logger.info "WARN: secret_id #{secret_id} not found".color(:yellow)
  logger.info e.message
  "NOT FOUND #{secret_id}" # simple string so Kubernetes YAML is valid
end