Class: Awshark::Ssm::Subcommand

Inherits:
Thor
  • Object
show all
Includes:
ClassOptions
Defined in:
lib/awshark/ssm/subcommand.rb

Instance Method Summary collapse

Methods included from ClassOptions

#process_class_options

Instance Method Details

#deploy(directory) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/awshark/ssm/subcommand.rb', line 51

def deploy(directory)
  process_class_options

  secrets_path = File.join(directory, 'secrets.yml')
  raise GracefulFail, "File #{secrets_path} does not exist." unless File.exist?(secrets_path)

  app_name = directory.split('/').last
  stage = options['stage']

  secrets = YAML.load_file(secrets_path)[stage]
  raise GracefulFail, "No secrets found for stage '#{stage}' in #{secrets_path}." if secrets.nil?

  ssm_client.update_secrets(application: "#{app_name}-#{stage}", secrets: secrets)
rescue GracefulFail => e
  puts e.message
end

#list(parameter_path) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/awshark/ssm/subcommand.rb', line 24

def list(parameter_path)
  process_class_options

  raise GracefulFail, 'PARAMETER_PATH must begin with a "/"' if parameter_path[0] != '/'

  puts "Parameter Store #{parameter_path.inspect} in #{::Aws.config[:region]}:"

  parameters = ssm_client.list_secrets(application: parameter_path)

  parameters.each do |param|
    printf " %-60<name>s %<value>s\n", { name: param.name, value: param.value }
  end
rescue GracefulFail => e
  puts e.message
end