aws_local_config_parser 0.0.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/LICENSE.txt +21 -0
- data/README.md +62 -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 +38 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4bd547cb8ccef948f138f99e94a7c4925dc6172484eb42d3dcec8bc95c5f319c
|
4
|
+
data.tar.gz: 6644f5dcd97e7443768b67a6d6fc09a0746d9429d5f2dc9f58b675eddbf82645
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eedb4639699391b7fc79474a3855ece38b8384c17a5e8001160c36e043b021e2e00e705d76f85a9d920a2634ba8077d3e9642ddbf3ba614f92f31c81101ea7ee
|
7
|
+
data.tar.gz: 9c93ba8b249b697b15f617cf5aac384100c57cb47ce0c1096d00a3b122931c21d5cf636526af18e310193567262769f42c2760ee17c3224955f3f458cf04c899
|
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,62 @@
|
|
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
|
+
|
51
|
+
If for some reason it's necessary, it's possible to temporarily skip `lefthook` with: `LEFTHOOK=0 git commit`.
|
52
|
+
|
53
|
+
## Create a new release
|
54
|
+
Following [Sematic Versioning](https://semver.org/), bump the version:
|
55
|
+
1. `gem bump --version "<sem_ver_bump>"` and merge the changes to `main`
|
56
|
+
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
|
57
|
+
1. Manually create a new [release](https://github.com/fac/aws_local_config_parser/releases):
|
58
|
+
1. Click on `Draft a new release`
|
59
|
+
1. In the `Choose a tag` dropdown, selecting the new version
|
60
|
+
1. Click `Generate release notes` and review the notes
|
61
|
+
1. Ensure `Set as the latest release` is checked
|
62
|
+
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,53 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aws_local_config_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- FreeAgent
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
12
|
-
dependencies:
|
13
|
-
|
11
|
+
date: 2024-07-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: inifile
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3'
|
27
|
+
description: Parse your local '"$HOME"/.aws/config' file.
|
14
28
|
email:
|
15
29
|
- opensource@freeagent.com
|
16
30
|
executables: []
|
17
31
|
extensions: []
|
18
32
|
extra_rdoc_files: []
|
19
|
-
files:
|
20
|
-
|
33
|
+
files:
|
34
|
+
- LICENSE.txt
|
35
|
+
- README.md
|
36
|
+
- bin/console
|
37
|
+
- bin/demo
|
38
|
+
- bin/setup
|
39
|
+
- lib/aws_local_config_parser.rb
|
40
|
+
- lib/aws_local_config_parser/errors.rb
|
41
|
+
- lib/aws_local_config_parser/version.rb
|
42
|
+
homepage: https://github.com/fac/aws_local_config_parser
|
21
43
|
licenses:
|
22
44
|
- MIT
|
23
45
|
metadata:
|
24
|
-
|
25
|
-
|
46
|
+
allowed_push_host: https://rubygems.org
|
47
|
+
homepage_uri: https://github.com/fac/aws_local_config_parser
|
48
|
+
source_code_uri: https://github.com/fac/aws_local_config_parser
|
49
|
+
changelog_uri: https://github.com/fac/aws_local_config_parser/releases
|
50
|
+
post_install_message:
|
26
51
|
rdoc_options: []
|
27
52
|
require_paths:
|
28
53
|
- lib
|
@@ -30,15 +55,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
30
55
|
requirements:
|
31
56
|
- - ">="
|
32
57
|
- !ruby/object:Gem::Version
|
33
|
-
version: 3.
|
58
|
+
version: '3.1'
|
34
59
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
60
|
requirements:
|
36
61
|
- - ">="
|
37
62
|
- !ruby/object:Gem::Version
|
38
63
|
version: '0'
|
39
64
|
requirements: []
|
40
|
-
rubygems_version: 3.5.
|
41
|
-
signing_key:
|
65
|
+
rubygems_version: 3.5.11
|
66
|
+
signing_key:
|
42
67
|
specification_version: 4
|
43
|
-
summary:
|
68
|
+
summary: A simple gem to parse your local AWS config file.
|
44
69
|
test_files: []
|