Class: SsmEnv::Fetcher

Inherits:
Object
  • Object
show all
Defined in:
lib/ssm_env/fetcher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Fetcher

Returns a new instance of Fetcher.



8
9
10
# File 'lib/ssm_env/fetcher.rb', line 8

def initialize(client: )
  @client = client
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



6
7
8
# File 'lib/ssm_env/fetcher.rb', line 6

def client
  @client
end

#ssm_paramsObject

Returns the value of attribute ssm_params.



5
6
7
# File 'lib/ssm_env/fetcher.rb', line 5

def ssm_params
  @ssm_params
end

Instance Method Details

#fetch(params:) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ssm_env/fetcher.rb', line 12

def fetch(params: )
  batch_size, self.ssm_params = 10, {}

  params.each_slice(batch_size) do |params_slice|
    response = self.client.get_parameters(names: params_slice, with_decryption: true)
    # Transforms to { :name => { value: value, type: type } }
    response_params = Hash[response.parameters.map { |item| [item.name.to_sym, {value: item.value, type: item.type}] }]
    response_params.each do |name, attributes|
      self.ssm_params[name] ||= {}
      self.ssm_params[name][:value] = attributes[:value]
      self.ssm_params[name][:type] = attributes[:type]
    end
  end
  self.ssm_params
end