aws_cli_config_parser 0.1.0 → 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 +4 -0
- data/Gemfile.lock +3 -3
- data/README.md +36 -7
- data/aws_cli_config_parser.gemspec +12 -12
- data/bin/aws_cli_config_parser +9 -0
- data/lib/aws_cli_config_parser/cli.rb +70 -0
- data/lib/aws_cli_config_parser/cli/arguments.rb +14 -0
- data/lib/aws_cli_config_parser/refined/strings.rb +15 -0
- data/lib/aws_cli_config_parser/version.rb +1 -1
- metadata +9 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f8c25969c12735b879ffcc5a81a379394470e0d718c73ad9efd7a12762efeb76
|
4
|
+
data.tar.gz: d29b6630a7df7750a4052883d1c8f846273e3110a8419cc11b21a27bc78c195d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dcc6e615d2e26dcca17def0aacded8085fde1a7e76ee9cf771d088efcb58d09e342b83cf843e0696de3541b7175bbbce46a387ec88db45c8bfc4d7663ea6d87b
|
7
|
+
data.tar.gz: 5d51bcfe4c57079bb4722d3738413fb5c6bac52f6b0d19eead9e456d840e3477cc881ecaa682d1318df959e9e546fd26ca7802f8b06e110c94ba305d49545bd8
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
aws_cli_config_parser (0.
|
4
|
+
aws_cli_config_parser (0.2.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -10,7 +10,7 @@ GEM
|
|
10
10
|
rake (13.0.3)
|
11
11
|
|
12
12
|
PLATFORMS
|
13
|
-
x86_64-linux
|
13
|
+
x86_64-linux
|
14
14
|
|
15
15
|
DEPENDENCIES
|
16
16
|
aws_cli_config_parser!
|
@@ -18,4 +18,4 @@ DEPENDENCIES
|
|
18
18
|
rake (~> 13.0)
|
19
19
|
|
20
20
|
BUNDLED WITH
|
21
|
-
2.2.
|
21
|
+
2.2.17
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# AWS CLI Configuration Parser
|
2
2
|
|
3
|
-
This Ruby gem provides a tool to parse profile settings and secrets from AWS CLI configuration files, including
|
3
|
+
This Ruby gem provides a tool to parse profile settings and secrets from AWS CLI configuration files, including temporary credentials cached by the CLI when using IAM roles. This is often useful when using CLI profiles that assume roles requiring an MFA code. After authenticating successfully with an MFA code, temporary session credentials are cached in your `~/.aws` folder. You'll often need to pass these temporary credentials to other tools such as Docker containers. This gem parses the files in your `~/.aws` folder and merges all information allowing you to retrieve any credential or setting.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -47,7 +47,7 @@ region = eu-central-1
|
|
47
47
|
**~/.aws/credentials**
|
48
48
|
```
|
49
49
|
[default]
|
50
|
-
aws_access_key_id =
|
50
|
+
aws_access_key_id = ASIA1111000011110000
|
51
51
|
aws_secret_access_key = SECRET1111000011110000111100001111000011
|
52
52
|
```
|
53
53
|
|
@@ -55,7 +55,7 @@ aws_secret_access_key = SECRET1111000011110000111100001111000011
|
|
55
55
|
```
|
56
56
|
{
|
57
57
|
"Credentials": {
|
58
|
-
"AccessKeyId": "
|
58
|
+
"AccessKeyId": "ASIA2222000022220000",
|
59
59
|
"SecretAccessKey": "SECRET2222000022220000222200002222000022",
|
60
60
|
"SessionToken": "SESSIONTOKEN222200002222000022220000222200002222000022220000etc",
|
61
61
|
"Expiration": "<some timestamp in the future>"
|
@@ -80,7 +80,7 @@ default = profiles.get('default')
|
|
80
80
|
default.get('region')
|
81
81
|
# => "eu-west-1"
|
82
82
|
default.get('aws_access_key_id')
|
83
|
-
# => "
|
83
|
+
# => "ASIA1111000011110000"
|
84
84
|
default.get('aws_secret_access_key')
|
85
85
|
# => "SECRET1111000011110000111100001111000011"
|
86
86
|
|
@@ -92,7 +92,7 @@ admin.get('region')
|
|
92
92
|
admin.get('role_arn')
|
93
93
|
# => "arn:aws:iam::222200002222:role/SomeRole"
|
94
94
|
admin.get('aws_access_key_id')
|
95
|
-
# => "
|
95
|
+
# => "ASIA2222000022220000"
|
96
96
|
admin.get('aws_secret_access_key')
|
97
97
|
# => "SECRET2222000022220000222200002222000022"
|
98
98
|
admin.get('aws_session_token')
|
@@ -105,7 +105,7 @@ Or if you prefer using hashes:
|
|
105
105
|
AwsCliConfigParser.parse.to_h == {
|
106
106
|
'default' => {
|
107
107
|
'region' => 'eu-west-1',
|
108
|
-
'aws_access_key_id' => '
|
108
|
+
'aws_access_key_id' => 'ASIA1111000011110000',
|
109
109
|
'aws_secret_access_key' => 'SECRET1111000011110000111100001111000011'
|
110
110
|
},
|
111
111
|
'admin' => {
|
@@ -113,7 +113,7 @@ AwsCliConfigParser.parse.to_h == {
|
|
113
113
|
'role_arn' => 'arn:aws:iam::222200002222:role/SomeRole',
|
114
114
|
'source_profile' => 'default',
|
115
115
|
'role_session_name' => 'session_name',
|
116
|
-
'aws_access_key_id' => '
|
116
|
+
'aws_access_key_id' => 'ASIA2222000022220000',
|
117
117
|
'aws_secret_access_key' => 'SECRET2222000022220000222200002222000022',
|
118
118
|
'aws_session_token' => 'SESSIONTOKEN222200002222000022220000222200002222000022220000etc',
|
119
119
|
}
|
@@ -128,6 +128,35 @@ AwsCliConfigParser.parse(aws_directory: '/somewhere/else/.my-aws-folder')
|
|
128
128
|
# => ...
|
129
129
|
```
|
130
130
|
|
131
|
+
### CLI frontend
|
132
|
+
|
133
|
+
This gem includes a limited CLI frontend. You can obtain a configuration value like this:
|
134
|
+
|
135
|
+
```sh
|
136
|
+
aws_cli_config_parser --profile admin --key aws_access_key_id
|
137
|
+
# ASIA2222000022220000
|
138
|
+
aws_cli_config_parser -p admin -k aws_access_key_id
|
139
|
+
# ASIA2222000022220000
|
140
|
+
```
|
141
|
+
|
142
|
+
You can optionally define a fallback value to be returned in case the specified profile does not exist or the configuration parameter is not defined:
|
143
|
+
|
144
|
+
```sh
|
145
|
+
aws_cli_config_parser --profile bogus --key aws_access_key_id --fallback OOOPS
|
146
|
+
# OOOPS
|
147
|
+
aws_cli_config_parser -p bogus -k aws_access_key_id -f OOOPS
|
148
|
+
# OOOPS
|
149
|
+
```
|
150
|
+
|
151
|
+
You can also specify a custom directory where the command will look for your AWS CLI configuration files:
|
152
|
+
|
153
|
+
```sh
|
154
|
+
aws_cli_config_parser --profile someone --key aws_access_key_id --directory /somewhere/else/.my-aws-folder
|
155
|
+
# ASIA................
|
156
|
+
aws_cli_config_parser -p someone -k aws_access_key_id -d /somewhere/else/.my-aws-folder
|
157
|
+
# ASIA................
|
158
|
+
```
|
159
|
+
|
131
160
|
|
132
161
|
## License
|
133
162
|
|
@@ -3,22 +3,22 @@
|
|
3
3
|
require_relative 'lib/aws_cli_config_parser/version'
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
|
-
spec.name
|
7
|
-
spec.version
|
8
|
-
spec.authors
|
9
|
-
|
10
|
-
spec.
|
11
|
-
spec.
|
6
|
+
spec.name = 'aws_cli_config_parser'
|
7
|
+
spec.version = AwsCliConfigParser::VERSION
|
8
|
+
spec.authors = ['brunze']
|
9
|
+
spec.homepage = 'https://github.com/brunze/aws_cli_config_parser'
|
10
|
+
spec.license = 'MIT'
|
11
|
+
spec.summary = 'Parses profile settings from AWS CLI configuration files.'
|
12
|
+
spec.description = <<~DESCRIPTION.strip
|
12
13
|
Parses profile settings and secrets from AWS CLI configuration files,
|
13
|
-
including
|
14
|
+
including temporary credentials cached by the CLI when using roles.
|
14
15
|
DESCRIPTION
|
15
|
-
|
16
|
-
spec.license = 'MIT'
|
16
|
+
|
17
17
|
spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
|
18
18
|
|
19
|
-
spec.metadata['homepage_uri']
|
19
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
20
20
|
spec.metadata['source_code_uri'] = spec.homepage
|
21
|
-
spec.metadata['changelog_uri']
|
21
|
+
spec.metadata['changelog_uri'] = spec.homepage + '/CHANGELOG.md'
|
22
22
|
|
23
23
|
# Specify which files should be added to the gem when it is released.
|
24
24
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
|
|
26
26
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
27
27
|
end
|
28
28
|
spec.bindir = 'bin'
|
29
|
-
spec.executables =
|
29
|
+
spec.executables = ['aws_cli_config_parser']
|
30
30
|
spec.require_paths = ['lib']
|
31
31
|
|
32
32
|
# Uncomment to register a new dependency of your gem
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'aws_cli_config_parser'
|
4
|
+
|
5
|
+
class AwsCliConfigParser::CLI; end
|
6
|
+
|
7
|
+
require 'aws_cli_config_parser/cli/arguments'
|
8
|
+
require 'optparse'
|
9
|
+
|
10
|
+
class AwsCliConfigParser::CLI
|
11
|
+
|
12
|
+
def dispatch argv
|
13
|
+
arguments = parse_arguments(argv).validated!
|
14
|
+
fallback = arguments.fallback_value
|
15
|
+
|
16
|
+
profiles = AwsCliConfigParser.parse(
|
17
|
+
aws_directory: arguments.aws_directory || '~/.aws',
|
18
|
+
)
|
19
|
+
|
20
|
+
if (profile = profiles.get(arguments.profile_name)).nil? && fallback.nil?
|
21
|
+
$stderr.puts "could not find profile `#{arguments.profile_name}`"
|
22
|
+
exit 1
|
23
|
+
elsif (value = profile&.get(arguments.parameter_name)).nil? && fallback.nil?
|
24
|
+
$stderr.puts "could not find a value for the parameter `#{arguments.parameter_name}`"
|
25
|
+
exit 1
|
26
|
+
else
|
27
|
+
puts value || fallback
|
28
|
+
exit 0
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def parse_arguments argv
|
35
|
+
Arguments.new.tap do |arguments|
|
36
|
+
OptionParser.new do |parser|
|
37
|
+
parser.banner = <<~BANNER
|
38
|
+
Extracts a configuration value from AWS CLI configuration files.
|
39
|
+
|
40
|
+
Usage: aws_cli_config_parser -p PROFILE -k KEY [-f FALLBACK] [-d AWS_DIRECTORY]
|
41
|
+
|
42
|
+
BANNER
|
43
|
+
|
44
|
+
parser.on('-p', '--profile=PROFILE', 'Profile from which to extract the configuration value.') do |profile|
|
45
|
+
arguments.profile_name = profile
|
46
|
+
end
|
47
|
+
parser.on('-k', '--key=KEY', 'Name of the configuration parameter to extract.') do |key|
|
48
|
+
arguments.parameter_name = key
|
49
|
+
end
|
50
|
+
parser.on('-f', '--fallback=VALUE', 'A default value to be returned in case a configuration value cannot be found.') do |value|
|
51
|
+
arguments.fallback_value = value
|
52
|
+
end
|
53
|
+
parser.on('-d', '--directory=PATH', 'Path to the AWS CLI configuration directory (default: `~/.aws`).') do |path|
|
54
|
+
arguments.aws_directory = path
|
55
|
+
end
|
56
|
+
|
57
|
+
parser.on_tail('-h', '--help', 'Prints this message.') do
|
58
|
+
puts parser.help
|
59
|
+
exit
|
60
|
+
end
|
61
|
+
parser.on_tail('-v', '--version', 'Prints the program version.') do
|
62
|
+
puts AwsCliConfigParser::VERSION
|
63
|
+
exit
|
64
|
+
end
|
65
|
+
end
|
66
|
+
.parse!(argv)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'aws_cli_config_parser/refined/strings'
|
2
|
+
|
3
|
+
class AwsCliConfigParser::CLI::Arguments
|
4
|
+
using AwsCliConfigParser::Refined::Strings
|
5
|
+
|
6
|
+
attr_accessor :profile_name, :parameter_name, :aws_directory, :fallback_value
|
7
|
+
|
8
|
+
def validated!
|
9
|
+
raise TypeError, "profile name is required (use -p, --profile)" if profile_name.nil? || profile_name.blank?
|
10
|
+
raise TypeError, "parameter name is required (use -k, --key)" if parameter_name.nil? || parameter_name.blank?
|
11
|
+
self
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
metadata
CHANGED
@@ -1,20 +1,21 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aws_cli_config_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- brunze
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-05-
|
11
|
+
date: 2021-05-26 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |-
|
14
14
|
Parses profile settings and secrets from AWS CLI configuration files,
|
15
|
-
including
|
15
|
+
including temporary credentials cached by the CLI when using roles.
|
16
16
|
email:
|
17
|
-
executables:
|
17
|
+
executables:
|
18
|
+
- aws_cli_config_parser
|
18
19
|
extensions: []
|
19
20
|
extra_rdoc_files: []
|
20
21
|
files:
|
@@ -26,12 +27,16 @@ files:
|
|
26
27
|
- README.md
|
27
28
|
- Rakefile
|
28
29
|
- aws_cli_config_parser.gemspec
|
30
|
+
- bin/aws_cli_config_parser
|
29
31
|
- bin/console
|
30
32
|
- lib/aws_cli_config_parser.rb
|
31
33
|
- lib/aws_cli_config_parser/cached_credential.rb
|
34
|
+
- lib/aws_cli_config_parser/cli.rb
|
35
|
+
- lib/aws_cli_config_parser/cli/arguments.rb
|
32
36
|
- lib/aws_cli_config_parser/profile.rb
|
33
37
|
- lib/aws_cli_config_parser/profiles.rb
|
34
38
|
- lib/aws_cli_config_parser/refined/arrays.rb
|
39
|
+
- lib/aws_cli_config_parser/refined/strings.rb
|
35
40
|
- lib/aws_cli_config_parser/version.rb
|
36
41
|
homepage: https://github.com/brunze/aws_cli_config_parser
|
37
42
|
licenses:
|