Class: App::AWSOutputter

Inherits:
Object
  • Object
show all
Extended by:
Columnist
Defined in:
lib/aws/aws_outputter.rb

Constant Summary collapse

EC2_INSTANCES =
'ec2_instances'
EC2_VOLUMES =
'ec2_volumes'
EC2_SECURITY_GROUPS =
'ec2_security_groups'
S3_BUCKETS =
's3_buckets'
RDS_MYSQL_INSTANCES =
'rds_mysql_instances'
SQS_QUEUES =
'sqs_queues'
HEADER_COLOR =
255
DIVIDER_COLOR =
240
DIM_COLOR =
246
CONSTRAINT_COLOR =
67
REGION_WIDTH =
15

Class Method Summary collapse

Class Method Details

.display(resource_title, resource, column_data, output, total_width, opts, args) ⇒ Object

Outputs EC2 data to terminal.

Returns:

  • void



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/aws/aws_outputter.rb', line 26

def self.display(resource_title, resource, column_data, output, total_width, opts, args)

    output = [] if output.nil?

    @terminal_width = Blufin::Terminal::get_terminal_width

    wildcard_width = @terminal_width - total_width - 8 - (column_data.length)

    puts "  \x1B[38;5;255m\x1B[48;5;54m #{output.length} \x1B[48;5;18m #{resource_title} \x1B[0m"
    puts
    table(:border => false) do

        row do
            column('', :width => 2, :color => HEADER_COLOR)
            column_data.each do |title, data|
                column(title, :width => get_width(data[:width], wildcard_width), :color => HEADER_COLOR)
            end
            column('', :width => 2, :color => HEADER_COLOR)
        end

        row do
            column('')
            column_data.each do |title, data|
                column('-' * get_width(data[:width], wildcard_width), :color => DIVIDER_COLOR)
            end
            column('')
        end

        output.each do |item|
            row do
                column('')
                column_data.each do |title, data|
                    color = data[:color].nil? ? 'default' : data[:color]
                    if data[:key] =~ /^Tags\./
                        value = App::AWSReports::extract_tag(item, data[:key])
                    else
                        value = get_value(data[:key], item)
                    end
                    value, color = get_formatter(data[:formatter], resource: resource, color: color).call(value) unless data[:formatter].nil?
                    column(value, :color => get_color(color))
                end
                column('')
            end
        end

    end
    puts

end

.display_parameters(table_data) ⇒ Object

Displays CF parameters in a table (currently during the CF intro screen).

Returns:

  • void

Raises:

  • (RuntimeError)


78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/aws/aws_outputter.rb', line 78

def self.display_parameters(table_data)
    raise RuntimeError, "Expected Array, instead got: #{table_data.class}" unless table_data.is_a?(Array)
    return unless table_data.any?
    # Must match widths below (minus remaining).
    tw            = Blufin::Terminal::get_terminal_width
    column_short  = 5
    column_widths = [32, 15, 75, 25, column_short, column_short, column_short, column_short]
    remaining     = tw - column_widths.inject(0) { |sum, x| sum + x } - 16
    column_widths << remaining
    table(:border => false) do
        row do
            column('', :width => 2, :color => HEADER_COLOR)
            column('Parameter', :width => 32, :color => HEADER_COLOR)
            column('Type', :width => 15, :color => HEADER_COLOR)
            column('Description', :width => 75, :color => HEADER_COLOR)
            column('AllowedPattern', :width => 25, :color => HEADER_COLOR)
            column('Min-L', :width => column_short, :color => HEADER_COLOR)
            column('Max-L', :width => column_short, :color => HEADER_COLOR)
            column('Min-V', :width => column_short, :color => HEADER_COLOR)
            column('Max-V', :width => column_short, :color => HEADER_COLOR)
            column('Cached/Default Value(s)', :width => remaining, :color => HEADER_COLOR)
            column('', :width => 2, :color => HEADER_COLOR)
        end
        row do
            column('')
            column_widths.each do |width|
                column('-' * width, :color => DIVIDER_COLOR)
            end
            column('')
        end
        table_data.each do |data|
            alp = data[:allowed_pattern]
            mil = data[:min_length]
            miv = data[:min_value]
            mal = data[:max_length]
            mav = data[:max_value]
            cop = 'light-green'
            cop = 'purple' if data[:type_internal] == :autocomplete
            cop = 'light-grey' if data[:type_internal] == :system || [
                AppCommand::CloudFormationCreate::OPTION_STACK_NAME,
                AppCommand::CloudFormationCreate::OPTION_PROJECT_ID,
                AppCommand::CloudFormationCreate::OPTION_DESCRIPTION,
                AppCommand::CloudFormationCreate::OPTION_TERM_PROTECT,
                AppCommand::CloudFormationCreate::OPTION_TIMEOUT,
                AppCommand::CloudFormationCreate::OPTION_OWNER
            ].include?(data[:parameter])
            # In case you want to change color in future, currently this is redundant.
            cod = data[:type_internal] == :system ? 'default' : 'default'
            cot = data[:type_internal] == :system ? 'default' : 'default'
            cot = data[:type] == AppCommand::CloudFormationCreate::SPECIAL ? 'light-grey' : cot
            row do
                column('')
                column(data[:parameter], :color => get_color(cop))
                column(data[:type], :color => get_color(cot))
                column(data[:description], :color => get_color(cod))
                column(alp.nil? ? "\xe2\x80\x94" : alp, :color => alp.nil? ? get_color('default') : CONSTRAINT_COLOR)
                column(mil.nil? ? "\xe2\x80\x94".rjust(column_short, ' ') : mil.to_s.rjust(column_short, ' '), :color => mil.nil? ? get_color('default') : CONSTRAINT_COLOR)
                column(mal.nil? ? "\xe2\x80\x94".rjust(column_short, ' ') : mal.to_s.rjust(column_short, ' '), :color => mal.nil? ? get_color('default') : CONSTRAINT_COLOR)
                column(miv.nil? ? "\xe2\x80\x94".rjust(column_short, ' ') : miv.to_s.rjust(column_short, ' '), :color => miv.nil? ? get_color('default') : CONSTRAINT_COLOR)
                column(mav.nil? ? "\xe2\x80\x94".rjust(column_short, ' ') : mav.to_s.rjust(column_short, ' '), :color => mav.nil? ? get_color('default') : CONSTRAINT_COLOR)
                column(data[:cached_value], :color => get_color('green'))
                column('')
            end
        end
    end
end