@@ -186,6 +186,7 @@ def __init__(
186186 self ._supplier_context = SupplierContext (
187187 self ._subject_token_type , self ._audience
188188 )
189+ self ._cred_file_path = None
189190
190191 if not self .is_workforce_pool and self ._workforce_pool_user_project :
191192 # Workload identity pools do not support workforce pool user projects.
@@ -321,11 +322,24 @@ def token_info_url(self):
321322
322323 return self ._token_info_url
323324
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+
324337 @_helpers .copy_docstring (credentials .Scoped )
325338 def with_scopes (self , scopes , default_scopes = None ):
326339 kwargs = self ._constructor_args ()
327340 kwargs .update (scopes = scopes , default_scopes = default_scopes )
328341 scoped = self .__class__ (** kwargs )
342+ scoped ._cred_file_path = self ._cred_file_path
329343 scoped ._metrics_options = self ._metrics_options
330344 return scoped
331345
@@ -442,30 +456,31 @@ def refresh(self, request):
442456
443457 self .expiry = now + lifetime
444458
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 ):
448460 kwargs = self ._constructor_args ()
449- kwargs .update (quota_project_id = quota_project_id )
450461 new_cred = self .__class__ (** kwargs )
462+ new_cred ._cred_file_path = self ._cred_file_path
451463 new_cred ._metrics_options = self ._metrics_options
452464 return new_cred
453465
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+
454473 @_helpers .copy_docstring (credentials .CredentialsWithTokenUri )
455474 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
461478
462479 @_helpers .copy_docstring (credentials .CredentialsWithUniverseDomain )
463480 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
469484
470485 def _should_initialize_impersonated_credentials (self ):
471486 return (
0 commit comments