Class: Jets::Dotenv::Ssm
- Inherits:
-
Object
- Object
- Jets::Dotenv::Ssm
- Includes:
- AwsServices, Util::Logging
- Defined in:
- lib/jets/dotenv/ssm.rb
Instance Method Summary collapse
- #get_ssm_parameters_path(path) ⇒ Object
-
#initialize(variables) ⇒ Ssm
constructor
A new instance of Ssm.
- #interpolate! ⇒ Object
-
#merged_variables ⇒ Object
Merges the variables from the dotenv files with the conventional ssm variables inferred by path, IE: /demo/dev/ User defined config/jets/env files values win over inferred ssm variables.
- #skip_list?(key) ⇒ Boolean
Methods included from Util::Logging
Methods included from AwsServices
#apigateway, #aws_options, #cfn, #codebuild, #dynamodb, #lambda_client, #logs, #s3, #s3_resource, #sns, #sqs, #ssm, #sts, #wafv2
Methods included from AwsServices::StackStatus
Methods included from AwsServices::GlobalMemoist
Constructor Details
#initialize(variables) ⇒ Ssm
Returns a new instance of Ssm.
6 7 8 9 |
# File 'lib/jets/dotenv/ssm.rb', line 6 def initialize(variables) @variables = variables @missing = [] end |
Instance Method Details
#get_ssm_parameters_path(path) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/jets/dotenv/ssm.rb', line 68 def get_ssm_parameters_path(path) if ARGV.include?("dotenv") && ARGV.include?("list") warn "# Autoloading SSM parameters within path #{path}" end parameters = {} next_token = nil loop do resp = ssm.get_parameters_by_path(path: path, with_decryption: true, next_token: next_token) resp.parameters.each do |param| key = param.name.sub(path, "") parameters[key] = param.value end next_token = resp.next_token break unless next_token end parameters end |
#interpolate! ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/jets/dotenv/ssm.rb', line 11 def interpolate! interpolated_vars = merged_variables.map do |key, value| var = Var.new(key, value) @missing << var if var.ssm_missing? var end interpolated_vars.each do |var| ENV[var.name] = var.value end if @missing.empty? interpolated_vars.map { |var| [var.name, var.value] }.sort.to_h # success else = "Error loading .env variables. No matching SSM parameters found for:\n".color(:red) += @missing.map do |var| " #{var.name}=#{var.raw_value} # ssm name: #{var.ssm_name}" end.join("\n") abort end end |
#merged_variables ⇒ Object
Merges the variables from the dotenv files with the conventional ssm variables inferred by path, IE: /demo/dev/ User defined config/jets/env files values win over inferred ssm variables.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/jets/dotenv/ssm.rb', line 36 def merged_variables if Jets.project.dotenv.ssm.autoload.enable ssm_vars = get_ssm_parameters_path(Convention.ssm_path) # IE: /demo/dev/ if Convention.jets_env_path != Convention.ssm_path jets_env_vars = get_ssm_parameters_path(Convention.jets_env_path) # IE: /demo/sbx/ ssm_vars = ssm_vars.merge(jets_env_vars) end # skip list ssm_vars = ssm_vars.delete_if { |k, v| skip_list?(k) } # optimization: no need to get vars with SSM values since they are already in ssm_vars vars = @variables.dup.delete_if { |k, v| v == "SSM" && ssm_vars.key?(k) } ssm_vars.merge(vars) else @variables end end |