@@ -216,29 +216,59 @@ def _create_composite_credentials(
216
216
)
217
217
218
218
if credentials_file :
219
- credentials , _ = google .auth .load_credentials_from_file (
220
- credentials_file ,
221
- scopes = scopes ,
222
- default_scopes = default_scopes
223
- )
219
+ try :
220
+ credentials , _ = google .auth .load_credentials_from_file (
221
+ credentials_file ,
222
+ scopes = scopes ,
223
+ default_scopes = default_scopes
224
+ )
225
+ # google-auth < x.x.x does not have `default_scopes`
226
+ # TODO: remove this try/except once google-auth >= x.x.x is required
227
+ except TypeError :
228
+ credentials , _ = google .auth .load_credentials_from_file (
229
+ credentials_file ,
230
+ scopes = scopes or default_scopes ,
231
+ )
224
232
elif credentials :
225
- credentials = google .auth .credentials .with_scopes_if_required (
226
- credentials ,
227
- scopes = scopes ,
228
- default_scopes = default_scopes
229
- )
233
+ try :
234
+ credentials = google .auth .credentials .with_scopes_if_required (
235
+ credentials ,
236
+ scopes = scopes ,
237
+ default_scopes = default_scopes
238
+ )
239
+ # google-auth < x.x.x does not have `default_scopes`
240
+ # TODO: remove this try/except once google-auth >= x.x.x is required
241
+ except TypeError :
242
+ credentials = google .auth .credentials .with_scopes_if_required (
243
+ credentials ,
244
+ scopes = scopes or default_scopes ,
245
+ )
246
+
230
247
else :
231
- credentials , _ = google .auth .default (scopes = scopes , default_scopes = default_scopes )
248
+ try :
249
+ credentials , _ = google .auth .default (scopes = scopes , default_scopes = default_scopes )
250
+ # google-auth < x.x.x does not have `default_scopes`
251
+ # TODO: remove this try/except once google-auth >= x.x.x is required
252
+ except TypeError :
253
+ credentials , _ = google .auth .default (scopes = scopes or default_scopes )
232
254
233
255
if quota_project_id and isinstance (credentials , google .auth .credentials .CredentialsWithQuotaProject ):
234
256
credentials = credentials .with_quota_project (quota_project_id )
235
257
236
258
request = google .auth .transport .requests .Request ()
237
259
238
260
# Create the metadata plugin for inserting the authorization header.
239
- metadata_plugin = google .auth .transport .grpc .AuthMetadataPlugin (
240
- credentials , request , default_host = default_host ,
241
- )
261
+
262
+ # google-auth < x.x.x does not have `default_host`
263
+ # TODO: remove this try/except once google-auth >= x.x.x is required
264
+ try :
265
+ metadata_plugin = google .auth .transport .grpc .AuthMetadataPlugin (
266
+ credentials , request , default_host = default_host ,
267
+ )
268
+ except :
269
+ metadata_plugin = google .auth .transport .grpc .AuthMetadataPlugin (
270
+ credentials , request
271
+ )
242
272
243
273
# Create a set of grpc.CallCredentials using the metadata plugin.
244
274
google_auth_credentials = grpc .metadata_call_credentials (metadata_plugin )
0 commit comments