Module: CuffDown

Defined in:
lib/cuffdown/main.rb

Class Method Summary collapse

Class Method Details

.dump(name, params, tags, output) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'lib/cuffdown/main.rb', line 39

def self.dump(name, params, tags, output)
  result = {
    'Format' => 'v1',
    'Suffix' => name,
    'Parameters' => params,
    'Tags' => tags,
  }
  YAML.dump(result, output)
end

.parameters(stack) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/cuffdown/main.rb', line 21

def self.parameters(stack)
  (stack[:parameters] || []).map do |param|
    {
      'Name' => param[:parameter_key],
      'Value' => param[:parameter_value],
    }
  end
end

.parse_cli_args(argv) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/cuffdown/main.rb', line 8

def self.parse_cli_args(argv)
  args = {}
  parser = OptionParser.new do |opts|
    opts.banner = 'Output CuffSert-formatted metadata from an existing stack.'
    opts.separator('')
    opts.separator('Usage: cuffdown <stack-name>')
    CuffBase.shared_cli_args(opts, args)
  end
  stackname, _ = parser.parse(argv)
  args[:stackname] = stackname
  args
end

.run(argv, output) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/cuffdown/main.rb', line 49

def self.run(argv, output)
  cli_args = self.parse_cli_args(argv)
  meta = CuffSert::StackConfig.new
  meta.stackname = cli_args[:stackname]
  client = CuffSert::RxCFClient.new(cli_args[:aws_region])
  stack = client.find_stack_blocking(meta)
  unless stack
    STDERR.puts "No such stack #{meta.stackname}"
    exit(1)
  end
  stack = stack.to_h
  self.dump(
    stack[:stack_name],
    self.parameters(stack),
    self.tags(stack),
    output
  )
end

.tags(stack) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/cuffdown/main.rb', line 30

def self.tags(stack)
  (stack[:tags] || []).map do |param|
    {
      'Name' => param[:key],
      'Value' => param[:value],
    }
  end
end