File tree Expand file tree Collapse file tree 1 file changed +18
-9
lines changed Expand file tree Collapse file tree 1 file changed +18
-9
lines changed Original file line number Diff line number Diff line change @@ -23,22 +23,31 @@ def initialize(options = {})
23
23
end
24
24
25
25
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
32
32
end
33
33
end
34
34
end
35
35
36
36
# Write credentials and expiration to AWS credentials file.
37
37
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 .
39
39
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 |
42
51
system ( "aws configure set #{ key } #{ value } --profile #{ @session_profile } " )
43
52
end
44
53
end
You can’t perform that action at this time.
0 commit comments