Class: AwsAssumeRole::Store::SharedConfigWithKeyring
Instance Attribute Summary collapse
#config_path, #credentials_path, #profile_name
Instance Method Summary
collapse
Methods included from Logging
included
#assume_role_credentials_from_config, #config_enabled?, #loadable?, #region
Constructor Details
Returns a new instance of SharedConfigWithKeyring.
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/aws_assume_role/store/shared_config_with_keyring.rb', line 26
def initialize(options = {})
@profile_name = determine_profile(options)
@config_enabled = options[:config_enabled]
@credentials_path = options[:credentials_path] ||
determine_credentials_path
@parsed_credentials = {}
load_credentials_file if loadable?(@credentials_path)
return unless @config_enabled
@config_path = options[:config_path] || determine_config_path
load_config_file if loadable?(@config_path)
end
|
Instance Attribute Details
#parsed_config ⇒ Object
Returns the value of attribute parsed_config.
13
14
15
|
# File 'lib/aws_assume_role/store/shared_config_with_keyring.rb', line 13
def parsed_config
@parsed_config
end
|
Instance Method Details
#credentials(opts = {}) ⇒ Object
58
59
60
61
62
63
|
# File 'lib/aws_assume_role/store/shared_config_with_keyring.rb', line 58
def credentials(opts = {})
logger.debug "SharedConfigWithKeyring asked for credentials with opts #{opts}"
p = opts[:profile] || @profile_name
validate_profile_exists(p) if credentials_present?
credentials_from_keyring(p, opts) || credentials_from_shared(p, opts) || credentials_from_config(p, opts)
end
|
#delete_profile(profile_name) ⇒ Object
86
87
88
89
90
91
92
93
94
|
# File 'lib/aws_assume_role/store/shared_config_with_keyring.rb', line 86
def delete_profile(profile_name)
Keyring.delete_credentials(profile_name)
semaphore.synchronize do
raise KeyError if configuration["profile #{profile_name}"].blank?
configuration.delete_section("profile #{profile_name}")
save_configuration
end
end
|
#fresh(options = {}) ⇒ Object
This method is part of a private API.
You should avoid using this method if possible, as it may be removed or be changed in the future.
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/aws_assume_role/store/shared_config_with_keyring.rb', line 39
def fresh(options = {})
@configuration = nil
@semaphore = nil
@assume_role_shared_config = nil
@profile_name = nil
@credentials_path = nil
@config_path = nil
@parsed_credentials = {}
@parsed_config = nil
@config_enabled = options[:config_enabled] ? true : false
@profile_name = determine_profile(options)
@credentials_path = options[:credentials_path] ||
determine_credentials_path
load_credentials_file if loadable?(@credentials_path)
return unless @config_enabled
@config_path = options[:config_path] || determine_config_path
load_config_file if loadable?(@config_path)
end
|
#migrate_profile(profile_name) ⇒ Object
96
97
98
99
|
# File 'lib/aws_assume_role/store/shared_config_with_keyring.rb', line 96
def migrate_profile(profile_name)
validate_profile_exists(profile_name)
save_profile(profile_name, configuration["profile #{profile_name}"])
end
|
#profile_hash(profile_name) ⇒ Object
109
110
111
|
# File 'lib/aws_assume_role/store/shared_config_with_keyring.rb', line 109
def profile_hash(profile_name)
{} || @parsed_config[profile_key(profile_name)]
end
|
#profile_region(profile_name) ⇒ Object
101
102
103
|
# File 'lib/aws_assume_role/store/shared_config_with_keyring.rb', line 101
def profile_region(profile_name)
resolve_profile_parameter(profile_name, "region")
end
|
#profile_role(profile_name) ⇒ Object
105
106
107
|
# File 'lib/aws_assume_role/store/shared_config_with_keyring.rb', line 105
def profile_role(profile_name)
resolve_profile_parameter(profile_name, "role_arn")
end
|
#profiles ⇒ Object
82
83
84
|
# File 'lib/aws_assume_role/store/shared_config_with_keyring.rb', line 82
def profiles
configuration.sections.map { |c| c.gsub("profile ", "") }
end
|
#save_profile(profile_name, hash) ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/aws_assume_role/store/shared_config_with_keyring.rb', line 65
def save_profile(profile_name, hash)
ckey = "profile #{profile_name}"
merged_config = configuration[ckey].deep_symbolize_keys.merge hash.to_h
merged_config[:mfa_serial] = merged_config[:serial_number] if merged_config[:serial_number]
credentials = Aws::Credentials.new(merged_config.delete(:aws_access_key_id),
merged_config.delete(:aws_secret_access_key))
semaphore.synchronize do
Keyring.save_credentials profile_name, credentials if credentials.set?
merged_config = merged_config.slice :region, :role_arn, :mfa_serial, :source_profile,
:role_session_name, :external_id, :duration_seconds,
:yubikey_oath_name
configuration.delete_section ckey
configuration[ckey] = merged_config.compact
save_configuration
end
end
|