Class: AwsLocalConfigParser
- Inherits:
-
Object
- Object
- AwsLocalConfigParser
- Defined in:
- lib/aws_local_config_parser.rb,
lib/aws_local_config_parser/errors.rb,
lib/aws_local_config_parser/version.rb
Defined Under Namespace
Classes: NoAwsConfig, NoMatchingProfile, NoMatchingSsoSession
Constant Summary collapse
- VERSION =
'1.0.0'
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#config_path ⇒ Object
Returns the value of attribute config_path.
Instance Method Summary collapse
- #all_profiles ⇒ Object
- #all_sso_sessions ⇒ Object
-
#initialize(config_path: "#{ENV["HOME"]}/.aws/config") ⇒ AwsLocalConfigParser
constructor
A new instance of AwsLocalConfigParser.
- #profile(profile_name) ⇒ Object
- #sso_session(sso_session) ⇒ Object
Constructor Details
#initialize(config_path: "#{ENV["HOME"]}/.aws/config") ⇒ AwsLocalConfigParser
Returns a new instance of AwsLocalConfigParser.
12 13 14 15 |
# File 'lib/aws_local_config_parser.rb', line 12 def initialize(config_path: "#{ENV["HOME"]}/.aws/config") @config_path = config_path @config = read_config_file end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
10 11 12 |
# File 'lib/aws_local_config_parser.rb', line 10 def config @config end |
#config_path ⇒ Object
Returns the value of attribute config_path.
10 11 12 |
# File 'lib/aws_local_config_parser.rb', line 10 def config_path @config_path end |
Instance Method Details
#all_profiles ⇒ Object
34 35 36 37 |
# File 'lib/aws_local_config_parser.rb', line 34 def all_profiles list_of_profiles = config_hash.keys.select { |entry| entry.start_with?('profile') }.sort list_of_profiles.map { |profile| profile.gsub('profile ', '') } end |
#all_sso_sessions ⇒ Object
29 30 31 32 |
# File 'lib/aws_local_config_parser.rb', line 29 def all_sso_sessions list_of_sso_sessions = config_hash.keys.select { |entry| entry.start_with?('sso-session') }.sort list_of_sso_sessions.map { |sso_session| sso_session.gsub('sso-session ', '') } end |
#profile(profile_name) ⇒ Object
17 18 19 20 21 |
# File 'lib/aws_local_config_parser.rb', line 17 def profile(profile_name) raise NoMatchingProfile.new(profile_name:, config_path:) unless config.has_section?("profile #{profile_name}") OpenStruct.new(config_hash["profile #{profile_name}"]) end |
#sso_session(sso_session) ⇒ Object
23 24 25 26 27 |
# File 'lib/aws_local_config_parser.rb', line 23 def sso_session(sso_session) raise NoMatchingSsoSession.new(sso_session:, config_path:) unless config.has_section?("sso-session #{sso_session}") OpenStruct.new(config_hash["sso-session #{sso_session}"]) end |