awful 0.0.180 → 0.0.181

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: 8e11f3359fe4adb56535cfd09a2baea8eca683d4
4
- data.tar.gz: 7d18da124bd687439a1b9dc01f6c5be1b35d59d9
3
+ metadata.gz: 57375515263da3b59aa6be96f3b22961cf462f08
4
+ data.tar.gz: aa3fe03470511d3127f15ade33a1497bbc2ae75a
5
5
  SHA512:
6
- metadata.gz: 7cd7d321f9dbd8aa02d8b696fc7a2baecec2dab180b32a4f458c777754361418af7b0a474bc64f1eff1688da1fcc9ee339e13ea8e33e6aea0c5db383a1381625
7
- data.tar.gz: f23c217fc9e4e08a206f487e02bd5fd49b9916729cc883580f3f70be62781260a70e43943fb64a6309127254f3b4a69b5850771011e66a1ac91cca009065d24c
6
+ metadata.gz: ec4213f8ce0ca3006ea5c372054dfa087fbfbcb72f895312b8b39825eb88c759b2e0738364d7f5b6f49ead1cf859d18a0a36f7babee15d59fed38d7f2cf41cd0
7
+ data.tar.gz: c088cc2c848eda7b20c737c8088b27a4f6cb1e11d30f04171c05c5c884b6f402e635f070859c64b6958264b36d381c107ccd0756983983f060b247bf5ca113c7
@@ -10,6 +10,20 @@ module Awful
10
10
  def iam
11
11
  @iam ||= Aws::IAM::Client.new
12
12
  end
13
+
14
+ def color_date(date)
15
+ diff = date - Time.now
16
+ set_color(
17
+ date,
18
+ if diff < 0
19
+ :red
20
+ elsif diff < (60*60*24*30)
21
+ :yellow
22
+ else
23
+ :green
24
+ end
25
+ )
26
+ end
13
27
  end
14
28
 
15
29
  desc 'ls [PATH_PREFIX]', 'list server certificates'
@@ -32,7 +46,7 @@ module Awful
32
46
  c.path,
33
47
  c.server_certificate_id,
34
48
  c.upload_date,
35
- c.expiration,
49
+ color_date(c.expiration),
36
50
  ]
37
51
  }.sort
38
52
  elsif options[:arns]
@@ -2,11 +2,19 @@ require 'json'
2
2
 
3
3
  module Awful
4
4
  class IAM < Cli
5
+ COLORS = {
6
+ Active: :green,
7
+ Inactive: :red,
8
+ }
5
9
 
6
10
  no_commands do
7
11
  def iam
8
12
  @iam ||= Aws::IAM::Client.new
9
13
  end
14
+
15
+ def color(string)
16
+ set_color(string, COLORS.fetch(string.to_sym, :yellow))
17
+ end
10
18
  end
11
19
 
12
20
  desc 'users', 'list users'
@@ -93,6 +101,62 @@ module Awful
93
101
  end
94
102
  end
95
103
 
104
+ desc 'keys', 'list access keys'
105
+ method_option :long, aliases: '-l', type: :boolean, default: false, desc: 'long listing'
106
+ method_option :user, aliases: '-u', type: :string, default: nil, desc: 'show different user'
107
+ method_option :delete, type: :string, default: nil, desc: 'delete named key'
108
+ def keys
109
+ if options[:delete]
110
+ if yes?("Really delete key #{options[:delete]}?", :yellow)
111
+ iam.delete_access_key(access_key_id: options[:delete])
112
+ end
113
+ return
114
+ end
115
+
116
+ ## list keys
117
+ iam.list_access_keys(user_name: options[:user]).access_key_metadata.output do |keys|
118
+ if options[:long]
119
+ print_table keys.map{ |k|
120
+ [k.user_name, k.access_key_id, k.create_date, color(k.status)]
121
+ }
122
+ else
123
+ puts keys.map(&:access_key_id)
124
+ end
125
+ end
126
+ end
127
+
128
+ desc 'old', 'report on old access keys'
129
+ method_option :days, aliases: '-d', type: :numeric, default: 90, desc: 'age in days to treat as old'
130
+ method_option :all, aliases: '-a', type: :boolean, default: false, desc: 'list all users'
131
+ def old
132
+ iam.list_users.users.map do |u|
133
+ iam.list_access_keys(user_name: u.user_name).access_key_metadata.map do |k|
134
+ age = ((Time.now - k.create_date)/(60*60*24)).to_i
135
+ too_old = age > options[:days]
136
+ if options[:all] || too_old
137
+ [k.user_name, k.create_date, set_color("#{age} days", too_old ? :red : :green)]
138
+ else
139
+ nil
140
+ end
141
+ end
142
+ end.flatten(1).reject(&:nil?).output do |list|
143
+ print_table list
144
+ end
145
+ end
146
+
147
+ desc 'rotate', 'rotate access key for user'
148
+ method_option :user, aliases: '-u', type: :string, default: nil, desc: 'show different user'
149
+ def rotate
150
+ key = iam.create_access_key(user_name: options[:user]).access_key
151
+ puts(
152
+ "Your new credentials:",
153
+ "AWS_ACCESS_KEY_ID=#{key.access_key_id}",
154
+ "AWS_SECRET_ACCESS_KEY=#{key.secret_access_key}",
155
+ )
156
+ rescue Aws::IAM::Errors::LimitExceeded
157
+ warn 'You have two access keys: please delete one and run this command again.'
158
+ end
159
+
96
160
  end
97
161
 
98
162
  end
@@ -1,3 +1,3 @@
1
1
  module Awful
2
- VERSION = '0.0.180'
2
+ VERSION = '0.0.181'
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.180
4
+ version: 0.0.181
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-14 00:00:00.000000000 Z
11
+ date: 2017-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler