Class: SecretsManager::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/secrets_manager/client.rb

Instance Method Summary collapse

Instance Method Details

#aws_error(secret_id) ⇒ Object



28
29
30
# File 'lib/secrets_manager/client.rb', line 28

def aws_error(secret_id)
  puts "Could not retrieve \"#{secret_id}\" secret from AWS. Please check you configured everything correctly."
end

#clientObject



5
6
7
# File 'lib/secrets_manager/client.rb', line 5

def client
  @client ||= Aws::SecretsManager::Client.new
end

#get_secret_hash(secret_id) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/secrets_manager/client.rb', line 15

def get_secret_hash(secret_id)
  return if (secret_string = get_secret_string(secret_id)).nil?

  JSON.parse(secret_string)
rescue JSON::ParserError
  json_parsing_error(secret_id)
end

#get_secret_string(secret_id) ⇒ Object



9
10
11
12
13
# File 'lib/secrets_manager/client.rb', line 9

def get_secret_string(secret_id)
  client.get_secret_value(secret_id: secret_id).secret_string
rescue Aws::SecretsManager::Errors::ServiceError
  aws_error(secret_id)
end

#json_parsing_error(secret_id) ⇒ Object



23
24
25
26
# File 'lib/secrets_manager/client.rb', line 23

def json_parsing_error(secret_id)
  puts "Could not parse JSON in \"#{secret_id}\" secret. Please check your secret contents."
  puts 'You can also define your secret type as "plaintext".'
end