Class: Jets::CLI::Dotenv::Ssm

Inherits:
Object
  • Object
show all
Includes:
AwsServices, Util::Logging
Defined in:
lib/jets/cli/dotenv/ssm.rb

Overview

The update logic is here and not a part of Jets::Dotenv::Ssm to emphasize that it’s only used for jets dotenv commands. This class is responsible for updating. The other Jets::Dotenv class is only repsonsible for reading. The one part of the other class that is used is Jets::Dotenv::Convention

Instance Method Summary collapse

Methods included from Util::Logging

#log

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

#output_value, #stack_exists?

Methods included from AwsServices::GlobalMemoist

included, #reset_cache!

Constructor Details

#initialize(options = {}) ⇒ Ssm

Returns a new instance of Ssm.



11
12
13
14
# File 'lib/jets/cli/dotenv/ssm.rb', line 11

def initialize(options = {})
  @options = options
  @parameter_type = options[:secure] ? "SecureString" : "String"
end

Instance Method Details

#conventional_name(name) ⇒ Object



51
52
53
54
55
56
57
58
# File 'lib/jets/cli/dotenv/ssm.rb', line 51

def conventional_name(name)
  # add conventional prefix
  # "/#{Jets.project.name}/#{Jets.env}/#{value}"
  unless name.include?("/")
    name = Jets::Dotenv::Convention.new.ssm_name(name)
  end
  name
end

#delete(names) ⇒ Object

There’s a delete_parameters method also that can delete 10 at a time. Use simple one-by-one deletion for clarity and to surface errors. Will allow program to continue for ParameterNotFound error. In case use wants to keep trying to delete all parameters.



34
35
36
37
38
39
40
41
42
# File 'lib/jets/cli/dotenv/ssm.rb', line 34

def delete(names)
  names.each do |name|
    name = conventional_name(name)
    ssm.delete_parameter(name: name)
    log.info "SSM Parameter deleted: #{name}"
  rescue Aws::SSM::Errors::ParameterNotFound => e
    log.warn "WARN: Failed to delete parameter #{name}: #{e.message}"
  end
end

#preview_list(names) ⇒ Object



44
45
46
47
48
49
# File 'lib/jets/cli/dotenv/ssm.rb', line 44

def preview_list(names)
  names = names.is_a?(Hash) ? names.keys.map(&:to_s) : names
  names.map do |name|
    "  #{conventional_name(name)}"
  end.join("\n")
end

#set(params) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/jets/cli/dotenv/ssm.rb', line 16

def set(params)
  # Loop through the hash and update each parameter
  params.each do |name, value|
    name = conventional_name(name)
    ssm.put_parameter(
      name: name,               # The name of the parameter
      value: value,             # The new value for the parameter
      type: @parameter_type,     # Set type to 'SecureString' if secure, else 'String'
      overwrite: true           # Allows overwriting an existing parameter
    )
    log.info "SSM Parameter set: #{name}"
  end
end