Class: Dev::Aws::Parameter

Inherits:
Object show all
Defined in:
lib/firespring_dev_commands/aws/parameter.rb

Overview

Class containing methods for get/put ssm parameters in Aws

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeParameter

Returns a new instance of Parameter.



9
10
11
# File 'lib/firespring_dev_commands/aws/parameter.rb', line 9

def initialize
  @client = ::Aws::SSM::Client.new
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



7
8
9
# File 'lib/firespring_dev_commands/aws/parameter.rb', line 7

def client
  @client
end

Instance Method Details

#get(name, with_decryption: true) ⇒ Object

Retrieve the ssm parameter object with the given name



19
20
21
22
23
# File 'lib/firespring_dev_commands/aws/parameter.rb', line 19

def get(name, with_decryption: true)
  client.get_parameter(name:, with_decryption:)&.parameter
rescue ::Aws::SSM::Errors::ParameterNotFound
  raise "parameter #{name} does not exist in #{Dev::Aws::Profile.new.current}"
end

#get_value(name, with_decryption: true) ⇒ Object

Get the value of the given parameter name



14
15
16
# File 'lib/firespring_dev_commands/aws/parameter.rb', line 14

def get_value(name, with_decryption: true)
  get(name, with_decryption:)&.value
end

#list(path, recursive: true, with_decryption: true) ⇒ Object

Retrieve all parameters which start with the given path



26
27
28
29
30
31
32
33
# File 'lib/firespring_dev_commands/aws/parameter.rb', line 26

def list(path, recursive: true, with_decryption: true)
  [].tap do |ary|
    params = {path:, recursive:, with_decryption:}
    Dev::Aws.each_page(client, :get_parameters_by_path, params) do |response|
      ary.concat(response.parameters)
    end
  end
end

#put(name, value, **params) ⇒ Object

Sets the given parameter name’s value to the given value Pass in additional params as desired



37
38
39
40
41
# File 'lib/firespring_dev_commands/aws/parameter.rb', line 37

def put(name, value, **params)
  params[:type] ||= 'String'
  params[:overwrite] ||= true
  client.put_parameter(name:, value:, **params)
end