aws_local_config_parser 0.0.1 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.txt +21 -0
- data/README.md +63 -0
- data/bin/console +13 -0
- data/bin/demo +62 -0
- data/bin/setup +5 -0
- data/lib/aws_local_config_parser/errors.rb +44 -0
- data/lib/aws_local_config_parser/version.rb +5 -0
- data/lib/aws_local_config_parser.rb +50 -0
- metadata +49 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9cca023a99a6a952e6f0adef530645e5c6b94287346d25f7edad8a13474f3ba6
|
4
|
+
data.tar.gz: df35c97974f876463d77fcf151e347b354249d6ff594eb915b035a47ed71c1e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 38a1a0634c67ea90dd15520901668b3fecb65548793733462bcdb77d9700b674250835b603c3e66e9daa1f9d06576cefafe906a70df666f5d9d1f907560dfea0
|
7
|
+
data.tar.gz: e3ccbc778c3122eda9acd3afdea088121d6810856b9666a00c47f72a2b9a96d158178fede5111ea89cc30e839732a924801b937989b9b2a31cf0b7248d4087ac
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2024 FreeAgent
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
# AwsLocalConfigParser
|
2
|
+
|
3
|
+
Parse your local `"$HOME"/.aws/config` to use it within a Ruby script.
|
4
|
+
|
5
|
+
## Up and Running
|
6
|
+
1. Checkout this repo: `gh repo clone fac/aws_local_config_parser`
|
7
|
+
1. Run: `bin/setup`
|
8
|
+
1. Run: `bin/demo`
|
9
|
+
|
10
|
+
## Usage
|
11
|
+
See [`demo`](./bin/demo) for examples on how to use the gem.
|
12
|
+
|
13
|
+
Supports parsing and returning:
|
14
|
+
- Profiles with SSO
|
15
|
+
- Profiles with Access Key + Secret
|
16
|
+
- SSO Sessions
|
17
|
+
|
18
|
+
``` ruby
|
19
|
+
require 'aws_local_config_parser'
|
20
|
+
|
21
|
+
config = AwsLocalConfigParser.new
|
22
|
+
|
23
|
+
# Profile with SSO
|
24
|
+
my_sso_profile = config.profile('my-sso-profile-name')
|
25
|
+
my_sso_profile.sso_session
|
26
|
+
my_sso_profile.sso_account_id
|
27
|
+
my_sso_profile.sso_role_name
|
28
|
+
my_sso_profile.region
|
29
|
+
|
30
|
+
## Profile with Access Key + Secret
|
31
|
+
non_sso_profile = config.profile('my-non-sso-profile-name')
|
32
|
+
non_sso_profile.aws_access_key_id
|
33
|
+
non_sso_profile.aws_secret_access_key
|
34
|
+
non_sso_profile.region
|
35
|
+
|
36
|
+
## SSO Session
|
37
|
+
my_sso_session = config.sso_session('sso-session')
|
38
|
+
my_sso_session.sso_start_url
|
39
|
+
my_sso_session.sso_registration_scopes
|
40
|
+
my_sso_session.sso_region
|
41
|
+
|
42
|
+
## Listing all names
|
43
|
+
config.all_profiles
|
44
|
+
config.all_sso_sessions
|
45
|
+
```
|
46
|
+
|
47
|
+
## Making a commit
|
48
|
+
[Lefthook](https://github.com/evilmartians/lefthook/) has [been configured](./lefthook.yml) with pre-commit checks to:
|
49
|
+
- run `rubocop` for any `ruby` files
|
50
|
+
- run `actionlint` for any GitHub workflow files
|
51
|
+
|
52
|
+
If for some reason it's necessary, it's possible to temporarily skip `lefthook` with: `LEFTHOOK=0 git commit`.
|
53
|
+
|
54
|
+
## Create a new release
|
55
|
+
Following [Sematic Versioning](https://semver.org/), bump the version:
|
56
|
+
1. `gem bump --version "<sem_ver_bump>"` and merge the changes to `main`
|
57
|
+
1. The [Release and Build Gem](https://github.com/fac/aws_local_config_parser/actions/workflows/release_gem.yml) wokflow will trigger a new version build
|
58
|
+
1. Manually create a new [release](https://github.com/fac/aws_local_config_parser/releases):
|
59
|
+
1. Click on `Draft a new release`
|
60
|
+
1. In the `Choose a tag` dropdown, selecting the new version
|
61
|
+
1. Click `Generate release notes` and review the notes
|
62
|
+
1. Ensure `Set as the latest release` is checked
|
63
|
+
1. Click `Publish release`
|
data/bin/console
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'aws_local_config_parser'
|
6
|
+
require 'debug'
|
7
|
+
require 'pry'
|
8
|
+
|
9
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
10
|
+
# with your gem easier. You can also use a different console, if you like.
|
11
|
+
|
12
|
+
require 'irb'
|
13
|
+
IRB.start(__FILE__)
|
data/bin/demo
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# frozen_string_literal: true
|
4
|
+
|
5
|
+
require_relative '../lib/aws_local_config_parser'
|
6
|
+
|
7
|
+
require 'debug'
|
8
|
+
require 'pastel'
|
9
|
+
|
10
|
+
config = AwsLocalConfigParser.new
|
11
|
+
pastel = Pastel.new
|
12
|
+
|
13
|
+
puts pastel.bold.blue('Profile:')
|
14
|
+
|
15
|
+
puts pastel.bold.magenta('fa-ci-stage') + pastel.bold.green(' [SSO Profile]')
|
16
|
+
stage = config.profile('fa-ci-stage')
|
17
|
+
puts "\tsso_session: #{stage.sso_session}"
|
18
|
+
puts "\tsso_account_id: #{stage.sso_account_id}"
|
19
|
+
puts "\tsso_role_name: #{stage.sso_role_name}"
|
20
|
+
puts "\tregion: #{stage.region}"
|
21
|
+
|
22
|
+
begin
|
23
|
+
puts "\n"
|
24
|
+
puts pastel.bold.magenta('component-finder-uploader') + pastel.bold.green(' [Access Key+Secret Profile]')
|
25
|
+
non_sso_profile = config.profile('component-finder-uploader')
|
26
|
+
puts "\taws_access_key_id: #{non_sso_profile.aws_access_key_id}"
|
27
|
+
puts "\taws_secret_access_key: #{non_sso_profile.aws_secret_access_key}"
|
28
|
+
puts "\tregion: #{non_sso_profile.region}"
|
29
|
+
rescue AwsLocalConfigParser::NoMatchingProfile => e
|
30
|
+
puts pastel.bold.red 'No local Access Key+Secret Profile to demo'
|
31
|
+
puts pastel.bold.red e.message.to_s
|
32
|
+
end
|
33
|
+
|
34
|
+
puts "\n"
|
35
|
+
puts pastel.bold.blue('SSO Session:')
|
36
|
+
puts pastel.bold.magenta('fa-sso')
|
37
|
+
sso_session = config.sso_session('fa-sso')
|
38
|
+
puts "\tsso_start_url: #{sso_session.sso_start_url}"
|
39
|
+
puts "\tsso_registration_scopes: #{sso_session.sso_registration_scopes}"
|
40
|
+
puts "\tsso_region: #{sso_session.sso_region}"
|
41
|
+
|
42
|
+
puts "\n"
|
43
|
+
puts pastel.bold.blue('Custom Errors:')
|
44
|
+
begin
|
45
|
+
puts config.profile('non-existant-profile')
|
46
|
+
rescue AwsLocalConfigParser::NoMatchingProfile => e
|
47
|
+
puts pastel.bold.red "🚨 #{e.message}"
|
48
|
+
end
|
49
|
+
|
50
|
+
begin
|
51
|
+
puts config.sso_session('non-existant-sso-session')
|
52
|
+
rescue AwsLocalConfigParser::NoMatchingSsoSession => e
|
53
|
+
puts pastel.bold.red "🚨 #{e.message}"
|
54
|
+
end
|
55
|
+
|
56
|
+
puts "\n"
|
57
|
+
puts pastel.bold.blue('SSO Sessions:')
|
58
|
+
puts config.all_sso_sessions
|
59
|
+
|
60
|
+
puts "\n"
|
61
|
+
puts pastel.bold.blue('Profiles:')
|
62
|
+
puts config.all_profiles
|
data/bin/setup
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class AwsLocalConfigParser
|
4
|
+
class NoAwsConfig < StandardError
|
5
|
+
attr_reader :config_path
|
6
|
+
|
7
|
+
def initialize(config_path:)
|
8
|
+
@config_path = config_path
|
9
|
+
super(msg: message)
|
10
|
+
end
|
11
|
+
|
12
|
+
def message
|
13
|
+
"No AWS config file at: '#{config_path}'."
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class NoMatchingProfile < StandardError
|
18
|
+
attr_reader :profile_name, :config_path
|
19
|
+
|
20
|
+
def initialize(profile_name:, config_path:)
|
21
|
+
@profile_name = profile_name
|
22
|
+
@config_path = config_path
|
23
|
+
super(msg: message)
|
24
|
+
end
|
25
|
+
|
26
|
+
def message
|
27
|
+
"No matching profile, '#{profile_name}', in '#{config_path}'."
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class NoMatchingSsoSession < StandardError
|
32
|
+
attr_reader :sso_session, :config_path
|
33
|
+
|
34
|
+
def initialize(sso_session:, config_path:)
|
35
|
+
@sso_session = sso_session
|
36
|
+
@config_path = config_path
|
37
|
+
super(msg: message)
|
38
|
+
end
|
39
|
+
|
40
|
+
def message
|
41
|
+
"No matching sso-session, '#{sso_session}', in '#{config_path}'."
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'aws_local_config_parser/version'
|
4
|
+
require_relative 'aws_local_config_parser/errors'
|
5
|
+
|
6
|
+
require 'inifile'
|
7
|
+
require 'ostruct'
|
8
|
+
|
9
|
+
class AwsLocalConfigParser
|
10
|
+
attr_accessor :config, :config_path
|
11
|
+
|
12
|
+
def initialize(config_path: "#{ENV["HOME"]}/.aws/config")
|
13
|
+
@config_path = config_path
|
14
|
+
@config = read_config_file
|
15
|
+
end
|
16
|
+
|
17
|
+
def profile(profile_name)
|
18
|
+
raise NoMatchingProfile.new(profile_name:, config_path:) unless config.has_section?("profile #{profile_name}")
|
19
|
+
|
20
|
+
OpenStruct.new(config_hash["profile #{profile_name}"])
|
21
|
+
end
|
22
|
+
|
23
|
+
def sso_session(sso_session)
|
24
|
+
raise NoMatchingSsoSession.new(sso_session:, config_path:) unless config.has_section?("sso-session #{sso_session}")
|
25
|
+
|
26
|
+
OpenStruct.new(config_hash["sso-session #{sso_session}"])
|
27
|
+
end
|
28
|
+
|
29
|
+
def all_sso_sessions
|
30
|
+
list_of_sso_sessions = config_hash.keys.select { |entry| entry.start_with?('sso-session') }.sort
|
31
|
+
list_of_sso_sessions.map { |sso_session| sso_session.gsub('sso-session ', '') }
|
32
|
+
end
|
33
|
+
|
34
|
+
def all_profiles
|
35
|
+
list_of_profiles = config_hash.keys.select { |entry| entry.start_with?('profile') }.sort
|
36
|
+
list_of_profiles.map { |profile| profile.gsub('profile ', '') }
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def read_config_file
|
42
|
+
raise AwsLocalConfigParser::NoAwsConfig.new(config_path:) unless File.exist?(config_path)
|
43
|
+
|
44
|
+
IniFile.load(config_path)
|
45
|
+
end
|
46
|
+
|
47
|
+
def config_hash
|
48
|
+
config.to_h
|
49
|
+
end
|
50
|
+
end
|
metadata
CHANGED
@@ -1,28 +1,65 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aws_local_config_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- FreeAgent
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
13
|
-
|
10
|
+
date: 2025-02-06 00:00:00.000000000 Z
|
11
|
+
dependencies:
|
12
|
+
- !ruby/object:Gem::Dependency
|
13
|
+
name: inifile
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - "~>"
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: '3'
|
19
|
+
type: :runtime
|
20
|
+
prerelease: false
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
requirements:
|
23
|
+
- - "~>"
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: '3'
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: ostruct
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
description: Parse your local '"$HOME"/.aws/config' file.
|
14
41
|
email:
|
15
42
|
- opensource@freeagent.com
|
16
43
|
executables: []
|
17
44
|
extensions: []
|
18
45
|
extra_rdoc_files: []
|
19
|
-
files:
|
20
|
-
|
46
|
+
files:
|
47
|
+
- LICENSE.txt
|
48
|
+
- README.md
|
49
|
+
- bin/console
|
50
|
+
- bin/demo
|
51
|
+
- bin/setup
|
52
|
+
- lib/aws_local_config_parser.rb
|
53
|
+
- lib/aws_local_config_parser/errors.rb
|
54
|
+
- lib/aws_local_config_parser/version.rb
|
55
|
+
homepage: https://github.com/fac/aws_local_config_parser
|
21
56
|
licenses:
|
22
57
|
- MIT
|
23
58
|
metadata:
|
24
|
-
|
25
|
-
|
59
|
+
allowed_push_host: https://rubygems.org
|
60
|
+
homepage_uri: https://github.com/fac/aws_local_config_parser
|
61
|
+
source_code_uri: https://github.com/fac/aws_local_config_parser
|
62
|
+
changelog_uri: https://github.com/fac/aws_local_config_parser/releases
|
26
63
|
rdoc_options: []
|
27
64
|
require_paths:
|
28
65
|
- lib
|
@@ -30,15 +67,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
30
67
|
requirements:
|
31
68
|
- - ">="
|
32
69
|
- !ruby/object:Gem::Version
|
33
|
-
version: 3.
|
70
|
+
version: '3.1'
|
34
71
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
72
|
requirements:
|
36
73
|
- - ">="
|
37
74
|
- !ruby/object:Gem::Version
|
38
75
|
version: '0'
|
39
76
|
requirements: []
|
40
|
-
rubygems_version: 3.
|
41
|
-
signing_key:
|
77
|
+
rubygems_version: 3.6.2
|
42
78
|
specification_version: 4
|
43
|
-
summary:
|
79
|
+
summary: A simple gem to parse your local AWS config file.
|
44
80
|
test_files: []
|