aboutsummaryrefslogtreecommitdiff
path: root/google
diff options
context:
space:
mode:
authorarithmetic1728 <58957152+arithmetic1728@users.noreply.github.com>2021-02-19 10:26:48 -0800
committerGitHub <noreply@github.com>2021-02-19 10:26:48 -0800
commit3f2f3eaf09006d3d0ec9c030d359114238479279 (patch)
tree4fe9d9729fe559659714a7fd16060def32ea932d /google
parent65074d3fbe488b95923dfa8335d071fa90bf383f (diff)
downloadgoogle-auth-library-python-3f2f3eaf09006d3d0ec9c030d359114238479279.tar.gz
fix: ignore gcloud warning when getting project id (#708)
* fix: ignore gcloud warning when getting project id * update
Diffstat (limited to 'google')
-rw-r--r--google/auth/_cloud_sdk.py13
1 files changed, 10 insertions, 3 deletions
diff --git a/google/auth/_cloud_sdk.py b/google/auth/_cloud_sdk.py
index e772fe9..40e6aec 100644
--- a/google/auth/_cloud_sdk.py
+++ b/google/auth/_cloud_sdk.py
@@ -84,6 +84,13 @@ def get_application_default_credentials_path():
return os.path.join(config_path, _CREDENTIALS_FILENAME)
+def _run_subprocess_ignore_stderr(command):
+ """ Return subprocess.check_output with the given command and ignores stderr."""
+ with open(os.devnull, "w") as devnull:
+ output = subprocess.check_output(command, stderr=devnull)
+ return output
+
+
def get_project_id():
"""Gets the project ID from the Cloud SDK.
@@ -96,9 +103,9 @@ def get_project_id():
command = _CLOUD_SDK_POSIX_COMMAND
try:
- output = subprocess.check_output(
- (command,) + _CLOUD_SDK_CONFIG_COMMAND, stderr=subprocess.STDOUT
- )
+ # Ignore the stderr coming from gcloud, so it won't be mixed into the output.
+ # https://github.com/googleapis/google-auth-library-python/issues/673
+ output = _run_subprocess_ignore_stderr((command,) + _CLOUD_SDK_CONFIG_COMMAND)
except (subprocess.CalledProcessError, OSError, IOError):
return None