Skip to content

Commit 57cf500

Browse files
hilts-vaughanbusunkim96tseaver
authored
feat: Add debug logging that can help with diagnosing auth lib. path (#473)
Co-authored-by: Bu Sun Kim <8822365+busunkim96@users.noreply.github.com> Co-authored-by: Tres Seaver <tseaver@palladion.com>
1 parent a066013 commit 57cf500

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

packages/google-auth/google/auth/_default.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,13 @@ def _get_gcloud_sdk_credentials():
155155
"""Gets the credentials and project ID from the Cloud SDK."""
156156
from google.auth import _cloud_sdk
157157

158+
_LOGGER.debug("Checking Cloud SDK credentials as part of auth process...")
159+
158160
# Check if application default credentials exist.
159161
credentials_filename = _cloud_sdk.get_application_default_credentials_path()
160162

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

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

180+
_LOGGER.debug(
181+
"Checking %s for explicit credentials as part of auth process...", explicit_file
182+
)
183+
177184
if explicit_file is not None:
178185
credentials, project_id = load_credentials_from_file(
179186
os.environ[environment_vars.CREDENTIALS]
@@ -190,15 +197,20 @@ def _get_gae_credentials():
190197
# While this library is normally bundled with app_engine, there are
191198
# some cases where it's not available, so we tolerate ImportError.
192199
try:
200+
_LOGGER.debug("Checking for App Engine runtime as part of auth process...")
193201
import google.auth.app_engine as app_engine
194202
except ImportError:
203+
_LOGGER.warning("Import of App Engine auth library failed.")
195204
return None, None
196205

197206
try:
198207
credentials = app_engine.Credentials()
199208
project_id = app_engine.get_project_id()
200209
return credentials, project_id
201210
except EnvironmentError:
211+
_LOGGER.debug(
212+
"No App Engine library was found so cannot authentication via App Engine Identity Credentials."
213+
)
202214
return None, None
203215

204216

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

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

230243
return compute_engine.Credentials(), project_id
231244
else:
245+
_LOGGER.warning(
246+
"Authentication failed using Compute Engine authentication due to unavailable metadata server."
247+
)
232248
return None, None
233249

234250

0 commit comments

Comments
 (0)