aboutsummaryrefslogtreecommitdiff
path: root/google/auth/_default_async.py
diff options
context:
space:
mode:
Diffstat (limited to 'google/auth/_default_async.py')
-rw-r--r--google/auth/_default_async.py20
1 files changed, 12 insertions, 8 deletions
diff --git a/google/auth/_default_async.py b/google/auth/_default_async.py
index 82e6c43..3fa125b 100644
--- a/google/auth/_default_async.py
+++ b/google/auth/_default_async.py
@@ -73,11 +73,13 @@ def load_credentials_from_file(filename, scopes=None, quota_project_id=None):
try:
credentials = credentials.Credentials.from_authorized_user_info(
info, scopes=scopes
- ).with_quota_project(quota_project_id)
+ )
except ValueError as caught_exc:
msg = "Failed to load authorized user credentials from {}".format(filename)
new_exc = exceptions.DefaultCredentialsError(msg, caught_exc)
raise new_exc from caught_exc
+ if quota_project_id:
+ credentials = credentials.with_quota_project(quota_project_id)
if not credentials.quota_project_id:
_default._warn_about_problematic_credentials(credentials)
return credentials, None
@@ -104,7 +106,7 @@ def load_credentials_from_file(filename, scopes=None, quota_project_id=None):
)
-def _get_gcloud_sdk_credentials():
+def _get_gcloud_sdk_credentials(quota_project_id=None):
"""Gets the credentials and project ID from the Cloud SDK."""
from google.auth import _cloud_sdk
@@ -114,7 +116,9 @@ def _get_gcloud_sdk_credentials():
if not os.path.isfile(credentials_filename):
return None, None
- credentials, project_id = load_credentials_from_file(credentials_filename)
+ credentials, project_id = load_credentials_from_file(
+ credentials_filename, quota_project_id=quota_project_id
+ )
if not project_id:
project_id = _cloud_sdk.get_project_id()
@@ -122,7 +126,7 @@ def _get_gcloud_sdk_credentials():
return credentials, project_id
-def _get_explicit_environ_credentials():
+def _get_explicit_environ_credentials(quota_project_id=None):
"""Gets credentials from the GOOGLE_APPLICATION_CREDENTIALS environment
variable."""
from google.auth import _cloud_sdk
@@ -134,11 +138,11 @@ def _get_explicit_environ_credentials():
# Cloud sdk flow calls gcloud to fetch project id, so if the explicit
# file path is cloud sdk credentials path, then we should fall back
# to cloud sdk flow, otherwise project id cannot be obtained.
- return _get_gcloud_sdk_credentials()
+ return _get_gcloud_sdk_credentials(quota_project_id=quota_project_id)
if explicit_file is not None:
credentials, project_id = load_credentials_from_file(
- os.environ[environment_vars.CREDENTIALS]
+ os.environ[environment_vars.CREDENTIALS], quota_project_id=quota_project_id
)
return credentials, project_id
@@ -250,8 +254,8 @@ def default_async(scopes=None, request=None, quota_project_id=None):
)
checkers = (
- _get_explicit_environ_credentials,
- _get_gcloud_sdk_credentials,
+ lambda: _get_explicit_environ_credentials(quota_project_id=quota_project_id),
+ lambda: _get_gcloud_sdk_credentials(quota_project_id=quota_project_id),
_get_gae_credentials,
lambda: _get_gce_credentials(request),
)