Skip to content

Commit

Permalink
Closes #2319
Browse files Browse the repository at this point in the history
  • Loading branch information
robertwb committed Mar 24, 2017
2 parents 9b8e16f + 7453766 commit c80ef18
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions sdks/python/apache_beam/internal/gcp/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,11 @@ def __init__(self, user_agent=None):
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 +
Expand Down

0 comments on commit c80ef18

Please sign in to comment.