awful 0.0.183 → 0.0.184

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c1ab2fc365e4aaccd052206843ef554704ffd86d
4
- data.tar.gz: b4afadc9463ef855311cdea9e3e03ce6ebb3ee7a
3
+ metadata.gz: 59dd0f87f7f3923ccb2513df11036452ae454876
4
+ data.tar.gz: 5fd17954751108e596562f5a2c60121203c628cc
5
5
  SHA512:
6
- metadata.gz: f7fbe4141ddaf40a4482d9562e12fd542ac0cdd42e84093beccdbfa36fd0e9c49525566cfa030a5e561e6b94fbd674f68ba1c248e8cede2a262e870a6fb108f8
7
- data.tar.gz: 89db4d459b0846fa4d7b2b4b7e1075a9daf7f538833e14139cdf937eb3b0212d59bfbea0ce31b0fe47545658d5a4f3877096945c2c881bae47a8d2098404f9a3
6
+ metadata.gz: acc31dd1f4fcafb05fa9edf887f3ef0f0cadee94f8ec173585764182403173044712a30a6908c154938533a44d7fcdea631bf882d52667686054ca8c1e518eac
7
+ data.tar.gz: 98e1a0ddfb2854a4e7382028403cf769bbcaf7d1ec708f35cc9ca811178c6002b7dc817b27b93edca08af637eb45e114e63b7e39cb70159eeb731f6ef4548f58
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ #-*- mode: ruby; -*-
3
+
4
+ require 'awful'
5
+ require 'awful/firehose'
6
+
7
+ Awful::Firehose.start(ARGV)
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ #-*- mode: ruby; -*-
3
+
4
+ require 'awful'
5
+ require 'awful/kinesis'
6
+
7
+ Awful::Kinesis.start(ARGV)
@@ -76,6 +76,10 @@ module Awful
76
76
  @s3 ||= Aws::S3::Client.new
77
77
  end
78
78
 
79
+ def cf
80
+ @cf ||= Aws::CloudFormation::Client.new
81
+ end
82
+
79
83
  def lambda
80
84
  @lambda ||= Aws::Lambda::Client.new
81
85
  end
@@ -24,10 +24,6 @@ module Awful
24
24
  }
25
25
 
26
26
  no_commands do
27
- def cf
28
- @cf ||= Aws::CloudFormation::Client.new
29
- end
30
-
31
27
  def color(string)
32
28
  set_color(string, COLORS.fetch(string.downcase.to_sym, :blue))
33
29
  end
@@ -0,0 +1,67 @@
1
+ require 'yaml'
2
+
3
+ module Awful
4
+ module Short
5
+ def firehose(*args)
6
+ Awful::Firehose.new.invoke(*args)
7
+ end
8
+ end
9
+
10
+ class Firehose < Cli
11
+ COLORS = {
12
+ ACTIVE: :green,
13
+ DELETING: :red,
14
+ }
15
+
16
+ no_commands do
17
+ def firehose
18
+ @_firehose ||= Aws::Firehose::Client.new
19
+ end
20
+
21
+ def color(string)
22
+ set_color(string, COLORS.fetch(string.to_sym, :yellow))
23
+ end
24
+
25
+ ## special-case paginator for delivery streams
26
+ def paginate_delivery_streams(thing)
27
+ token = nil
28
+ things = []
29
+ loop do
30
+ resp = yield(token)
31
+ items = resp.send(thing)
32
+ things += items
33
+ token = items.last
34
+ break unless resp.has_more_delivery_streams
35
+ end
36
+ things
37
+ end
38
+ end
39
+
40
+ desc 'ls', 'list firehose streams'
41
+ method_option :long, aliases: '-l', type: :boolean, default: false, desc: 'long listing'
42
+ def ls
43
+ paginate_delivery_streams(:delivery_stream_names) do |start|
44
+ firehose.list_delivery_streams(exclusive_start_delivery_stream_name: start)
45
+ end.output do |streams|
46
+ if options[:long]
47
+ print_table streams.map { |name|
48
+
49
+ s = firehose.describe_delivery_stream(delivery_stream_name: name).delivery_stream_description
50
+ op = s.has_more_destinations ? '>' : ''
51
+ [s.delivery_stream_name, op + s.destinations.count.to_s, color(s.delivery_stream_status), s.delivery_stream_type, 'v' + s.version_id.to_s, s.create_timestamp]
52
+ }
53
+ else
54
+ puts streams
55
+ end
56
+ end
57
+ end
58
+
59
+ desc 'dump NAME', 'describe firehose stream'
60
+ def dump(name)
61
+ firehose.describe_delivery_stream(delivery_stream_name: name).delivery_stream_description.output do |stream|
62
+ puts YAML.dump(stringify_keys(stream.to_hash))
63
+ end
64
+ end
65
+
66
+ end
67
+ end
@@ -0,0 +1,66 @@
1
+ require 'yaml'
2
+
3
+ module Awful
4
+ module Short
5
+ def kinesis(*args)
6
+ Awful::Kinesis.new.invoke(*args)
7
+ end
8
+ end
9
+
10
+ class Kinesis < Cli
11
+ COLORS = {
12
+ ACTIVE: :green,
13
+ DELETING: :red,
14
+ }
15
+
16
+ no_commands do
17
+ def kinesis
18
+ @_kinesis ||= Aws::Kinesis::Client.new
19
+ end
20
+
21
+ def color(string)
22
+ set_color(string, COLORS.fetch(string.to_sym, :yellow))
23
+ end
24
+
25
+ ## special-case paginator for streams
26
+ def paginate_streams(thing)
27
+ token = nil
28
+ things = []
29
+ loop do
30
+ resp = yield(token)
31
+ items = resp.send(thing)
32
+ things += items
33
+ token = items.last
34
+ break unless resp.has_more_streams
35
+ end
36
+ things
37
+ end
38
+ end
39
+
40
+ desc 'ls', 'list streams'
41
+ method_option :long, aliases: '-l', type: :boolean, default: false, desc: 'long listing'
42
+ def ls
43
+ paginate_streams(:stream_names) do |start|
44
+ kinesis.list_streams(exclusive_start_stream_name: start)
45
+ end.output do |streams|
46
+ if options[:long]
47
+ print_table streams.map { |name|
48
+ s = kinesis.describe_stream(stream_name: name).stream_description
49
+ op = s.has_more_shards ? '>' : ''
50
+ [s.stream_name, op + s.shards.count.to_s, color(s.stream_status), s.encryption_type, s.retention_period_hours.to_s + 'h', s.stream_creation_timestamp]
51
+ }
52
+ else
53
+ puts streams
54
+ end
55
+ end
56
+ end
57
+
58
+ desc 'dump [NAME]', 'describe a stream by name'
59
+ def dump(name)
60
+ kinesis.describe_stream(stream_name: name).stream_description.output do |stream|
61
+ puts YAML.dump(stringify_keys(stream.to_hash))
62
+ end
63
+ end
64
+
65
+ end
66
+ end
@@ -17,6 +17,13 @@ module Awful
17
17
  rescue Aws::S3::Errors::NoSuchTagSet # sdk throws this if no tags
18
18
  nil
19
19
  end
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
26
+ end
20
27
  end
21
28
 
22
29
  desc 'ls PATTERN', 'list buckets or objects'
@@ -197,5 +204,25 @@ module Awful
197
204
  }
198
205
  )
199
206
  end
207
+
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'
210
+ 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
223
+ end
224
+ end
225
+ end
226
+
200
227
  end
201
228
  end
@@ -1,3 +1,3 @@
1
1
  module Awful
2
- VERSION = '0.0.183'
2
+ VERSION = '0.0.184'
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.183
4
+ version: 0.0.184
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-09-21 00:00:00.000000000 Z
11
+ date: 2017-11-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -105,8 +105,10 @@ executables:
105
105
  - elasticache
106
106
  - elb
107
107
  - emr
108
+ - firehose
108
109
  - iam
109
110
  - keypair
111
+ - kinesis
110
112
  - kms
111
113
  - lambda
112
114
  - lc
@@ -154,8 +156,10 @@ files:
154
156
  - bin/elasticache
155
157
  - bin/elb
156
158
  - bin/emr
159
+ - bin/firehose
157
160
  - bin/iam
158
161
  - bin/keypair
162
+ - bin/kinesis
159
163
  - bin/kms
160
164
  - bin/lambda
161
165
  - bin/lc
@@ -201,8 +205,10 @@ files:
201
205
  - lib/awful/elasticache.rb
202
206
  - lib/awful/elb.rb
203
207
  - lib/awful/emr.rb
208
+ - lib/awful/firehose.rb
204
209
  - lib/awful/iam.rb
205
210
  - lib/awful/keypair.rb
211
+ - lib/awful/kinesis.rb
206
212
  - lib/awful/kms.rb
207
213
  - lib/awful/lambda.rb
208
214
  - lib/awful/lambda_events.rb