@@ -186,6 +186,7 @@ def __init__(
186
186
self ._supplier_context = SupplierContext (
187
187
self ._subject_token_type , self ._audience
188
188
)
189
+ self ._cred_file_path = None
189
190
190
191
if not self .is_workforce_pool and self ._workforce_pool_user_project :
191
192
# Workload identity pools do not support workforce pool user projects.
@@ -321,11 +322,24 @@ def token_info_url(self):
321
322
322
323
return self ._token_info_url
323
324
325
+ @_helpers .copy_docstring (credentials .Credentials )
326
+ def get_cred_info (self ):
327
+ if self ._cred_file_path :
328
+ cred_info_json = {
329
+ "credential_source" : self ._cred_file_path ,
330
+ "credential_type" : "external account credentials" ,
331
+ }
332
+ if self .service_account_email :
333
+ cred_info_json ["principal" ] = self .service_account_email
334
+ return cred_info_json
335
+ return None
336
+
324
337
@_helpers .copy_docstring (credentials .Scoped )
325
338
def with_scopes (self , scopes , default_scopes = None ):
326
339
kwargs = self ._constructor_args ()
327
340
kwargs .update (scopes = scopes , default_scopes = default_scopes )
328
341
scoped = self .__class__ (** kwargs )
342
+ scoped ._cred_file_path = self ._cred_file_path
329
343
scoped ._metrics_options = self ._metrics_options
330
344
return scoped
331
345
@@ -442,30 +456,31 @@ def refresh(self, request):
442
456
443
457
self .expiry = now + lifetime
444
458
445
- @_helpers .copy_docstring (credentials .CredentialsWithQuotaProject )
446
- def with_quota_project (self , quota_project_id ):
447
- # Return copy of instance with the provided quota project ID.
459
+ def _make_copy (self ):
448
460
kwargs = self ._constructor_args ()
449
- kwargs .update (quota_project_id = quota_project_id )
450
461
new_cred = self .__class__ (** kwargs )
462
+ new_cred ._cred_file_path = self ._cred_file_path
451
463
new_cred ._metrics_options = self ._metrics_options
452
464
return new_cred
453
465
466
+ @_helpers .copy_docstring (credentials .CredentialsWithQuotaProject )
467
+ def with_quota_project (self , quota_project_id ):
468
+ # Return copy of instance with the provided quota project ID.
469
+ cred = self ._make_copy ()
470
+ cred ._quota_project_id = quota_project_id
471
+ return cred
472
+
454
473
@_helpers .copy_docstring (credentials .CredentialsWithTokenUri )
455
474
def with_token_uri (self , token_uri ):
456
- kwargs = self ._constructor_args ()
457
- kwargs .update (token_url = token_uri )
458
- new_cred = self .__class__ (** kwargs )
459
- new_cred ._metrics_options = self ._metrics_options
460
- return new_cred
475
+ cred = self ._make_copy ()
476
+ cred ._token_url = token_uri
477
+ return cred
461
478
462
479
@_helpers .copy_docstring (credentials .CredentialsWithUniverseDomain )
463
480
def with_universe_domain (self , universe_domain ):
464
- kwargs = self ._constructor_args ()
465
- kwargs .update (universe_domain = universe_domain )
466
- new_cred = self .__class__ (** kwargs )
467
- new_cred ._metrics_options = self ._metrics_options
468
- return new_cred
481
+ cred = self ._make_copy ()
482
+ cred ._universe_domain = universe_domain
483
+ return cred
469
484
470
485
def _should_initialize_impersonated_credentials (self ):
471
486
return (
0 commit comments