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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
|
# File 'lib/routes/aws_list.rb', line 81
def opts_routing
system('clear') unless @silent
if @opts[:metadata]
App::AWSReports::get_auto_fetch_resources(@data).each do |title, data|
output = []
output << "\x1B[38;5;240m AWS-CLI Command:\x1B[38;5;106m #{data[:resource][App::AWSReports::KEY_CLI]['command']}" if data[:resource].has_key?(App::AWSReports::KEY_CLI) && data[:resource][App::AWSReports::KEY_CLI].has_key?('command')
output << "\x1B[38;5;240m Region(s):\x1B[38;5;94m #{data[:resource][App::AWSReports::KEY_REGIONS].join(', ')}" if data[:resource].has_key?(App::AWSReports::KEY_REGIONS)
output << "\x1B[38;5;240mPreferred Region(s):\x1B[38;5;94m #{data[:resource][App::AWSReports::KEY_REGIONS_PREFERRED].join(', ')}" if data[:resource].has_key?(App::AWSReports::KEY_REGIONS_PREFERRED)
Blufin::Terminal::custom(data[:resource_title], 55, "Exports: #{Blufin::Terminal::format_highlight(title)}", output)
end
puts
exit
end
if @resource.nil?
resource_title = Blufin::Terminal::prompt_select('Select AWS Resource(s) to list:', @data.keys)
@resource = @data[resource_title]
else
resource_title = @opts[:resource]
end
cache_file = '/tmp/aws-uber-results-cache.txt'
if !@opts[:resource].nil? && @opts[:resource].downcase == App::AWSReports::CONST_ALL
if false && Blufin::Files::file_exists(cache_file)
uber_results = {}
puts
puts " \x1B[38;5;196mGetting regional_response from cache: #{Blufin::Terminal::format_directory(cache_file)}\x1B[0m"
eval("uber_results = #{Blufin::Files::read_file(cache_file)[0]}")
else
uber_results = {}
cmd_color = 240
threads = []
no_fit = []
puts
@data.each do |resource_title, resource|
fit_res = fits_in_terminal(resource_title)
unless fit_res[0]
no_fit << "\x1B[38;5;196m#{resource_title}\x1B[38;5;240m (required: #{fit_res[1]} / actual: #{fit_res[2]})"
next
end
sleep(0.01)
cmd_regions = @regions.join(',')
cmd_regions = resource[App::AWSReports::KEY_REGIONS].join(',') if resource.has_key?(App::AWSReports::KEY_REGIONS)
cmd_regions = "\x1B[38;5;#{cmd_color}m[\x1B[38;5;246m#{cmd_regions}\x1B[38;5;#{cmd_color}m]"
App::AWSOutputter::output_cli_command("aws #{resource[App::AWSReports::KEY_CLI][App::AWSReports::KEY_COMMAND]} --region #{cmd_regions}\x1B[38;5;240m --profile \x1B[38;5;246m#{App::AWSProfile::get_profile_name}\x1B[0m")
threads << Thread.new {
uber_results[resource_title] = App::AWSReports::get_aws_data(@regions, resource, resource_title, silent: true)
}
end
sleep(0.01)
if no_fit.any?
Blufin::Terminal::warning("The following resource(s) will be omitted because they won't fit in the terminal window.", no_fit)
else
puts
end
Blufin::Terminal::execute_proc('AWS - Fetching data...', Proc.new {
threads.each { |thread| thread.join }
})
Blufin::Files::write_file(cache_file, [uber_results.inspect])
end
puts
@data.each do |resource_title, resource|
if uber_results.has_key?(resource_title)
output_aws_data(uber_results[resource_title], resource, resource_title, silent: false)
end
end
else
if !@opts[:json] && !@opts[:json_prompt] && !@opts[:yaml] && !@opts[:yaml_colored] && !fits_in_terminal(resource_title)[0]
Blufin::Terminal::error("Output for #{Blufin::Terminal::format_highlight(resource_title)} \x1B[38;5;240m(#{Blufin::Terminal::format_action(@table_widths[resource_title])}\x1B[38;5;240m-width)\x1B[0m does not fit in Terminal \x1B[38;5;240m(#{Blufin::Terminal::format_action(@terminal_width)}\x1B[38;5;240m-width)\x1B[0m", 'Please make your terminal wider and try again.', true)
end
cache_file = "/tmp/aws-results-#{resource_title}-cache.txt"
if false && Blufin::Files::file_exists(cache_file)
puts
puts " \x1B[38;5;196mGetting regional_response from cache: #{Blufin::Terminal::format_directory(cache_file)}\x1B[0m"
results = {}
eval("results = #{Blufin::Files::read_file(cache_file)[0]}")
else
results = App::AWSReports::get_aws_data(@regions, @resource, resource_title, silent: @silent)
Blufin::Files::write_file(cache_file, [results.inspect])
end
output_aws_data(results, @resource, resource_title, silent: @silent)
end
end
|