Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add debug logging that can help with diagnosing auth lib. path #473

Merged
merged 5 commits into from
Jul 21, 2020
Merged
Changes from 1 commit
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
10 changes: 10 additions & 0 deletions google/auth/_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,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 @@ -160,6 +163,8 @@ def _get_explicit_environ_credentials():
"""Gets credentials from the GOOGLE_APPLICATION_CREDENTIALS environment
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(
Expand All @@ -177,15 +182,18 @@ 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 @@ -202,6 +210,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 @@ -216,6 +225,7 @@ 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