class AwsRunAs::Config

Manages the configuartion file, including loading and retrieving values.

Attributes

profile[R]

Public Class Methods

find_config_file() click to toggle source

Finds the configuration file (used if no file is specified). paths searched: ./aws_config, and ~/.aws/config.

# File lib/aws_runas/config.rb, line 23
def self.find_config_file
  local_config = File.expand_path('aws_config')
  user_config = File.expand_path('~/.aws/config')
  return local_config if File.exist?(local_config)
  user_config if File.exist?(user_config)
end
new(path:, profile:) click to toggle source
# File lib/aws_runas/config.rb, line 30
def initialize(path:, profile:)
  @path = path
  @path = self.class.find_config_file unless @path
  fail(Errno::ENOENT, "#{@path}") unless File.exist?(@path.to_s)
  @profile = profile
end

Public Instance Methods

load_config_value(key:) click to toggle source

Loads the config section for a specific profile.

# File lib/aws_runas/config.rb, line 38
def load_config_value(key:)
  section = @profile
  section = "profile #{@profile}" unless @profile == 'default'
  aws_config = IniFile.load(@path)
  unless aws_config.has_section?(section)
    fail(NameError, "Profile #{@profile} not found in #{@path}")
  end
  aws_config[section][key]
end
load_source_profile() click to toggle source

loads the soruce credentials profile based on the supplied profile.

# File lib/aws_runas/config.rb, line 55
def load_source_profile
  source_profile = load_config_value(key: 'source_profile')
  return source_profile if source_profile
  @profile
end
mfa_required?() click to toggle source

Checks to see if MFA is required for a specific profile.

# File lib/aws_runas/config.rb, line 49
def mfa_required?
  return true if load_config_value(key: 'mfa_serial') && !ENV.include?('AWS_SESSION_TOKEN')
  false
end