Skip to content

Commit 5d43d4e

Browse files
Explicitly map credentials keys
1 parent 941ea8d commit 5d43d4e

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

lib/aws/google/cached_credentials.rb

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,31 @@ def initialize(options = {})
2323
end
2424

2525
def refresh_if_near_expiration
26-
if near_expiration?(SYNC_EXPIRATION_LENGTH)
27-
@mutex.synchronize do
28-
if near_expiration?(SYNC_EXPIRATION_LENGTH)
29-
refresh
30-
write_credentials
31-
end
26+
return unless near_expiration?(SYNC_EXPIRATION_LENGTH)
27+
28+
@mutex.synchronize do
29+
if near_expiration?(SYNC_EXPIRATION_LENGTH)
30+
refresh
31+
write_credentials
3232
end
3333
end
3434
end
3535

3636
# Write credentials and expiration to AWS credentials file.
3737
def write_credentials
38-
# AWS CLI is needed because writing AWS credentials is not supported by the AWS Ruby SDK.
38+
# Ensure the AWS CLI is available before attempting to write credentials.
3939
return unless system('which aws >/dev/null 2>&1')
40-
Aws::SharedCredentials::KEY_MAP.transform_values(&@credentials.method(:send)).
41-
merge(expiration: @expiration).each do |key, value|
40+
41+
# Manually map the credentials to the keys used by AWS CLI
42+
credentials_map = {
43+
'aws_access_key_id' => @credentials.access_key_id,
44+
'aws_secret_access_key' => @credentials.secret_access_key,
45+
'aws_session_token' => @credentials.session_token,
46+
'expiration' => @expiration
47+
}
48+
49+
# Use the AWS CLI to set the credentials in the session profile
50+
credentials_map.each do |key, value|
4251
system("aws configure set #{key} #{value} --profile #{@session_profile}")
4352
end
4453
end

0 commit comments

Comments
 (0)