Module: AwsAssumeRole::Store::Keyring
Constant Summary
collapse
- KEYRING_KEY =
"AwsAssumeRole".freeze
Config, DefaultProvider, VERSION
Class Method Summary
collapse
Methods included from Logging
included
shared_config
Class Method Details
.delete_credentials(id, backend: nil) ⇒ Object
46
47
48
49
50
|
# File 'lib/aws_assume_role/store/keyring.rb', line 46
def delete_credentials(id, backend: nil)
semaphore.synchronize do
keyring(backend).delete_password(KEYRING_KEY, id)
end
end
|
.fetch(id, backend: nil) ⇒ Object
38
39
40
41
42
43
44
|
# File 'lib/aws_assume_role/store/keyring.rb', line 38
def fetch(id, backend: nil)
logger.debug "Fetching #{id} from keyring"
fetched = keyring(backend).get_password(KEYRING_KEY, id)
return nil if fetched == "null" || fetched.nil?
raise Aws::Errors::NoSuchProfileError unless fetched
JSON.parse(fetched, symbolize_names: true)
end
|
.keyring(backend = AwsAssumeRole::Config.backend) ⇒ Object
29
30
31
32
33
34
35
36
|
# File 'lib/aws_assume_role/store/keyring.rb', line 29
def keyring(backend = AwsAssumeRole::Config.backend)
keyrings[backend] ||= begin
try_backend_plugin
klass = backend ? "Keyring::Backend::#{backend}".constantize : nil
logger.debug "Initializing #{klass} backend"
::Keyring.new(klass)
end
end
|
.keyrings ⇒ Object
19
20
21
|
# File 'lib/aws_assume_role/store/keyring.rb', line 19
def keyrings
@keyrings ||= {}
end
|
.save_credentials(id, credentials, expiration: nil, backend: nil) ⇒ Object
52
53
54
55
56
57
58
|
# File 'lib/aws_assume_role/store/keyring.rb', line 52
def save_credentials(id, credentials, expiration: nil, backend: nil)
credentials_to_persist = Serialization.credentials_to_hash(credentials)
credentials_to_persist[:expiration] = expiration if expiration
semaphore.synchronize do
keyring(backend).set_password(KEYRING_KEY, id, credentials_to_persist.to_json)
end
end
|
.semaphore ⇒ Object
15
16
17
|
# File 'lib/aws_assume_role/store/keyring.rb', line 15
def semaphore
@semaphore ||= Mutex.new
end
|
.try_backend_plugin ⇒ Object
23
24
25
26
27
|
# File 'lib/aws_assume_role/store/keyring.rb', line 23
def try_backend_plugin
return if AwsAssumeRole::Config.backend_plugin.blank?
logger.info "Attempting to load #{AwsAssumeRole::Config.backend_plugin} plugin"
require AwsAssumeRole::Config.backend_plugin
end
|