Skip to content

Commit 7cf84be

Browse files
linting
1 parent 586d47f commit 7cf84be

File tree

2 files changed

+12
-29
lines changed

2 files changed

+12
-29
lines changed

.github/workflows/pr-verify.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@ jobs:
4444
run: bundle install
4545

4646
- name: Run tests
47-
run: bundle exec rake test
47+
run: bundle exec rake test

lib/aws/google/cached_credentials.rb

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,45 +17,28 @@ def initialize(options = {})
1717

1818
@profile = options[:profile] || ENV['AWS_PROFILE'] || ENV['AWS_DEFAULT_PROFILE'] || 'default'
1919
@session_profile = @profile + '_session'
20-
@expiration = begin
21-
Aws.shared_config.expiration(profile: @session_profile)
22-
rescue StandardError
23-
nil
24-
end
25-
@credentials = begin
26-
Aws.shared_config.credentials(profile: @session_profile)
27-
rescue StandardError
28-
nil
29-
end
20+
@expiration = Aws.shared_config.expiration(profile: @session_profile) rescue nil
21+
@credentials = Aws.shared_config.credentials(profile: @session_profile) rescue nil
3022
refresh_if_near_expiration
3123
end
3224

3325
def refresh_if_near_expiration
34-
return unless near_expiration?(SYNC_EXPIRATION_LENGTH)
35-
36-
@mutex.synchronize do
37-
if near_expiration?(SYNC_EXPIRATION_LENGTH)
38-
refresh
39-
write_credentials
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
4032
end
4133
end
4234
end
4335

4436
# Write credentials and expiration to AWS credentials file.
4537
def write_credentials
46-
# Ensure the AWS CLI is available before attempting to write credentials.
38+
# AWS CLI is needed because writing AWS credentials is not supported by the AWS Ruby SDK.
4739
return unless system('which aws >/dev/null 2>&1')
48-
49-
# Manually map the credentials to the keys used by AWS CLI
50-
credentials_map = {
51-
'aws_access_key_id' => @credentials.access_key_id,
52-
'aws_secret_access_key' => @credentials.secret_access_key,
53-
'aws_session_token' => @credentials.session_token,
54-
'expiration' => @expiration
55-
}
56-
57-
# Use the AWS CLI to set the credentials in the session profile
58-
credentials_map.each do |key, value|
40+
Aws::SharedCredentials::KEY_MAP.transform_values(&@credentials.method(:send)).
41+
merge(expiration: @expiration).each do |key, value|
5942
system("aws configure set #{key} #{value} --profile #{@session_profile}")
6043
end
6144
end

0 commit comments

Comments
 (0)