Repository: beam Updated Branches: refs/heads/master 9b8e16fca -> c80ef1837
Allow customizing the GCE metadata service URL. The goal here is to allow a user to customize where a job finds the metadata service; it would also be possible to do this programmatically (eg expose a variable), but making it an environment variable allows a caller to do this without need to do so in-process. Project: http://git-wip-us.apache.org/repos/asf/beam/repo Commit: http://git-wip-us.apache.org/repos/asf/beam/commit/7453766b Tree: http://git-wip-us.apache.org/repos/asf/beam/tree/7453766b Diff: http://git-wip-us.apache.org/repos/asf/beam/diff/7453766b Branch: refs/heads/master Commit: 7453766b0045fabcb8e6e683b30f7fa1a20b334c Parents: 9b8e16f Author: Craig Citro <craigci...@google.com> Authored: Fri Mar 24 13:38:50 2017 -0700 Committer: Robert Bradshaw <rober...@gmail.com> Committed: Fri Mar 24 14:47:19 2017 -0700 ---------------------------------------------------------------------- sdks/python/apache_beam/internal/gcp/auth.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/beam/blob/7453766b/sdks/python/apache_beam/internal/gcp/auth.py ---------------------------------------------------------------------- diff --git a/sdks/python/apache_beam/internal/gcp/auth.py b/sdks/python/apache_beam/internal/gcp/auth.py index ccc67c6..8304658 100644 --- a/sdks/python/apache_beam/internal/gcp/auth.py +++ b/sdks/python/apache_beam/internal/gcp/auth.py @@ -86,9 +86,11 @@ class GCEMetadataCredentials(OAuth2Credentials): retry_filter=retry.retry_on_server_errors_and_timeout_filter) def _refresh(self, http_request): refresh_time = datetime.datetime.now() - req = urllib2.Request('http://metadata.google.internal/computeMetadata/v1/' - 'instance/service-accounts/default/token', - headers={'Metadata-Flavor': 'Google'}) + metadata_root = os.environ.get( + 'GCE_METADATA_ROOT', 'metadata.google.internal') + token_url = ('http://{}/computeMetadata/v1/instance/service-accounts/' + 'default/token').format(metadata_root) + req = urllib2.Request(token_url, headers={'Metadata-Flavor': 'Google'}) token_data = json.loads(urllib2.urlopen(req).read()) self.access_token = token_data['access_token'] self.token_expiry = (refresh_time +