Class: CloudConfig::Providers::AwsParameterStore

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

Overview

A class for fetching configuration from AWS Parameter Store

Examples:

provider = CloudConfig::Providers::AwsParameterStore.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 = {}) ⇒ AwsParameterStore

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

Parameters:

  • opts (Hash) (defaults to: {})

    Parameter store options

Options Hash (opts):

  • :with_decryption (Boolean)

    Whether all keys need to be decrypted



24
25
26
27
28
# File 'lib/cloud-config/providers/aws_parameter_store.rb', line 24

def initialize(opts = {})
  @client = Aws::SSM::Client.new

  @with_decryption = opts.fetch(:with_decryption, false)
end

Instance Attribute Details

#An instance of the AWS Parameter Store client(instanceoftheAWSParameterStoreclient) ⇒ Aws::SSM::Client (readonly)

Returns:

  • (Aws::SSM::Client)


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

attr_reader :client

#clientObject (readonly)

Returns the value of attribute client.



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

def client
  @client
end

#Whether parameters need to be decrypted(parametersneedtobedecrypted) ⇒ Boolean (readonly)

Returns:

  • (Boolean)


18
# File 'lib/cloud-config/providers/aws_parameter_store.rb', line 18

attr_reader :with_decryption

#with_decryptionObject (readonly)

Returns the value of attribute with_decryption.



18
19
20
# File 'lib/cloud-config/providers/aws_parameter_store.rb', line 18

def with_decryption
  @with_decryption
end

Instance Method Details

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

Fetch the value of the key

Parameters:

  • key (String, Symbol)

    Key to fetch

  • opts (Hash) (defaults to: {})

    for fetching the key

Options Hash (opts):

  • :with_decryption (Boolean)

    Whether the key needs decrypting

Returns:

  • (String)

    Value of the key



37
38
39
40
41
# File 'lib/cloud-config/providers/aws_parameter_store.rb', line 37

def get(key, opts = {})
  decrypt = opts.fetch(:with_decryption) { with_decryption }

  client.get_parameter(name: key, with_decryption: decrypt).parameter.value
end

#set(key, value) ⇒ Object

Set the value of the key

Parameters:

  • key (String, Symbol)

    Key to set

  • value (Object)

    Value of the key



47
48
49
# File 'lib/cloud-config/providers/aws_parameter_store.rb', line 47

def set(key, value)
  client.put_parameter(name: key, value:)
end