awskeyring 1.0.2 → 1.1.0

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
  SHA256:
3
- metadata.gz: 98c9cb7a8b1bb999039afa9aa3ecadab9fc7cea93a370d954df6eeadde4439df
4
- data.tar.gz: bf180c1f0bd4938effce45a6649b91dec8400f39212e6ef60c4af788989ba12a
3
+ metadata.gz: b87abef9f85c6701db2bd73209be0d385ac426b5421aeff5c0f81b1d67b695d9
4
+ data.tar.gz: 63e772094af9ad179f44b254ccf607418bc33577e67d6fd35c304708bdcf7a43
5
5
  SHA512:
6
- metadata.gz: c63542d56d3f72bd58f5e4157840695955492795a10fdfb9271a847c64bd6347d4addfca4b9c8f9a2b2f6463d93cf9775e3c47745bf447fd65fd2d1be9a0b557
7
- data.tar.gz: 1bdd84d62afb7496f22403e8a2fb09df0b543962c7c7308b260763a3a394e1adcc954da52cd1828fa6c8193ec136bbac0fc6c3121294e4da43f8967914854234
6
+ metadata.gz: b78466f81f87df9e9dd48ac5755ed58b9ea35a84d2f87b4c1fc3e9501cf4545cdc5a4730b412967ef8e2ccae2cf641d4fa05decff75d966b7b47d3e1955c30a5
7
+ data.tar.gz: 550148fee86d1dcb7bdf3c52b14400ab9d8bdf1e84361b5f77ad0a05c9d43e86cd539a3a0d6617eff288f9a70925f99cf775f4d150596f308e4f16361325dc1d
@@ -1,6 +1,16 @@
1
- # Change Log
1
+ # Changelog
2
+
3
+ ## [v1.1.0](https://github.com/servian/awskeyring/tree/v1.1.0) (2019-11-06)
4
+
5
+ [Full Changelog](https://github.com/servian/awskeyring/compare/v1.0.2...v1.1.0)
6
+
7
+ **Implemented enhancements:**
8
+
9
+ - Add completion to input prompts [\#53](https://github.com/servian/awskeyring/pull/53) ([tristanmorgan](https://github.com/tristanmorgan))
10
+ - Check for existing \(or not\) role names [\#52](https://github.com/servian/awskeyring/pull/52) ([tristanmorgan](https://github.com/tristanmorgan))
2
11
 
3
12
  ## [v1.0.2](https://github.com/servian/awskeyring/tree/v1.0.2) (2019-10-18)
13
+
4
14
  [Full Changelog](https://github.com/servian/awskeyring/compare/v1.0.1...v1.0.2)
5
15
 
6
16
  **Implemented enhancements:**
@@ -9,6 +19,7 @@
9
19
  - Use RuboCop-RSpec too and expect\(\) more. [\#48](https://github.com/servian/awskeyring/pull/48) ([tristanmorgan](https://github.com/tristanmorgan))
10
20
 
11
21
  ## [v1.0.1](https://github.com/servian/awskeyring/tree/v1.0.1) (2019-05-23)
22
+
12
23
  [Full Changelog](https://github.com/servian/awskeyring/compare/v1.0.0...v1.0.1)
13
24
 
14
25
  **Implemented enhancements:**
@@ -20,209 +31,13 @@
20
31
  - Unfreeze secret strings. [\#46](https://github.com/servian/awskeyring/pull/46) ([tristanmorgan](https://github.com/tristanmorgan))
21
32
 
22
33
  ## [v1.0.0](https://github.com/servian/awskeyring/tree/v1.0.0) (2019-05-19)
34
+
23
35
  [Full Changelog](https://github.com/servian/awskeyring/compare/v0.10.0...v1.0.0)
24
36
 
25
37
  **Implemented enhancements:**
26
38
 
27
39
  - More RuboCop changes and tweaked version string. [\#45](https://github.com/servian/awskeyring/pull/45) ([tristanmorgan](https://github.com/tristanmorgan))
28
40
 
29
- ## [v0.10.0](https://github.com/servian/awskeyring/tree/v0.10.0) (2019-04-24)
30
- [Full Changelog](https://github.com/servian/awskeyring/compare/v0.9.0...v0.10.0)
31
-
32
- **Implemented enhancements:**
33
-
34
- - Add --unset flag to env command [\#44](https://github.com/servian/awskeyring/pull/44) ([tristanmorgan](https://github.com/tristanmorgan))
35
-
36
- ## [v0.9.0](https://github.com/servian/awskeyring/tree/v0.9.0) (2019-04-09)
37
- [Full Changelog](https://github.com/servian/awskeyring/compare/v0.8.1...v0.9.0)
38
-
39
- **Implemented enhancements:**
40
-
41
- - Strip whitespace from user input [\#43](https://github.com/servian/awskeyring/pull/43) ([tristanmorgan](https://github.com/tristanmorgan))
42
-
43
- ## [v0.8.1](https://github.com/servian/awskeyring/tree/v0.8.1) (2019-02-06)
44
- [Full Changelog](https://github.com/servian/awskeyring/compare/v0.8.0...v0.8.1)
45
-
46
- **Fixed bugs:**
47
-
48
- - Fix usage behind PROXIES [\#42](https://github.com/servian/awskeyring/pull/42) ([tristanmorgan](https://github.com/tristanmorgan))
49
-
50
- ## [v0.8.0](https://github.com/servian/awskeyring/tree/v0.8.0) (2018-12-19)
51
- [Full Changelog](https://github.com/servian/awskeyring/compare/v0.7.2...v0.8.0)
52
-
53
- **Implemented enhancements:**
54
-
55
- - Provide input feedback for secret fields. [\#41](https://github.com/servian/awskeyring/pull/41) ([tristanmorgan](https://github.com/tristanmorgan))
56
-
57
- **Fixed bugs:**
58
-
59
- - Cannot enter secret access key when adding new accounts in 0.7.0 [\#36](https://github.com/servian/awskeyring/issues/36)
60
-
61
- ## [v0.7.2](https://github.com/servian/awskeyring/tree/v0.7.2) (2018-12-17)
62
- [Full Changelog](https://github.com/servian/awskeyring/compare/v0.7.1...v0.7.2)
63
-
64
- **Fixed bugs:**
65
-
66
- - Validate that account doesn't already exists. [\#40](https://github.com/servian/awskeyring/pull/40) ([tristanmorgan](https://github.com/tristanmorgan))
67
- - Check for COMMAND param to exec. [\#38](https://github.com/servian/awskeyring/pull/38) ([tristanmorgan](https://github.com/tristanmorgan))
68
-
69
- ## [v0.7.1](https://github.com/servian/awskeyring/tree/v0.7.1) (2018-12-03)
70
- [Full Changelog](https://github.com/servian/awskeyring/compare/v0.7.0...v0.7.1)
71
-
72
- **Fixed bugs:**
73
-
74
- - Trailing LF was being passed to validator [\#37](https://github.com/servian/awskeyring/pull/37) ([tristanmorgan](https://github.com/tristanmorgan))
75
-
76
- ## [v0.7.0](https://github.com/servian/awskeyring/tree/v0.7.0) (2018-11-26)
77
- [Full Changelog](https://github.com/servian/awskeyring/compare/v0.6.0...v0.7.0)
78
-
79
- **Implemented enhancements:**
80
-
81
- - Validate existing account. [\#35](https://github.com/servian/awskeyring/pull/35) ([tristanmorgan](https://github.com/tristanmorgan))
82
- - Swap Highline for Thor::LineEditor [\#34](https://github.com/servian/awskeyring/pull/34) ([tristanmorgan](https://github.com/tristanmorgan))
83
-
84
- ## [v0.6.0](https://github.com/servian/awskeyring/tree/v0.6.0) (2018-10-18)
85
- [Full Changelog](https://github.com/servian/awskeyring/compare/v0.5.3...v0.6.0)
86
-
87
- **Fixed bugs:**
88
-
89
- - Use a default Region for Rotate. [\#33](https://github.com/servian/awskeyring/pull/33) ([tristanmorgan](https://github.com/tristanmorgan))
90
- - Fix JSON time format to use ISO8601. [\#32](https://github.com/servian/awskeyring/pull/32) ([tristanmorgan](https://github.com/tristanmorgan))
91
-
92
- ## [v0.5.3](https://github.com/servian/awskeyring/tree/v0.5.3) (2018-10-03)
93
- [Full Changelog](https://github.com/servian/awskeyring/compare/v0.5.2...v0.5.3)
94
-
95
- **Implemented enhancements:**
96
-
97
- - Console favourites [\#31](https://github.com/servian/awskeyring/pull/31) ([tristanmorgan](https://github.com/tristanmorgan))
98
-
99
- ## [v0.5.2](https://github.com/servian/awskeyring/tree/v0.5.2) (2018-09-18)
100
- [Full Changelog](https://github.com/servian/awskeyring/compare/v0.5.1...v0.5.2)
101
-
102
- **Implemented enhancements:**
103
-
104
- - More robust autocomplete. [\#30](https://github.com/servian/awskeyring/pull/30) ([tristanmorgan](https://github.com/tristanmorgan))
105
-
106
- ## [v0.5.1](https://github.com/servian/awskeyring/tree/v0.5.1) (2018-09-12)
107
- [Full Changelog](https://github.com/servian/awskeyring/compare/v0.5.0...v0.5.1)
108
-
109
- **Implemented enhancements:**
110
-
111
- - Autocomplete flags too. [\#29](https://github.com/servian/awskeyring/pull/29) ([tristanmorgan](https://github.com/tristanmorgan))
112
-
113
- ## [v0.5.0](https://github.com/servian/awskeyring/tree/v0.5.0) (2018-09-10)
114
- [Full Changelog](https://github.com/servian/awskeyring/compare/v0.4.0...v0.5.0)
115
-
116
- **Implemented enhancements:**
117
-
118
- - Separate update account from add account. [\#28](https://github.com/servian/awskeyring/pull/28) ([tristanmorgan](https://github.com/tristanmorgan))
119
-
120
- **Merged pull requests:**
121
-
122
- - Refactor [\#27](https://github.com/servian/awskeyring/pull/27) ([tristanmorgan](https://github.com/tristanmorgan))
123
-
124
- ## [v0.4.0](https://github.com/servian/awskeyring/tree/v0.4.0) (2018-08-21)
125
- [Full Changelog](https://github.com/servian/awskeyring/compare/v0.3.1...v0.4.0)
126
-
127
- **Implemented enhancements:**
128
-
129
- - I18n - Internationalisation [\#26](https://github.com/servian/awskeyring/pull/26) ([tristanmorgan](https://github.com/tristanmorgan))
130
- - Adds no token flag to skip saved token [\#25](https://github.com/servian/awskeyring/pull/25) ([tristanmorgan](https://github.com/tristanmorgan))
131
-
132
- ## [v0.3.1](https://github.com/servian/awskeyring/tree/v0.3.1) (2018-07-25)
133
- [Full Changelog](https://github.com/servian/awskeyring/compare/v0.3.0...v0.3.1)
134
-
135
- **Implemented enhancements:**
136
-
137
- - Warn about key-age [\#24](https://github.com/servian/awskeyring/pull/24) ([tristanmorgan](https://github.com/tristanmorgan))
138
-
139
- **Fixed bugs:**
140
-
141
- - Error adding account when region is not specified [\#21](https://github.com/servian/awskeyring/issues/21)
142
- - Check more locations for current region. [\#23](https://github.com/servian/awskeyring/pull/23) ([tristanmorgan](https://github.com/tristanmorgan))
143
-
144
- **Merged pull requests:**
145
-
146
- - Set a default region on cred verify. [\#22](https://github.com/servian/awskeyring/pull/22) ([tristanmorgan](https://github.com/tristanmorgan))
147
-
148
- ## [v0.3.0](https://github.com/servian/awskeyring/tree/v0.3.0) (2018-04-12)
149
- [Full Changelog](https://github.com/servian/awskeyring/compare/v0.2.0...v0.3.0)
150
-
151
- **Implemented enhancements:**
152
-
153
- - Validate tokens upon adding them to the keychain [\#18](https://github.com/servian/awskeyring/issues/18)
154
- - Generate a token from IAM User credentials using the GetFederationToken API [\#17](https://github.com/servian/awskeyring/issues/17)
155
- - Test creds against AWS API \(optionally\). [\#20](https://github.com/servian/awskeyring/pull/20) ([tristanmorgan](https://github.com/tristanmorgan))
156
- - Allow STS get\_session\_token without role [\#19](https://github.com/servian/awskeyring/pull/19) ([tristanmorgan](https://github.com/tristanmorgan))
157
-
158
- ## [v0.2.0](https://github.com/servian/awskeyring/tree/v0.2.0) (2018-04-05)
159
- [Full Changelog](https://github.com/servian/awskeyring/compare/v0.1.1...v0.2.0)
160
-
161
- **Implemented enhancements:**
162
-
163
- - Add AWS CLI credential\_process compatible JSON output [\#16](https://github.com/servian/awskeyring/pull/16) ([tristanmorgan](https://github.com/tristanmorgan))
164
-
165
- ## [v0.1.1](https://github.com/servian/awskeyring/tree/v0.1.1) (2018-03-25)
166
- [Full Changelog](https://github.com/servian/awskeyring/compare/v0.1.0...v0.1.1)
167
-
168
- **Merged pull requests:**
169
-
170
- - More coverage with tests. [\#15](https://github.com/servian/awskeyring/pull/15) ([tristanmorgan](https://github.com/tristanmorgan))
171
- - Validate MFA code and tweak Autocomplete [\#14](https://github.com/servian/awskeyring/pull/14) ([tristanmorgan](https://github.com/tristanmorgan))
172
-
173
- ## [v0.1.0](https://github.com/servian/awskeyring/tree/v0.1.0) (2018-03-14)
174
- [Full Changelog](https://github.com/servian/awskeyring/compare/v0.0.6...v0.1.0)
175
-
176
- **Implemented enhancements:**
177
-
178
- - Item refactor [\#13](https://github.com/servian/awskeyring/pull/13) ([tristanmorgan](https://github.com/tristanmorgan))
179
- - Aws refactor [\#12](https://github.com/servian/awskeyring/pull/12) ([tristanmorgan](https://github.com/tristanmorgan))
180
-
181
- ## [v0.0.6](https://github.com/servian/awskeyring/tree/v0.0.6) (2018-03-01)
182
- [Full Changelog](https://github.com/servian/awskeyring/compare/v0.0.5...v0.0.6)
183
-
184
- **Implemented enhancements:**
185
-
186
- - Credential Rotation Feature [\#4](https://github.com/servian/awskeyring/issues/4)
187
- - Rotate credentials feature. [\#11](https://github.com/servian/awskeyring/pull/11) ([tristanmorgan](https://github.com/tristanmorgan))
188
-
189
- **Merged pull requests:**
190
-
191
- - Input validation [\#10](https://github.com/servian/awskeyring/pull/10) ([tristanmorgan](https://github.com/tristanmorgan))
192
- - Adding a check for incorrect file modes. [\#9](https://github.com/servian/awskeyring/pull/9) ([tristanmorgan](https://github.com/tristanmorgan))
193
-
194
- ## [v0.0.5](https://github.com/servian/awskeyring/tree/v0.0.5) (2018-02-15)
195
- [Full Changelog](https://github.com/servian/awskeyring/compare/v0.0.4...v0.0.5)
196
-
197
- **Fixed bugs:**
198
-
199
- - Issue on add [\#7](https://github.com/servian/awskeyring/issues/7)
200
-
201
- **Merged pull requests:**
202
-
203
- - fix issue \#7 and add a path to open console. [\#8](https://github.com/servian/awskeyring/pull/8) ([tristanmorgan](https://github.com/tristanmorgan))
204
-
205
- ## [v0.0.4](https://github.com/servian/awskeyring/tree/v0.0.4) (2018-01-29)
206
- [Full Changelog](https://github.com/servian/awskeyring/compare/v0.0.3...v0.0.4)
207
-
208
- ## [v0.0.3](https://github.com/servian/awskeyring/tree/v0.0.3) (2018-01-28)
209
- [Full Changelog](https://github.com/servian/awskeyring/compare/v0.0.2...v0.0.3)
210
-
211
- **Implemented enhancements:**
212
-
213
- - Remove Token feature [\#5](https://github.com/servian/awskeyring/issues/5)
214
- - Implement exec command [\#2](https://github.com/servian/awskeyring/issues/2)
215
- - Add Remove token feature [\#6](https://github.com/servian/awskeyring/pull/6) ([tristanmorgan](https://github.com/tristanmorgan))
216
- - Implement exec feature. [\#3](https://github.com/servian/awskeyring/pull/3) ([tristanmorgan](https://github.com/tristanmorgan))
217
-
218
- ## [v0.0.2](https://github.com/servian/awskeyring/tree/v0.0.2) (2018-01-18)
219
- [Full Changelog](https://github.com/servian/awskeyring/compare/v0.0.1...v0.0.2)
220
-
221
- **Merged pull requests:**
222
-
223
- - Sledgehammer disable of rubocop metrics. [\#1](https://github.com/servian/awskeyring/pull/1) ([tristanmorgan](https://github.com/tristanmorgan))
224
-
225
- ## [v0.0.1](https://github.com/servian/awskeyring/tree/v0.0.1) (2017-12-25)
226
41
 
227
42
 
228
- \* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
43
+ \* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)*
data/Rakefile CHANGED
@@ -7,7 +7,10 @@ require 'github_changelog_generator/task'
7
7
  require 'yard'
8
8
 
9
9
  GitHubChangelogGenerator::RakeTask.new :changelog do |config|
10
+ config.user = 'servian'
11
+ config.project = 'awskeyring'
10
12
  config.future_release = "v#{Awskeyring::VERSION}"
13
+ config.since_tag = 'v0.10.0'
11
14
  end
12
15
 
13
16
  RuboCop::RakeTask.new do |rubocop|
@@ -302,4 +302,24 @@ module Awskeyring # rubocop:disable Metrics/ModuleLength
302
302
 
303
303
  account_name
304
304
  end
305
+
306
+ # Validate role exists
307
+ #
308
+ # @param [String] role_name the associated role name.
309
+ def self.role_exists(role_name)
310
+ Awskeyring::Validate.role_name(role_name)
311
+ raise 'Role does not exist' unless list_role_names.include?(role_name)
312
+
313
+ role_name
314
+ end
315
+
316
+ # Validate role does not exists
317
+ #
318
+ # @param [String] role_name the associated role name.
319
+ def self.role_not_exists(role_name)
320
+ Awskeyring::Validate.role_name(role_name)
321
+ raise 'Role already exists' if list_role_names.include?(role_name)
322
+
323
+ role_name
324
+ end
305
325
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Awskeyring
4
4
  # The Gem's version number
5
- VERSION = '1.0.2'
5
+ VERSION = '1.1.0'
6
6
  # The Gem's homepage
7
7
  HOMEPAGE = 'https://github.com/servian/awskeyring'
8
8
  end
@@ -44,7 +44,12 @@ class AwskeyringCommand < Thor # rubocop:disable Metrics/ClassLength
44
44
  exit 1
45
45
  end
46
46
 
47
- keychain = ask_missing(existing: options[:keychain], message: I18n.t('message.keychain'))
47
+ keychain = ask_check(
48
+ existing: options[:keychain],
49
+ flags: 'optional',
50
+ message: I18n.t('message.keychain'),
51
+ validator: Awskeyring::Validate.method(:account_name)
52
+ )
48
53
  keychain = 'awskeyring' if keychain.empty?
49
54
 
50
55
  puts I18n.t('message.newkeychain')
@@ -78,7 +83,8 @@ class AwskeyringCommand < Thor # rubocop:disable Metrics/ClassLength
78
83
  else
79
84
  account = ask_check(
80
85
  existing: account, message: I18n.t('message.account'),
81
- validator: Awskeyring.method(:account_exists)
86
+ validator: Awskeyring.method(:account_exists),
87
+ limited_to: Awskeyring.list_account_names
82
88
  )
83
89
  cred = age_check_and_get(account: account, no_token: options['no-token'])
84
90
  put_env_string(cred)
@@ -88,7 +94,7 @@ class AwskeyringCommand < Thor # rubocop:disable Metrics/ClassLength
88
94
  desc 'json ACCOUNT', I18n.t('json.desc')
89
95
  method_option 'no-token', type: :boolean, aliases: '-n', desc: I18n.t('method_option.notoken'), default: false
90
96
  # Print JSON for use with credential_process
91
- def json(account = nil)
97
+ def json(account)
92
98
  account = ask_check(
93
99
  existing: account, message: I18n.t('message.account'), validator: Awskeyring.method(:account_exists)
94
100
  )
@@ -137,11 +143,11 @@ class AwskeyringCommand < Thor # rubocop:disable Metrics/ClassLength
137
143
  )
138
144
  secret = ask_check(
139
145
  existing: options[:secret], message: I18n.t('message.secret'),
140
- secure: true, validator: Awskeyring::Validate.method(:secret_access_key)
146
+ flags: 'secure', validator: Awskeyring::Validate.method(:secret_access_key)
141
147
  )
142
148
  mfa = ask_check(
143
149
  existing: options[:mfa], message: I18n.t('message.mfa'),
144
- optional: true, validator: Awskeyring::Validate.method(:mfa_arn)
150
+ flags: 'optional', validator: Awskeyring::Validate.method(:mfa_arn)
145
151
  )
146
152
  Awskeyring::Awsapi.verify_cred(key: key, secret: secret) unless options['no-remote']
147
153
  Awskeyring.add_account(
@@ -158,16 +164,18 @@ class AwskeyringCommand < Thor # rubocop:disable Metrics/ClassLength
158
164
  method_option :secret, type: :string, aliases: '-s', desc: I18n.t('method_option.secret')
159
165
  method_option 'no-remote', type: :boolean, aliases: '-r', desc: I18n.t('method_option.noremote'), default: false
160
166
  # Update an Account
161
- def update(account = nil) # rubocop:disable Metrics/MethodLength
167
+ def update(account = nil) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
162
168
  account = ask_check(
163
- existing: account, message: I18n.t('message.account'), validator: Awskeyring.method(:account_exists)
169
+ existing: account, message: I18n.t('message.account'),
170
+ validator: Awskeyring.method(:account_exists),
171
+ limited_to: Awskeyring.list_account_names
164
172
  )
165
173
  key = ask_check(
166
174
  existing: options[:key], message: I18n.t('message.key'), validator: Awskeyring::Validate.method(:access_key)
167
175
  )
168
176
  secret = ask_check(
169
177
  existing: options[:secret], message: I18n.t('message.secret'),
170
- secure: true, validator: Awskeyring::Validate.method(:secret_access_key)
178
+ flags: 'secure', validator: Awskeyring::Validate.method(:secret_access_key)
171
179
  )
172
180
  Awskeyring::Awsapi.verify_cred(key: key, secret: secret) unless options['no-remote']
173
181
  Awskeyring.update_account(
@@ -185,7 +193,7 @@ class AwskeyringCommand < Thor # rubocop:disable Metrics/ClassLength
185
193
  def add_role(role = nil)
186
194
  role = ask_check(
187
195
  existing: role, message: I18n.t('message.role'),
188
- validator: Awskeyring::Validate.method(:role_name)
196
+ validator: Awskeyring.method(:role_not_exists)
189
197
  )
190
198
  arn = ask_check(
191
199
  existing: options[:arn], message: I18n.t('message.arn'),
@@ -203,7 +211,8 @@ class AwskeyringCommand < Thor # rubocop:disable Metrics/ClassLength
203
211
  # Remove an account
204
212
  def remove(account = nil)
205
213
  account = ask_check(
206
- existing: account, message: I18n.t('message.account'), validator: Awskeyring.method(:account_exists)
214
+ existing: account, message: I18n.t('message.account'), validator: Awskeyring.method(:account_exists),
215
+ limited_to: Awskeyring.list_account_names
207
216
  )
208
217
  Awskeyring.delete_account(account: account, message: I18n.t('message.delaccount', account: account))
209
218
  end
@@ -212,7 +221,8 @@ class AwskeyringCommand < Thor # rubocop:disable Metrics/ClassLength
212
221
  # remove a session token
213
222
  def remove_token(account = nil)
214
223
  account = ask_check(
215
- existing: account, message: I18n.t('message.account'), validator: Awskeyring.method(:account_exists)
224
+ existing: account, message: I18n.t('message.account'), validator: Awskeyring.method(:account_exists),
225
+ limited_to: Awskeyring.list_account_names
216
226
  )
217
227
  Awskeyring.delete_token(account: account, message: I18n.t('message.deltoken', account: account))
218
228
  end
@@ -222,7 +232,8 @@ class AwskeyringCommand < Thor # rubocop:disable Metrics/ClassLength
222
232
  # remove a role
223
233
  def remove_role(role = nil)
224
234
  role = ask_check(
225
- existing: role, message: I18n.t('message.role'), validator: Awskeyring::Validate.method(:role_name)
235
+ existing: role, message: I18n.t('message.role'), validator: Awskeyring.method(:role_exists),
236
+ limited_to: Awskeyring.list_role_names
226
237
  )
227
238
  Awskeyring.delete_role(role_name: role, message: I18n.t('message.delrole', role: role))
228
239
  end
@@ -231,7 +242,10 @@ class AwskeyringCommand < Thor # rubocop:disable Metrics/ClassLength
231
242
  # rotate Account keys
232
243
  def rotate(account = nil) # rubocop:disable Metrics/MethodLength
233
244
  account = ask_check(
234
- existing: account, message: I18n.t('message.account'), validator: Awskeyring.method(:account_exists)
245
+ existing: account,
246
+ message: I18n.t('message.account'),
247
+ validator: Awskeyring.method(:account_exists),
248
+ limited_to: Awskeyring.list_account_names
235
249
  )
236
250
  cred = Awskeyring.get_valid_creds(account: account, no_token: true)
237
251
 
@@ -263,12 +277,16 @@ class AwskeyringCommand < Thor # rubocop:disable Metrics/ClassLength
263
277
  # generate a sessiopn token
264
278
  def token(account = nil, role = nil, code = nil) # rubocop:disable all
265
279
  account = ask_check(
266
- existing: account, message: I18n.t('message.account'), validator: Awskeyring.method(:account_exists)
280
+ existing: account,
281
+ message: I18n.t('message.account'),
282
+ validator: Awskeyring.method(:account_exists),
283
+ limited_to: Awskeyring.list_account_names
267
284
  )
268
285
  role ||= options[:role]
269
286
  if role
270
287
  role = ask_check(
271
- existing: role, message: I18n.t('message.role'), validator: Awskeyring::Validate.method(:role_name)
288
+ existing: role, message: I18n.t('message.role'), validator: Awskeyring.method(:role_exists),
289
+ limited_to: Awskeyring.list_role_names
272
290
  )
273
291
  end
274
292
  code ||= options[:code]
@@ -320,7 +338,10 @@ class AwskeyringCommand < Thor # rubocop:disable Metrics/ClassLength
320
338
  # Open the AWS Console
321
339
  def console(account = nil) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
322
340
  account = ask_check(
323
- existing: account, message: I18n.t('message.account'), validator: Awskeyring.method(:account_exists)
341
+ existing: account,
342
+ message: I18n.t('message.account'),
343
+ validator: Awskeyring.method(:account_exists),
344
+ limited_to: Awskeyring.list_account_names
324
345
  )
325
346
  cred = age_check_and_get(account: account, no_token: options['no-token'])
326
347
 
@@ -436,11 +457,17 @@ class AwskeyringCommand < Thor # rubocop:disable Metrics/ClassLength
436
457
  Awskeyring::Awsapi::AWS_ENV_VARS.each { |key| puts "unset #{key}" unless env_var.key?(key) }
437
458
  end
438
459
 
439
- def ask_check(existing:, message:, secure: false, optional: false, validator: nil)
460
+ def ask_check(existing:, message:, flags: nil, validator: nil, limited_to: nil) # rubocop:disable Metrics/MethodLength
440
461
  retries ||= 3
441
462
  begin
442
- value = ask_missing(existing: existing, message: message, secure: secure, optional: optional)
443
- value = validator.call(value) unless value.empty? && optional
463
+ value = ask_missing(
464
+ existing: existing,
465
+ message: message,
466
+ secure: 'secure'.eql?(flags),
467
+ optional: 'optional'.eql?(flags),
468
+ limited_to: limited_to
469
+ )
470
+ value = validator.call(value) unless value.empty? && 'optional'.eql?(flags)
444
471
  rescue RuntimeError => e
445
472
  warn e.message
446
473
  existing = nil
@@ -450,15 +477,17 @@ class AwskeyringCommand < Thor # rubocop:disable Metrics/ClassLength
450
477
  value
451
478
  end
452
479
 
453
- def ask_missing(existing:, message:, secure: false, optional: false)
454
- existing || ask(message: message, secure: secure, optional: optional).strip
480
+ def ask_missing(existing:, message:, secure: false, optional: false, limited_to: nil)
481
+ existing || ask(message: message, secure: secure, optional: optional, limited_to: limited_to).strip
455
482
  end
456
483
 
457
- def ask(message:, secure: false, optional: false)
484
+ def ask(message:, secure: false, optional: false, limited_to: nil)
458
485
  if secure
459
486
  Awskeyring::Input.read_secret(message.rjust(20) + ': ')
460
487
  elsif optional
461
488
  Thor::LineEditor.readline((message + ' (optional)').rjust(20) + ': ')
489
+ elsif limited_to
490
+ Thor::LineEditor.readline(message.rjust(20) + ': ', limited_to: limited_to)
462
491
  else
463
492
  Thor::LineEditor.readline(message.rjust(20) + ': ')
464
493
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: awskeyring
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tristan Morgan
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-10-18 00:00:00.000000000 Z
11
+ date: 2019-11-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-iam