Skip to content
This repository was archived by the owner on Mar 6, 2026. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions google/auth/_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,13 @@ def _get_gcloud_sdk_credentials():
"""Gets the credentials and project ID from the Cloud SDK."""
from google.auth import _cloud_sdk

_LOGGER.debug("Checking Cloud SDK credentials as part of auth process...")

# Check if application default credentials exist.
credentials_filename = _cloud_sdk.get_application_default_credentials_path()

if not os.path.isfile(credentials_filename):
_LOGGER.debug("Cloud SDK credentials not found on disk; not using them")
return None, None

credentials, project_id = load_credentials_from_file(credentials_filename)
Expand All @@ -174,6 +177,10 @@ def _get_explicit_environ_credentials():
variable."""
explicit_file = os.environ.get(environment_vars.CREDENTIALS)

_LOGGER.debug(
"Checking %s for explicit credentials as part of auth process...", explicit_file
)

if explicit_file is not None:
credentials, project_id = load_credentials_from_file(
os.environ[environment_vars.CREDENTIALS]
Expand All @@ -190,15 +197,20 @@ def _get_gae_credentials():
# While this library is normally bundled with app_engine, there are
# some cases where it's not available, so we tolerate ImportError.
try:
_LOGGER.debug("Checking for App Engine runtime as part of auth process...")
import google.auth.app_engine as app_engine
except ImportError:
_LOGGER.warning("Import of App Engine auth library failed.")
return None, None

try:
credentials = app_engine.Credentials()
project_id = app_engine.get_project_id()
return credentials, project_id
except EnvironmentError:
_LOGGER.debug(
"No App Engine library was found so cannot authentication via App Engine Identity Credentials."
)
return None, None


Expand All @@ -215,6 +227,7 @@ def _get_gce_credentials(request=None):
from google.auth import compute_engine
from google.auth.compute_engine import _metadata
except ImportError:
_LOGGER.warning("Import of Compute Engine auth library failed.")
return None, None

if request is None:
Expand All @@ -229,6 +242,9 @@ def _get_gce_credentials(request=None):

return compute_engine.Credentials(), project_id
else:
_LOGGER.warning(
"Authentication failed using Compute Engine authentication due to unavailable metadata server."
)
return None, None


Expand Down