Class: Jets::Dotenv::Ssm
- Inherits:
-
Object
- Object
- Jets::Dotenv::Ssm
- Defined in:
- lib/jets/dotenv/ssm.rb
Constant Summary collapse
- SSM_VARIABLE_REGEXP =
/^ssm:(.*)/
Instance Method Summary collapse
- #fetch_ssm_value(key, value) ⇒ Object
-
#initialize(variables = {}) ⇒ Ssm
constructor
A new instance of Ssm.
- #interpolate! ⇒ Object
- #ssm ⇒ Object
Constructor Details
#initialize(variables = {}) ⇒ Ssm
Returns a new instance of Ssm.
7 8 9 10 |
# File 'lib/jets/dotenv/ssm.rb', line 7 def initialize(variables={}) @variables = variables @missing = [] end |
Instance Method Details
#fetch_ssm_value(key, value) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/jets/dotenv/ssm.rb', line 34 def fetch_ssm_value(key, value) name = value.start_with?("/") ? value : "/#{Jets.config.project_name}/#{Jets.env}/#{value}" response = ssm.get_parameter(name: name, with_decryption: true) response.parameter.value rescue Aws::SSM::Errors::ParameterNotFound @missing << [key, value, name] '' end |
#interpolate! ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/jets/dotenv/ssm.rb', line 12 def interpolate! interpolated_variables = @variables.map do |key, value| if value[SSM_VARIABLE_REGEXP] value = fetch_ssm_value(key, $1) end [key, value] end interpolated_variables.each do |key, value| ENV[key] = value end if @missing.empty? interpolated_variables.to_h # success else = "Error loading .env variables. No matching SSM parameters found for:\n".color(:red) += @missing.map { |k,v,n| " #{k}=ssm:#{v} # ssm name: #{n}"}.join("\n") abort end end |
#ssm ⇒ Object
44 45 46 |
# File 'lib/jets/dotenv/ssm.rb', line 44 def ssm @ssm ||= Aws::SSM::Client.new end |