aboutsummaryrefslogtreecommitdiff
path: root/oauth2client
diff options
context:
space:
mode:
authorCraig Citro <craigcitro@gmail.com>2017-03-27 09:47:44 -0700
committerJon Wayne Parrott <jonwayne@google.com>2017-03-27 09:47:44 -0700
commitfeec15f070903069347b9386a24fb73148f97411 (patch)
treef90c1a0a8aeb25024c247763bd55969a45c3560d /oauth2client
parenta3cf56b659e067dea8ead933f81e4a6f42d30ed8 (diff)
downloadoauth2client-feec15f070903069347b9386a24fb73148f97411.tar.gz
Allow customizing the GCE metadata service address via an env var. (#704)
The goal here is to make it possible for a user of a binary that depends on this library (eg the google cloud SDK) to be able to customize where it looks for the GCE metadata service. (An adventurous user can already customize the GCE metadata service location via the existing global vars in this library.) The only bit of awkwardness here is really the test: since this is a top-level statement, reloading is the only way to ensure it works.
Diffstat (limited to 'oauth2client')
-rw-r--r--oauth2client/client.py2
-rw-r--r--oauth2client/contrib/_metadata.py4
2 files changed, 4 insertions, 2 deletions
diff --git a/oauth2client/client.py b/oauth2client/client.py
index de2a314..27d62eb 100644
--- a/oauth2client/client.py
+++ b/oauth2client/client.py
@@ -108,7 +108,7 @@ except ValueError: # pragma: NO COVER
GCE_METADATA_TIMEOUT = 3
_SERVER_SOFTWARE = 'SERVER_SOFTWARE'
-_GCE_METADATA_URI = 'http://169.254.169.254'
+_GCE_METADATA_URI = 'http://' + os.getenv('GCE_METADATA_IP', '169.254.169.254')
_METADATA_FLAVOR_HEADER = 'metadata-flavor' # lowercase header
_DESIRED_METADATA_FLAVOR = 'Google'
_GCE_HEADERS = {_METADATA_FLAVOR_HEADER: _DESIRED_METADATA_FLAVOR}
diff --git a/oauth2client/contrib/_metadata.py b/oauth2client/contrib/_metadata.py
index 1dd3542..564cd39 100644
--- a/oauth2client/contrib/_metadata.py
+++ b/oauth2client/contrib/_metadata.py
@@ -19,6 +19,7 @@ See https://cloud.google.com/compute/docs/metadata
import datetime
import json
+import os
from six.moves import http_client
from six.moves.urllib import parse as urlparse
@@ -28,7 +29,8 @@ from oauth2client import client
from oauth2client import transport
-METADATA_ROOT = 'http://metadata.google.internal/computeMetadata/v1/'
+METADATA_ROOT = 'http://{}/computeMetadata/v1/'.format(
+ os.getenv('GCE_METADATA_ROOT', 'metadata.google.internal'))
METADATA_HEADERS = {'Metadata-Flavor': 'Google'}