Class: TerraspacePluginAws::Interfaces::Helper::Secret

Inherits:
SecretBase
  • Object
show all
Defined in:
lib/terraspace_plugin_aws/interfaces/helper/secret.rb

Instance Method Summary collapse

Methods inherited from SecretBase

#initialize

Methods included from Logging

#logger

Methods included from Clients

#dynamodb, #s3, #secretsmanager, #ssm, #sts

Constructor Details

This class inherits a constructor from TerraspacePluginAws::Interfaces::Helper::SecretBase

Instance Method Details

#fetch(secret_id) ⇒ Object



3
4
5
6
7
8
# File 'lib/terraspace_plugin_aws/interfaces/helper/secret.rb', line 3

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

#fetch_value(secret_id) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/terraspace_plugin_aws/interfaces/helper/secret.rb', line 10

def fetch_value(secret_id)
  secret_value = secretsmanager.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
rescue Aws::SecretsManager::Errors::ValidationException => e
  logger.info "WARN: secret_id #{secret_id} not found".color(:yellow)
  logger.info e.message
  "INVALID NAME #{secret_id}" # simple string so tfvars valid
end