Skip to content

Commit 43b92ca

Browse files
committed
_default uses impersonated_credentials method
1 parent fc6d67b commit 43b92ca

File tree

2 files changed

+3
-37
lines changed

2 files changed

+3
-37
lines changed

google/auth/_default.py

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -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(

google/auth/impersonated_credentials.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ def _source_credentials_from_impersonated_account_info(cls, info):
424424
425425
Raises:
426426
InvalidType: If the source_credentials are not a support impersonation type
427-
ValueError: If the info is not in the expected format.
427+
ValueError: If the source_credentials info is not in the expected format.
428428
"""
429429
_AUTHORIZED_USER_TYPE = "authorized_user"
430430
_SERVICE_ACCOUNT_TYPE = "service_account"

0 commit comments

Comments
 (0)