Class: StratoEnv::SSMFetcher

Inherits:
Object
  • Object
show all
Defined in:
lib/strato_env/ssm_fetcher.rb

Overview

SSM Parameter Store implementation of the fetcher protocol used by StratoEnv.

Given a path, returns a Hash<String, String> mapping each parameter’s basename (last path component) to its value. Pages are followed transparently and SecureString values are decrypted by default.

Examples:

fetcher = StratoEnv::SSMFetcher.new(recursive: true)
fetcher.call("/myapp/")
# => { "DATABASE_URL" => "postgres://...", "REDIS_URL" => "redis://..." }

Instance Method Summary collapse

Constructor Details

#initialize(client: nil, recursive: false, with_decryption: true) ⇒ SSMFetcher

Returns a new instance of SSMFetcher.

Parameters:

  • client (Aws::SSM::Client, nil) (defaults to: nil)

    an SSM client. Defaults to a new Aws::SSM::Client configured from the ambient AWS environment.

  • recursive (Boolean) (defaults to: false)

    whether to fetch parameters nested beneath the given path. Defaults to false to match the common one-level layout.

  • with_decryption (Boolean) (defaults to: true)

    decrypt SecureString parameters in flight. Defaults to true.



22
23
24
25
26
# File 'lib/strato_env/ssm_fetcher.rb', line 22

def initialize(client: nil, recursive: false, with_decryption: true)
  @client = client || Aws::SSM::Client.new
  @recursive = recursive
  @with_decryption = with_decryption
end

Instance Method Details

#call(path) ⇒ Hash<String, String>

Fetch all parameters under a single SSM path.

Parameters:

  • path (String)

    the SSM path to query (typically with a trailing slash).

Returns:

  • (Hash<String, String>)

    parameter basenames mapped to their values.



32
33
34
35
36
37
38
# File 'lib/strato_env/ssm_fetcher.rb', line 32

def call(path)
  @client.get_parameters_by_path(
    path: path, recursive: @recursive, with_decryption: @with_decryption
  ).each_page.flat_map(&:parameters).to_h do |param|
    [param.name.split("/").last, param.value]
  end
end