class Lamby::SsmParameterStore
Constants
- MAX_RESULTS
- Param
Attributes
params[R]
path[R]
Public Class Methods
dotenv(path)
click to toggle source
# File lib/lamby/ssm_parameter_store.rb, line 14 def dotenv(path) new(path).get!.to_dotenv end
get!(path)
click to toggle source
# File lib/lamby/ssm_parameter_store.rb, line 18 def get!(path) parts = path[1..-1].split('/') env = parts.pop path = "/#{parts.join('/')}" param = new(path).get!.params.detect do |p| p.env == env end param&.value end
new(path, options = {})
click to toggle source
# File lib/lamby/ssm_parameter_store.rb, line 30 def initialize(path, options = {}) @path = path @params = [] @options = options end
Public Instance Methods
client()
click to toggle source
# File lib/lamby/ssm_parameter_store.rb, line 56 def client @client ||= begin options = @options[:client_options] || {} Aws::SSM::Client.new(options) end end
get!()
click to toggle source
# File lib/lamby/ssm_parameter_store.rb, line 46 def get! get_all! get_history! unless label.to_s.empty? self end
label()
click to toggle source
# File lib/lamby/ssm_parameter_store.rb, line 52 def label ENV['LAMBY_SSM_PARAMS_LABEL'] || @options[:label] end
to_dotenv()
click to toggle source
# File lib/lamby/ssm_parameter_store.rb, line 42 def to_dotenv File.open(dotenv_file, 'a') { |f| f.write(dotenv_contents) } end
to_env(overwrite: true)
click to toggle source
# File lib/lamby/ssm_parameter_store.rb, line 36 def to_env(overwrite: true) params.each do |param| overwrite ? ENV[param.env] = param.value : ENV[param.env] ||= param.value end end
Private Instance Methods
dotenv_contents()
click to toggle source
# File lib/lamby/ssm_parameter_store.rb, line 70 def dotenv_contents params.each_with_object('') do |param, contents| line = "#{param.env}=#{param.value}\n" contents << line end end
dotenv_file()
click to toggle source
# File lib/lamby/ssm_parameter_store.rb, line 66 def dotenv_file @options[:dotenv_file] || ENV['LAMBY_SSM_PARAMS_FILE'] || Rails.root.join(".env.#{Rails.env}") end
get_all()
click to toggle source
# File lib/lamby/ssm_parameter_store.rb, line 92 def get_all @all_response = client.get_parameters_by_path(get_all_options) end
get_all!()
click to toggle source
Path
# File lib/lamby/ssm_parameter_store.rb, line 79 def get_all! return params if @got_all get_parse_all while @all_response.next_token do get_parse_all end @got_all = true params end
get_all_options()
click to toggle source
# File lib/lamby/ssm_parameter_store.rb, line 96 def get_all_options { path: path, recursive: true, with_decryption: true, max_results: MAX_RESULTS }.tap { |options| token = @all_response&.next_token options[:next_token] = token if token } end
get_history(name)
click to toggle source
# File lib/lamby/ssm_parameter_store.rb, line 132 def get_history(name) @hist_response = client.get_parameter_history(get_history_options(name)) end
get_history!()
click to toggle source
History
# File lib/lamby/ssm_parameter_store.rb, line 116 def get_history! return params if @got_history params.each do |param| name = param.name get_parse_history(name) while @hist_response.next_token do get_parse_history(name) end end @got_history = true params end
get_history_options(name)
click to toggle source
# File lib/lamby/ssm_parameter_store.rb, line 136 def get_history_options(name) { name: name, with_decryption: true, max_results: MAX_RESULTS }.tap { |options| token = @hist_response&.next_token options[:next_token] = token if token } end
get_parse_all()
click to toggle source
# File lib/lamby/ssm_parameter_store.rb, line 87 def get_parse_all get_all parse_all end
get_parse_history(name)
click to toggle source
# File lib/lamby/ssm_parameter_store.rb, line 127 def get_parse_history(name) get_history(name) parse_history(name) end
parse_all()
click to toggle source
# File lib/lamby/ssm_parameter_store.rb, line 107 def parse_all @all_response.parameters.each do |p| env = p.name.split('/').last params << Param.new(p.name, env, p.value) end end
parse_history(name)
click to toggle source
# File lib/lamby/ssm_parameter_store.rb, line 146 def parse_history(name) @hist_response.parameters.each do |p| next unless p.labels.include? label param = params.detect { |param| param.name == name } param.value = p.value end end