Class: Lamby::SsmParameterStore

Inherits:
Object
  • Object
show all
Defined in:
lib/lamby/ssm_parameter_store.rb

Defined Under Namespace

Classes: Param

Constant Summary collapse

MAX_RESULTS =
10

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, options = {}) ⇒ SsmParameterStore

Returns a new instance of SsmParameterStore.



29
30
31
32
33
# File 'lib/lamby/ssm_parameter_store.rb', line 29

def initialize(path, options = {})
  @path = path
  @params = []
  @options = options
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



10
11
12
# File 'lib/lamby/ssm_parameter_store.rb', line 10

def params
  @params
end

#pathObject (readonly)

Returns the value of attribute path.



10
11
12
# File 'lib/lamby/ssm_parameter_store.rb', line 10

def path
  @path
end

Class Method Details

.dotenv(path) ⇒ Object



14
15
16
# File 'lib/lamby/ssm_parameter_store.rb', line 14

def dotenv(path)
  new(path).get!.to_dotenv
end

.get!(path) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/lamby/ssm_parameter_store.rb', line 18

def get!(path)
  parts = path.from(1).split('/')
  env = parts.pop
  path = "/#{parts.join('/')}"
  new(path).get!.params.detect do |p|
    p.env == env
  end.try(:value)
end

Instance Method Details

#clientObject



55
56
57
58
59
60
# File 'lib/lamby/ssm_parameter_store.rb', line 55

def client
  @client ||= begin
    options = @options[:client_options] || {}
    Aws::SSM::Client.new(options)
  end
end

#get!Object



45
46
47
48
49
# File 'lib/lamby/ssm_parameter_store.rb', line 45

def get!
  get_all!
  get_history! if label.present?
  self
end

#labelObject



51
52
53
# File 'lib/lamby/ssm_parameter_store.rb', line 51

def label
  ENV['LAMBY_SSM_PARAMS_LABEL'] || @options[:label]
end

#to_dotenvObject



41
42
43
# File 'lib/lamby/ssm_parameter_store.rb', line 41

def to_dotenv
  File.open(dotenv_file, 'w') { |f| f.write(dotenv_contents) }
end

#to_env(overwrite: true) ⇒ Object



35
36
37
38
39
# File 'lib/lamby/ssm_parameter_store.rb', line 35

def to_env(overwrite: true)
  params.each do |param|
    overwrite ? ENV[param.env] = param.value : ENV[param.env] ||= param.value
  end
end