diff options
author | Jon Wayne Parrott <jonwayne@google.com> | 2016-07-27 13:53:27 -0700 |
---|---|---|
committer | Jon Wayne Parrott <jonwayne@google.com> | 2016-07-27 13:53:27 -0700 |
commit | 216c7c9407ffdc320a9225cee3b2315d086a2327 (patch) | |
tree | 8b07f136ad4f496caaef5feeeba4d69adbdc789f /oauth2client | |
parent | bb2386ea51b330765b7c44461465bdceb0be09b4 (diff) | |
download | oauth2client-216c7c9407ffdc320a9225cee3b2315d086a2327.tar.gz |
Add configurable timeout for metadata server.
Diffstat (limited to 'oauth2client')
-rw-r--r-- | oauth2client/client.py | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/oauth2client/client.py b/oauth2client/client.py index 4efd492..16aedba 100644 --- a/oauth2client/client.py +++ b/oauth2client/client.py @@ -102,6 +102,14 @@ DEFAULT_ENV_NAME = 'UNKNOWN' # If set to True _get_environment avoid GCE check (_detect_gce_environment) NO_GCE_CHECK = os.environ.setdefault('NO_GCE_CHECK', 'False') +# Timeout in seconds to wait for the GCE metadata server when detecting the +# GCE environment. +try: + GCE_METADATA_TIMEOUT = int( + os.environ.setdefault('GCE_METADATA_TIMEOUT', '3')) +except ValueError: # pragma: NO COVER + GCE_METADATA_TIMEOUT = 3 + _SERVER_SOFTWARE = 'SERVER_SOFTWARE' _GCE_METADATA_HOST = '169.254.169.254' _METADATA_FLAVOR_HEADER = 'Metadata-Flavor' @@ -998,7 +1006,7 @@ def _detect_gce_environment(): # the metadata resolution was particularly slow. The latter case is # "unlikely". connection = six.moves.http_client.HTTPConnection( - _GCE_METADATA_HOST, timeout=1) + _GCE_METADATA_HOST, timeout=GCE_METADATA_TIMEOUT) try: headers = {_METADATA_FLAVOR_HEADER: _DESIRED_METADATA_FLAVOR} |