awskeyring 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -1
- data/README.md +10 -3
- data/lib/awskeyring/awsapi.rb +19 -1
- data/lib/awskeyring/version.rb +1 -1
- data/lib/awskeyring.rb +3 -1
- data/lib/awskeyring_command.rb +58 -21
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e905b5fccdebddbc839f898423c513e8c3c3475
|
4
|
+
data.tar.gz: da11dceb9c06415e01647a2de7512103df2d951d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c6b3db63fda21933153f5eb38be4a24e07701709c3d893b71c5266d8faca9b0385060dbdde6bac3ebad69d42077e8ae1e6199a74996e996be37f12883f299f8
|
7
|
+
data.tar.gz: d7db72c1d2f8a1d33508c113a5b8866dc48c5fc53017a89b9b14d8e7dae05d48e4ee1d8ac0f69d83d4041e48e3fbadb26f3847824c7240666ae2525018715c1d
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,13 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
-
## [v0.
|
3
|
+
## [v0.2.0](https://github.com/vibrato/awskeyring/tree/v0.2.0) (2018-04-05)
|
4
|
+
[Full Changelog](https://github.com/vibrato/awskeyring/compare/v0.1.1...v0.2.0)
|
5
|
+
|
6
|
+
**Implemented enhancements:**
|
7
|
+
|
8
|
+
- Add AWS CLI credential\_process compatible JSON output [\#16](https://github.com/vibrato/awskeyring/pull/16) ([tristanmorgan](https://github.com/tristanmorgan))
|
9
|
+
|
10
|
+
## [v0.1.1](https://github.com/vibrato/awskeyring/tree/v0.1.1) (2018-03-25)
|
4
11
|
[Full Changelog](https://github.com/vibrato/awskeyring/compare/v0.1.0...v0.1.1)
|
5
12
|
|
6
13
|
**Merged pull requests:**
|
data/README.md
CHANGED
@@ -32,13 +32,19 @@ Now your keys are stored safely in the macOS keychain. To print environment vari
|
|
32
32
|
|
33
33
|
awskeyring env personal-aws
|
34
34
|
|
35
|
-
|
35
|
+
Alternatively you can create a profile using the credential_process config variable. See the [AWS CLI Config docs](http://docs.aws.amazon.com/cli/latest/topic/config-vars.html#cli-aws-help-config-vars) for more details on this config option.
|
36
|
+
|
37
|
+
[profile personal]
|
38
|
+
region = us-west-1
|
39
|
+
credential_process = awskeyring json personal-aws
|
40
|
+
|
41
|
+
See below and in the [wiki](https://github.com/vibrato/awskeyring/wiki) for more details on usage.
|
36
42
|
|
37
43
|
## Installation
|
38
44
|
|
39
45
|
Install it with:
|
40
46
|
|
41
|
-
$ gem install awskeyring
|
47
|
+
$ gem install awskeyring --user-install
|
42
48
|
|
43
49
|
## Usage
|
44
50
|
|
@@ -53,6 +59,7 @@ The CLI is using [Thor](http://whatisthor.com) with help provided interactively.
|
|
53
59
|
awskeyring exec ACCOUNT command... # Execute a COMMAND with the environment set for an ACCOUNT
|
54
60
|
awskeyring help [COMMAND] # Describe available commands or one specific command
|
55
61
|
awskeyring initialise # Initialises a new KEYCHAIN
|
62
|
+
awskeyring json ACCOUNT # Outputs AWS CLI compatible JSON for an ACCOUNT
|
56
63
|
awskeyring list # Prints a list of accounts in the keyring
|
57
64
|
awskeyring list-role # Prints a list of roles in the keyring
|
58
65
|
awskeyring remove ACCOUNT # Removes an ACCOUNT from the keyring
|
@@ -73,7 +80,7 @@ To set your environment easily the following bash function helps:
|
|
73
80
|
|
74
81
|
After checking out the repo, run `bundle update` to install dependencies. Then, run `rake` to run the tests. Run `bundle exec awskeyring` to use the gem in this directory, ignoring other installed copies of this gem.
|
75
82
|
|
76
|
-
To install this gem onto your local machine, run `bundle exec rake install`.
|
83
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
77
84
|
|
78
85
|
## Contributing
|
79
86
|
|
data/lib/awskeyring/awsapi.rb
CHANGED
@@ -49,7 +49,7 @@ module Awskeyring
|
|
49
49
|
)
|
50
50
|
end
|
51
51
|
rescue Aws::STS::Errors::AccessDenied => err
|
52
|
-
|
52
|
+
warn err.to_s
|
53
53
|
exit 1
|
54
54
|
end
|
55
55
|
|
@@ -61,6 +61,24 @@ module Awskeyring
|
|
61
61
|
}
|
62
62
|
end
|
63
63
|
|
64
|
+
# Genarates AWS CLI compatible JSON
|
65
|
+
# see credential_process in AWS Docs
|
66
|
+
#
|
67
|
+
# @param [String] key The aws_access_key_id
|
68
|
+
# @param [String] secret The aws_secret_access_key
|
69
|
+
# @param [String] token The aws_session_token
|
70
|
+
# @param [String] expiry expiry time
|
71
|
+
# @return [String] credential_process json
|
72
|
+
def self.get_cred_json(key:, secret:, token:, expiry:)
|
73
|
+
JSON.pretty_generate(
|
74
|
+
Version: 1,
|
75
|
+
AccessKeyId: key,
|
76
|
+
SecretAccessKey: secret,
|
77
|
+
SessionToken: token,
|
78
|
+
Expiration: expiry
|
79
|
+
)
|
80
|
+
end
|
81
|
+
|
64
82
|
# Retrieves an AWS Console login url
|
65
83
|
#
|
66
84
|
# @param [String] key The aws_access_key_id
|
data/lib/awskeyring/version.rb
CHANGED
data/lib/awskeyring.rb
CHANGED
@@ -162,11 +162,13 @@ module Awskeyring # rubocop:disable Metrics/ModuleLength
|
|
162
162
|
def self.get_valid_creds(account:)
|
163
163
|
cred, temp_cred = get_valid_item_pair(account: account)
|
164
164
|
token = temp_cred.password unless temp_cred.nil?
|
165
|
+
expiry = temp_cred.attributes[:account].to_i unless temp_cred.nil?
|
165
166
|
{
|
166
167
|
account: account,
|
167
168
|
key: cred.attributes[:account],
|
168
169
|
secret: cred.password,
|
169
|
-
token: token
|
170
|
+
token: token,
|
171
|
+
expiry: expiry
|
170
172
|
}
|
171
173
|
end
|
172
174
|
|
data/lib/awskeyring_command.rb
CHANGED
@@ -76,6 +76,22 @@ class AwskeyringCommand < Thor # rubocop:disable Metrics/ClassLength
|
|
76
76
|
)
|
77
77
|
end
|
78
78
|
|
79
|
+
desc 'json ACCOUNT', 'Outputs AWS CLI compatible JSON for an ACCOUNT'
|
80
|
+
# Print JSON for use with credential_process
|
81
|
+
def json(account = nil)
|
82
|
+
account = ask_check(
|
83
|
+
existing: account, message: 'account name', validator: Awskeyring::Validate.method(:account_name)
|
84
|
+
)
|
85
|
+
cred = Awskeyring.get_valid_creds(account: account)
|
86
|
+
expiry = Time.at(cred[:expiry]) unless cred[:expiry].nil?
|
87
|
+
puts Awskeyring::Awsapi.get_cred_json(
|
88
|
+
key: cred[:key],
|
89
|
+
secret: cred[:secret],
|
90
|
+
token: cred[:token],
|
91
|
+
expiry: expiry || Time.new + 3600
|
92
|
+
)
|
93
|
+
end
|
94
|
+
|
79
95
|
desc 'exec ACCOUNT command...', 'Execute a COMMAND with the environment set for an ACCOUNT'
|
80
96
|
# execute an external command with env set
|
81
97
|
def exec(account, *command)
|
@@ -166,12 +182,23 @@ class AwskeyringCommand < Thor # rubocop:disable Metrics/ClassLength
|
|
166
182
|
|
167
183
|
desc 'rotate ACCOUNT', 'Rotate access keys for an ACCOUNT'
|
168
184
|
# rotate Account keys
|
169
|
-
def rotate(account = nil)
|
185
|
+
def rotate(account = nil) # rubocop:disable Metrics/MethodLength
|
170
186
|
account = ask_check(
|
171
187
|
existing: account, message: 'account name', validator: Awskeyring::Validate.method(:account_name)
|
172
188
|
)
|
173
189
|
item_hash = Awskeyring.get_account_hash(account: account)
|
174
|
-
|
190
|
+
|
191
|
+
begin
|
192
|
+
new_key = Awskeyring::Awsapi.rotate(
|
193
|
+
account: item_hash[:account],
|
194
|
+
key: item_hash[:key],
|
195
|
+
secret: item_hash[:secret]
|
196
|
+
)
|
197
|
+
rescue Aws::Errors::ServiceError => err
|
198
|
+
warn err.to_s
|
199
|
+
exit 1
|
200
|
+
end
|
201
|
+
|
175
202
|
Awskeyring.update_account(
|
176
203
|
account: account,
|
177
204
|
key: new_key[:key],
|
@@ -216,15 +243,20 @@ class AwskeyringCommand < Thor # rubocop:disable Metrics/ClassLength
|
|
216
243
|
item_hash = Awskeyring.get_account_hash(account: account)
|
217
244
|
role_arn = Awskeyring.get_role_arn(role_name: role) if role
|
218
245
|
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
246
|
+
begin
|
247
|
+
new_creds = Awskeyring::Awsapi.get_token(
|
248
|
+
code: code,
|
249
|
+
role_arn: role_arn,
|
250
|
+
duration: duration,
|
251
|
+
mfa: item_hash[:mfa],
|
252
|
+
key: item_hash[:key],
|
253
|
+
secret: item_hash[:secret],
|
254
|
+
user: ENV['USER']
|
255
|
+
)
|
256
|
+
rescue Aws::Errors::ServiceError => err
|
257
|
+
warn err.to_s
|
258
|
+
exit 1
|
259
|
+
end
|
228
260
|
|
229
261
|
Awskeyring.add_token(
|
230
262
|
account: account,
|
@@ -241,7 +273,7 @@ class AwskeyringCommand < Thor # rubocop:disable Metrics/ClassLength
|
|
241
273
|
desc 'console ACCOUNT', 'Open the AWS Console for the ACCOUNT'
|
242
274
|
method_option :path, type: :string, aliases: '-p', desc: 'The service PATH to open.'
|
243
275
|
# Open the AWS Console
|
244
|
-
def console(account = nil)
|
276
|
+
def console(account = nil) # rubocop:disable Metrics/MethodLength
|
245
277
|
account = ask_check(
|
246
278
|
existing: account, message: 'account name', validator: Awskeyring::Validate.method(:account_name)
|
247
279
|
)
|
@@ -249,13 +281,18 @@ class AwskeyringCommand < Thor # rubocop:disable Metrics/ClassLength
|
|
249
281
|
|
250
282
|
path = options[:path] || 'console'
|
251
283
|
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
284
|
+
begin
|
285
|
+
login_url = Awskeyring::Awsapi.get_login_url(
|
286
|
+
key: cred[:key],
|
287
|
+
secret: cred[:secret],
|
288
|
+
token: cred[:token],
|
289
|
+
path: path,
|
290
|
+
user: ENV['USER']
|
291
|
+
)
|
292
|
+
rescue Aws::Errors::ServiceError => err
|
293
|
+
warn err.to_s
|
294
|
+
exit 1
|
295
|
+
end
|
259
296
|
|
260
297
|
pid = Process.spawn("open \"#{login_url}\"")
|
261
298
|
Process.wait pid
|
@@ -329,8 +366,8 @@ class AwskeyringCommand < Thor # rubocop:disable Metrics/ClassLength
|
|
329
366
|
begin
|
330
367
|
value = ask_missing(existing: existing, message: message, secure: secure, optional: optional)
|
331
368
|
value = validator.call(value) unless value.empty? && optional
|
332
|
-
rescue RuntimeError =>
|
333
|
-
warn
|
369
|
+
rescue RuntimeError => err
|
370
|
+
warn err.message
|
334
371
|
existing = nil
|
335
372
|
retry unless (retries -= 1).zero?
|
336
373
|
exit 1
|
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: 0.
|
4
|
+
version: 0.2.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: 2018-
|
11
|
+
date: 2018-04-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk-iam
|