@@ -151,6 +151,7 @@ def __init__(
151151 self ._trust_boundary = trust_boundary
152152 self ._universe_domain = universe_domain or credentials .DEFAULT_UNIVERSE_DOMAIN
153153 self ._account = account or ""
154+ self ._cred_file_path = None
154155
155156 def __getstate__ (self ):
156157 """A __getstate__ method must exist for the __setstate__ to be called
@@ -189,6 +190,7 @@ def __setstate__(self, d):
189190 self ._universe_domain = (
190191 d .get ("_universe_domain" ) or credentials .DEFAULT_UNIVERSE_DOMAIN
191192 )
193+ self ._cred_file_path = d .get ("_cred_file_path" )
192194 # The refresh_handler setter should be used to repopulate this.
193195 self ._refresh_handler = None
194196 self ._refresh_worker = None
@@ -278,10 +280,8 @@ def account(self):
278280 """str: The user account associated with the credential. If the account is unknown an empty string is returned."""
279281 return self ._account
280282
281- @_helpers .copy_docstring (credentials .CredentialsWithQuotaProject )
282- def with_quota_project (self , quota_project_id ):
283-
284- return self .__class__ (
283+ def _make_copy (self ):
284+ cred = self .__class__ (
285285 self .token ,
286286 refresh_token = self .refresh_token ,
287287 id_token = self .id_token ,
@@ -291,34 +291,36 @@ def with_quota_project(self, quota_project_id):
291291 scopes = self .scopes ,
292292 default_scopes = self .default_scopes ,
293293 granted_scopes = self .granted_scopes ,
294- quota_project_id = quota_project_id ,
294+ quota_project_id = self . quota_project_id ,
295295 rapt_token = self .rapt_token ,
296296 enable_reauth_refresh = self ._enable_reauth_refresh ,
297297 trust_boundary = self ._trust_boundary ,
298298 universe_domain = self ._universe_domain ,
299299 account = self ._account ,
300300 )
301+ cred ._cred_file_path = self ._cred_file_path
302+ return cred
303+
304+ @_helpers .copy_docstring (credentials .Credentials )
305+ def get_cred_info (self ):
306+ if self ._cred_file_path :
307+ return {
308+ "credential_source" : self ._cred_file_path ,
309+ "credential_type" : "user credentials" ,
310+ }
311+ return None
312+
313+ @_helpers .copy_docstring (credentials .CredentialsWithQuotaProject )
314+ def with_quota_project (self , quota_project_id ):
315+ cred = self ._make_copy ()
316+ cred ._quota_project_id = quota_project_id
317+ return cred
301318
302319 @_helpers .copy_docstring (credentials .CredentialsWithTokenUri )
303320 def with_token_uri (self , token_uri ):
304-
305- return self .__class__ (
306- self .token ,
307- refresh_token = self .refresh_token ,
308- id_token = self .id_token ,
309- token_uri = token_uri ,
310- client_id = self .client_id ,
311- client_secret = self .client_secret ,
312- scopes = self .scopes ,
313- default_scopes = self .default_scopes ,
314- granted_scopes = self .granted_scopes ,
315- quota_project_id = self .quota_project_id ,
316- rapt_token = self .rapt_token ,
317- enable_reauth_refresh = self ._enable_reauth_refresh ,
318- trust_boundary = self ._trust_boundary ,
319- universe_domain = self ._universe_domain ,
320- account = self ._account ,
321- )
321+ cred = self ._make_copy ()
322+ cred ._token_uri = token_uri
323+ return cred
322324
323325 def with_account (self , account ):
324326 """Returns a copy of these credentials with a modified account.
@@ -329,45 +331,15 @@ def with_account(self, account):
329331 Returns:
330332 google.oauth2.credentials.Credentials: A new credentials instance.
331333 """
332-
333- return self .__class__ (
334- self .token ,
335- refresh_token = self .refresh_token ,
336- id_token = self .id_token ,
337- token_uri = self ._token_uri ,
338- client_id = self .client_id ,
339- client_secret = self .client_secret ,
340- scopes = self .scopes ,
341- default_scopes = self .default_scopes ,
342- granted_scopes = self .granted_scopes ,
343- quota_project_id = self .quota_project_id ,
344- rapt_token = self .rapt_token ,
345- enable_reauth_refresh = self ._enable_reauth_refresh ,
346- trust_boundary = self ._trust_boundary ,
347- universe_domain = self ._universe_domain ,
348- account = account ,
349- )
334+ cred = self ._make_copy ()
335+ cred ._account = account
336+ return cred
350337
351338 @_helpers .copy_docstring (credentials .CredentialsWithUniverseDomain )
352339 def with_universe_domain (self , universe_domain ):
353-
354- return self .__class__ (
355- self .token ,
356- refresh_token = self .refresh_token ,
357- id_token = self .id_token ,
358- token_uri = self ._token_uri ,
359- client_id = self .client_id ,
360- client_secret = self .client_secret ,
361- scopes = self .scopes ,
362- default_scopes = self .default_scopes ,
363- granted_scopes = self .granted_scopes ,
364- quota_project_id = self .quota_project_id ,
365- rapt_token = self .rapt_token ,
366- enable_reauth_refresh = self ._enable_reauth_refresh ,
367- trust_boundary = self ._trust_boundary ,
368- universe_domain = universe_domain ,
369- account = self ._account ,
370- )
340+ cred = self ._make_copy ()
341+ cred ._universe_domain = universe_domain
342+ return cred
371343
372344 def _metric_header_for_usage (self ):
373345 return metrics .CRED_TYPE_USER
0 commit comments