@@ -20,7 +20,7 @@ module Aws
20
20
#
21
21
# ec2 = Aws::EC2::Client.new(credentials: role_credentials)
22
22
#
23
- # If you omit `:client` option, a new {STS::Client} object will be
23
+ # If you omit `:client` option, a new {Aws:: STS::Client} object will be
24
24
# constructed.
25
25
class Google
26
26
include ::Aws ::CredentialProvider
@@ -101,7 +101,8 @@ def refresh
101
101
rescue JWT ::DecodeError , JWT ::ExpiredSignature
102
102
# Refresh and retry once if token is expired or invalid.
103
103
client . refresh!
104
- ( tries -= 1 ) . zero? ? raise : retry
104
+ raise if ( tries -= 1 ) . zero?
105
+ retry
105
106
end
106
107
107
108
@client . assume_role_with_web_identity (
@@ -111,14 +112,16 @@ def refresh
111
112
)
112
113
)
113
114
rescue Signet ::AuthorizationError => e
114
- ( @google_client = google_oauth ) && retry || raise
115
+ retry if ( @google_client = google_oauth )
116
+ raise
115
117
rescue Aws ::STS ::Errors ::AccessDenied => e
116
118
retry if ( @google_client = google_oauth )
117
119
raise e , "\n Your Google ID does not have access to the requested AWS Role. Ask your administrator to provide access.
118
120
Role: #{ @assume_role_params [ :role_arn ] }
119
121
Email: #{ token_params [ 'email' ] }
120
122
Google ID: #{ token_params [ 'sub' ] } " , e . backtrace
121
123
end
124
+
122
125
c = assume_role . credentials
123
126
@credentials = Aws ::Credentials . new (
124
127
c . access_key_id ,
@@ -129,8 +132,7 @@ def refresh
129
132
write_credentials
130
133
end
131
134
132
- # Use `aws configure set` to write credentials and expiration to AWS credentials file.
133
- # AWS CLI is needed because writing AWS credentials is not supported by the AWS Ruby SDK.
135
+ # Write credentials and expiration to AWS credentials file.
134
136
def write_credentials
135
137
%w[
136
138
access_key_id
@@ -150,8 +152,6 @@ def get(key, opts = {})
150
152
profile = opts . delete ( :profile ) || @profile_name
151
153
if @parsed_config && ( prof_config = @parsed_config [ profile ] )
152
154
prof_config [ key ]
153
- else
154
- nil
155
155
end
156
156
end
157
157
end
0 commit comments