@@ -484,42 +484,8 @@ def _get_impersonated_service_account_credentials(filename, info, scopes):
484484 from google .auth import impersonated_credentials
485485
486486 try :
487- source_credentials_info = info .get ("source_credentials" )
488- source_credentials_type = source_credentials_info .get ("type" )
489- if source_credentials_type == _AUTHORIZED_USER_TYPE :
490- source_credentials , _ = _get_authorized_user_credentials (
491- filename , source_credentials_info
492- )
493- elif source_credentials_type == _SERVICE_ACCOUNT_TYPE :
494- source_credentials , _ = _get_service_account_credentials (
495- filename , source_credentials_info
496- )
497- elif source_credentials_type == _EXTERNAL_ACCOUNT_AUTHORIZED_USER_TYPE :
498- source_credentials , _ = _get_external_account_authorized_user_credentials (
499- filename , source_credentials_info
500- )
501- else :
502- raise exceptions .InvalidType (
503- "source credential of type {} is not supported." .format (
504- source_credentials_type
505- )
506- )
507- impersonation_url = info .get ("service_account_impersonation_url" )
508- start_index = impersonation_url .rfind ("/" )
509- end_index = impersonation_url .find (":generateAccessToken" )
510- if start_index == - 1 or end_index == - 1 or start_index > end_index :
511- raise exceptions .InvalidValue (
512- "Cannot extract target principal from {}" .format (impersonation_url )
513- )
514- target_principal = impersonation_url [start_index + 1 : end_index ]
515- delegates = info .get ("delegates" )
516- quota_project_id = info .get ("quota_project_id" )
517- credentials = impersonated_credentials .Credentials (
518- source_credentials ,
519- target_principal ,
520- scopes ,
521- delegates ,
522- quota_project_id = quota_project_id ,
487+ credentials = impersonated_credentials .Credentials .from_impersonated_account_info (
488+ info , scopes = scopes
523489 )
524490 except ValueError as caught_exc :
525491 msg = "Failed to load impersonated service account credentials from {}" .format (
0 commit comments