Class: CloudConfig::Providers::AwsSecretsManager

Inherits:
Object
  • Object
show all
Defined in:
lib/cloud-config/providers/aws_secrets_manager.rb

Overview

A class for fetching configuration from AWS Secrets Manager

Examples:

provider = CloudConfig::Providers::AwsSecretsManager.new # Assuming AWS credentials are already configured
provider.set(:example_key, :example_value)
provider.get(:example_key) #=> 'example_value'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(_opts = {}) ⇒ AwsSecretsManager

Create a new instance of CloudConfig::Providers::AwsSecretsManager.



17
18
19
# File 'lib/cloud-config/providers/aws_secrets_manager.rb', line 17

def initialize(_opts = {})
  @client = Aws::SecretsManager::Client.new
end

Instance Attribute Details

#An instance of the AWS Secrets Manager client(instanceoftheAWSSecretsManagerclient) ⇒ Aws::SSM::Client (readonly)

Returns:

  • (Aws::SSM::Client)


14
# File 'lib/cloud-config/providers/aws_secrets_manager.rb', line 14

attr_reader :client

#clientObject (readonly)

Returns the value of attribute client.



14
15
16
# File 'lib/cloud-config/providers/aws_secrets_manager.rb', line 14

def client
  @client
end

Instance Method Details

#get(key, _opts = {}) ⇒ String

Fetch the value of the key

Parameters:

  • key (String, Symbol)

    Key to fetch

Returns:

  • (String)

    Value of the key



26
27
28
29
30
# File 'lib/cloud-config/providers/aws_secrets_manager.rb', line 26

def get(key, _opts = {})
  secret = client.get_secret_value(secret_id: key)

  secret.secret_binary || secret.secret_string
end

#set(key, value) ⇒ Object

Set the value of the key

Parameters:

  • key (String, Symbol)

    Key to set

  • value (Object)

    Value of the key



36
37
38
# File 'lib/cloud-config/providers/aws_secrets_manager.rb', line 36

def set(key, value)
  client.put_secret_value(secret_id: key, secret_string: value)
end