awful 0.0.184 → 0.0.185

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 59dd0f87f7f3923ccb2513df11036452ae454876
4
- data.tar.gz: 5fd17954751108e596562f5a2c60121203c628cc
3
+ metadata.gz: 87f2a0676250644bd5230e35158ba527dd25ba96
4
+ data.tar.gz: fe588f61abad3ecc1fdcd4eb713abf8e954938c9
5
5
  SHA512:
6
- metadata.gz: acc31dd1f4fcafb05fa9edf887f3ef0f0cadee94f8ec173585764182403173044712a30a6908c154938533a44d7fcdea631bf882d52667686054ca8c1e518eac
7
- data.tar.gz: 98e1a0ddfb2854a4e7382028403cf769bbcaf7d1ec708f35cc9ca811178c6002b7dc817b27b93edca08af637eb45e114e63b7e39cb70159eeb731f6ef4548f58
6
+ metadata.gz: 0bbd35722e545882c17ea07f6eaf3d387b1f323f26f007c329753c598394a51e5cb5e515b9a24a70675ce0c87c7b4b18c32f674cecd7cbe096e978c7dd2df515
7
+ data.tar.gz: e1b3fde92c3f5319bcd3eccd057f0dc6e7a0fe1f14db91c3fb419b1a9e7edf65cc859b974e6bcf41aff1aef7568fce9aac28d3614f4181c2be45c25a61600419
@@ -88,6 +88,10 @@ module Awful
88
88
  @support ||= Aws::Support::Client.new
89
89
  end
90
90
 
91
+ def cf
92
+ @cf ||= Aws::CloudFormation::Client.new
93
+ end
94
+
91
95
  def symbolize_keys(thing)
92
96
  if thing.is_a?(Hash)
93
97
  Hash[ thing.map { |k,v| [ k.to_sym, symbolize_keys(v) ] } ]
@@ -23,6 +23,16 @@ module Awful
23
23
  rollback_complete: :red,
24
24
  }
25
25
 
26
+ ## stack statuses that are not DELETE_COMPLETE
27
+ STATUSES = %i[
28
+ CREATE_IN_PROGRESS CREATE_FAILED CREATE_COMPLETE
29
+ ROLLBACK_IN_PROGRESS ROLLBACK_FAILED ROLLBACK_COMPLETE
30
+ DELETE_IN_PROGRESS DELETE_FAILED
31
+ UPDATE_IN_PROGRESS UPDATE_COMPLETE_CLEANUP_IN_PROGRESS UPDATE_COMPLETE
32
+ UPDATE_ROLLBACK_IN_PROGRESS UPDATE_ROLLBACK_FAILED UPDATE_ROLLBACK_COMPLETE_CLEANUP_IN_PROGRESS UPDATE_ROLLBACK_COMPLETE
33
+ REVIEW_IN_PROGRESS
34
+ ]
35
+
26
36
  no_commands do
27
37
  def color(string)
28
38
  set_color(string, COLORS.fetch(string.downcase.to_sym, :blue))
@@ -41,28 +51,16 @@ module Awful
41
51
  end
42
52
 
43
53
  desc 'ls [PATTERN]', 'list cloudformation stacks matching PATTERN'
44
- method_option :long, aliases: '-l', type: :boolean, default: false, desc: 'Long listing'
45
- method_option :all, aliases: '-a', type: :boolean, default: false, desc: 'Show all, including stacks in DELETE_COMPLETE'
46
- def ls(name = /./)
47
- stacks = stack_summaries
48
-
49
- ## skip deleted stacks unless -a given
50
- unless options[:all]
51
- stacks = stacks.select { |stack| stack.stack_status != 'DELETE_COMPLETE' }
52
- end
53
-
54
- ## match on given arg
55
- stacks.select do |stack|
56
- stack.stack_name.match(name)
54
+ method_option :long, aliases: '-l', type: :boolean, default: false, desc: 'long listing'
55
+ def ls(name = nil)
56
+ paginate(:stack_summaries) do |next_token|
57
+ cf.list_stacks(stack_status_filter: STATUSES, next_token: next_token)
58
+ end.tap do |stacks|
59
+ stacks.select! { |s| s.stack_name.match(name) } if name
57
60
  end.output do |list|
58
61
  if options[:long]
59
62
  print_table list.map { |s|
60
- [
61
- s.stack_name,
62
- s.creation_time,
63
- color(s.stack_status),
64
- s.template_description,
65
- ]
63
+ [s.stack_name, s.creation_time, color(s.stack_status), s.template_description]
66
64
  }.sort
67
65
  else
68
66
  puts list.map(&:stack_name).sort
@@ -18,11 +18,16 @@ module Awful
18
18
  nil
19
19
  end
20
20
 
21
- ## get a stack if it exists, or nil
22
- def cfn_stack(name)
23
- name && cf.describe_stacks(stack_name: name)
24
- rescue Aws::CloudFormation::Errors::ValidationError
25
- nil
21
+ def get_stack_tag(name)
22
+ (get_tags(name) || []).find do |tag|
23
+ tag.key == 'aws:cloudformation:stack-name'
24
+ end&.value
25
+ end
26
+
27
+ def stack_exists?(name)
28
+ cf.describe_stacks(stack_name: name) && true
29
+ rescue ::Aws::CloudFormation::Errors::ValidationError
30
+ false
26
31
  end
27
32
  end
28
33
 
@@ -205,21 +210,14 @@ module Awful
205
210
  )
206
211
  end
207
212
 
208
- desc 'orphans', 'get buckets tagged by a stack that no longer exists'
209
- method_option :delete, aliases: '-d', type: :boolean, default: false, desc: 'delete empty orphaned buckets'
213
+ desc 'orphans', 'find empty buckets from a deleted CFN stack'
214
+ method_option :delete, type: :boolean, default: false, desc: 'delete orphaned buckets'
210
215
  def orphans
211
- s3.list_buckets.buckets.each do |b|
212
- stack = get_tags(b.name)&.find{ |t| t.key == 'aws:cloudformation:stack-name' }&.value
213
- next if cfn_stack(stack) # not an orphan if stack exists
214
-
215
- if options[:delete]
216
- if s3.list_objects_v2(bucket: b.name, max_keys: 1).key_count == 0
217
- s3.delete_bucket(bucket: b.name) if yes?("Delete empty bucket #{b.name}?", :yellow)
218
- else
219
- puts "#{b.name} not empty"
220
- end
221
- else
222
- puts b.name
216
+ s3.list_buckets.buckets.each do |bucket|
217
+ if (stack = get_stack_tag(bucket.name))
218
+ next if stack_exists?(stack)
219
+ puts bucket.name
220
+ s3.delete_bucket(bucket: bucket.name) if options[:delete]
223
221
  end
224
222
  end
225
223
  end
@@ -1,3 +1,3 @@
1
1
  module Awful
2
- VERSION = '0.0.184'
2
+ VERSION = '0.0.185'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: awful
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.184
4
+ version: 0.0.185
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ric Lister
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-21 00:00:00.000000000 Z
11
+ date: 2018-01-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler