Class: Sfn::Command::Describe

Inherits:
Sfn::Command
  • Object
show all
Includes:
Sfn::CommandModule::Base
Defined in:
lib/sfn/command/describe.rb

Overview

Cloudformation describe command

Constant Summary collapse

AVAILABLE_DISPLAYS =
[:resources, :outputs, :tags]

Constants inherited from Sfn::Command

CONFIG_BASE_NAME, VALID_CONFIG_EXTENSIONS

Instance Method Summary collapse

Methods included from Sfn::CommandModule::Base

included

Methods inherited from Sfn::Command

#config, #initialize

Methods included from Sfn::CommandModule::Callbacks

#api_action!, #callbacks_for, #run_callbacks_for

Constructor Details

This class inherits a constructor from Sfn::Command

Instance Method Details

#default_attributesArray<String>



101
102
103
# File 'lib/sfn/command/describe.rb', line 101

def default_attributes
  %w(updated logical_id type status status_reason)
end

#execute!Object

Run the stack describe action



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/sfn/command/describe.rb', line 15

def execute!
  name_required!
  stack_name = name_args.last
  root_stack = api_action! do
    provider.stack(stack_name)
  end
  if root_stack
    ([root_stack] + root_stack.nested_stacks).compact.each do |stack|
      ui.info "Stack description of #{ui.color(stack.name, :bold)}:"
      display = [].tap do |to_display|
        AVAILABLE_DISPLAYS.each do |display_option|
          if config[display_option]
            to_display << display_option
          end
        end
      end
      display = AVAILABLE_DISPLAYS.dup if display.empty?
      display.each do |display_method|
        self.send(display_method, stack)
      end
      ui.puts
    end
  else
    ui.fatal "Failed to find requested stack: #{ui.color(stack_name, :bold, :red)}"
    raise "Requested stack not found: #{stack_name}"
  end
end

#outputs(stack) ⇒ Object

Display outputs



73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/sfn/command/describe.rb', line 73

def outputs(stack)
  ui.info "Outputs for stack: #{ui.color(stack.name, :bold)}"
  unless stack.outputs.nil? || stack.outputs.empty?
    stack.outputs.each do |output|
      key, value = output.key, output.value
      key = snake(key).to_s.split("_").map(&:capitalize).join(" ")
      ui.info ["  ", ui.color("#{key}:", :bold), value].join(" ")
    end
  else
    ui.info "  #{ui.color("No outputs found")}"
  end
end

#resources(stack) ⇒ Object

Display resources



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/sfn/command/describe.rb', line 46

def resources(stack)
  stack_resources = stack.resources.all.sort do |x, y|
    y.updated <=> x.updated
  end.map do |resource|
    Smash.new(resource.attributes)
  end
  ui.table(self) do
    table(:border => false) do
      row(:header => true) do
        allowed_attributes.each do |attr|
          column as_title(attr), :width => stack_resources.map { |r| r[attr].to_s.length }.push(as_title(attr).length).max + 2
        end
      end
      stack_resources.each do |resource|
        row do
          allowed_attributes.each do |attr|
            column resource[attr]
          end
        end
      end
    end
  end.display
end

#tags(stack) ⇒ Object

Display tags



89
90
91
92
93
94
95
96
97
98
# File 'lib/sfn/command/describe.rb', line 89

def tags(stack)
  ui.info "Tags for stack: #{ui.color(stack.name, :bold)}"
  if stack.tags && !stack.tags.empty?
    stack.tags.each do |key, value|
      ui.info ["  ", ui.color("#{key}:", :bold), value].join(" ")
    end
  else
    ui.info "  #{ui.color("No tags found")}"
  end
end