Class: AwsLocalConfigParser

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#configObject

Returns the value of attribute config.



10
11
12
# File 'lib/aws_local_config_parser.rb', line 10

def config
  @config
end

#config_pathObject

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_profilesObject



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_sessionsObject



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

Raises:



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