Class: Knowledge::Adapters::Ssm

Inherits:
Base
  • Object
show all
Defined in:
lib/knowledge/adapters/ssm.rb

Overview

Description ===

This adapter takes some vars in your SSM parameters and set it in your project’s config.

Usage ===

@example:

adapter = Knowledge::Adapters::Ssm.new(params: { root_path: '/path', setter: MySetter, variables: my_vars)

adapter.run

Attributes ===

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params: {}, setter:, variables:) ⇒ Ssm

Constructor =================================================================================================

Parameters:

  • :params (Hash)
  • :variables (Hash)
  • :setter (Class)
  • params (Hash) (defaults to: {})

    a customizable set of options

Options Hash (params:):

  • :client (Aws::SSM::Client)
  • :raise_on_parameter_not_found (Boolean)
  • :root_path (String)


44
45
46
47
48
49
50
51
# File 'lib/knowledge/adapters/ssm.rb', line 44

def initialize(params: {}, setter:, variables:)
  super

  @client = params[:client] || params['client']
  @raise_not_found = params[:raise_on_parameter_not_found] || params['raise_on_parameter_not_found'] || false
  @root_path = params[:root_path] || params['root_path']
  @ssm_parameters = @root_path ? fetch_recursive_parameters : fetch_parameters
end

Instance Attribute Details

#raise_not_foundObject (readonly)

Attributes ==================================================================================================



31
32
33
# File 'lib/knowledge/adapters/ssm.rb', line 31

def raise_not_found
  @raise_not_found
end

#root_pathObject (readonly)

Attributes ==================================================================================================



31
32
33
# File 'lib/knowledge/adapters/ssm.rb', line 31

def root_path
  @root_path
end

#setterClass (readonly)

Returns the current value of setter.

Returns:

  • (Class)

    the current value of setter



31
32
33
# File 'lib/knowledge/adapters/ssm.rb', line 31

def setter
  @setter
end

#ssm_parametersObject (readonly)

Attributes ==================================================================================================



31
32
33
# File 'lib/knowledge/adapters/ssm.rb', line 31

def ssm_parameters
  @ssm_parameters
end

#variablesHash (readonly)

Returns the current value of variables.

Returns:

  • (Hash)

    the current value of variables



31
32
33
# File 'lib/knowledge/adapters/ssm.rb', line 31

def variables
  @variables
end

Instance Method Details

#runObject

Instance Methods ============================================================================================

Description ===

Runs the actual adapter.



59
60
61
62
63
64
65
66
67
# File 'lib/knowledge/adapters/ssm.rb', line 59

def run
  variables.each do |name, path|
    base_path = root_path[0..-2] if root_path&.end_with?('/')
    path = "/#{path.sub('/', '')}"
    value = Array(@ssm_parameters).detect { |p| p.name == "#{base_path}#{path}" }&.value

    setter.set(name: name, value: value)
  end
end