fix: detect correct auth when ADC env var is set but empty (#1374) · googleapis/google-auth-library-python@bfc07e1
@@ -330,31 +330,31 @@ def _get_explicit_environ_credentials(quota_project_id=None):
330330from google.auth import _cloud_sdk
331331332332cloud_sdk_adc_path = _cloud_sdk.get_application_default_credentials_path()
333-explicit_file = os.environ.get(environment_vars.CREDENTIALS)
333+explicit_file = os.environ.get(environment_vars.CREDENTIALS, "")
334334335335_LOGGER.debug(
336-"Checking %s for explicit credentials as part of auth process...", explicit_file
336+"Checking '%s' for explicit credentials as part of auth process...",
337+explicit_file,
337338 )
338339339-if explicit_file is not None and explicit_file == cloud_sdk_adc_path:
340+if explicit_file != "" and explicit_file == cloud_sdk_adc_path:
340341# Cloud sdk flow calls gcloud to fetch project id, so if the explicit
341342# file path is cloud sdk credentials path, then we should fall back
342343# to cloud sdk flow, otherwise project id cannot be obtained.
343344_LOGGER.debug(
344-"Explicit credentials path %s is the same as Cloud SDK credentials path, fall back to Cloud SDK credentials flow...",
345+"Explicit credentials path '%s' is the same as Cloud SDK credentials path, fall back to Cloud SDK credentials flow...",
345346explicit_file,
346347 )
347348return _get_gcloud_sdk_credentials(quota_project_id=quota_project_id)
348349349-if explicit_file is not None:
350+if explicit_file != "":
350351with warnings.catch_warnings():
351352warnings.simplefilter("ignore", DeprecationWarning)
352353credentials, project_id = load_credentials_from_file(
353354os.environ[environment_vars.CREDENTIALS],
354355quota_project_id=quota_project_id,
355356 )
356357credentials._cred_file_path = f"{explicit_file} file via the GOOGLE_APPLICATION_CREDENTIALS environment variable"
357-358358return credentials, project_id
359359360360else: