Skip to content

Commit

Permalink
mock app_identity
Browse files Browse the repository at this point in the history
  • Loading branch information
krzyzacy committed Feb 27, 2018
1 parent c493d69 commit c824fbf
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
18 changes: 9 additions & 9 deletions gubernator/gcs_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import json
import logging
import urlparse
import zlib

import google.appengine.ext.ndb as ndb
Expand All @@ -27,19 +28,19 @@
@ndb.tasklet
def get(url):
context = ndb.get_context()

auth_token, _ = app_identity.get_access_token(
'https://www.googleapis.com/auth/cloud-platform')
logging.info(
'Using token {} to represent identity {}'.format(
auth_token, app_identity.get_service_account_name()))

logging.info('token: %s', 'Bearer {}'.format(auth_token))
headers = {
'accept-encoding': 'gzip, *',
'x-goog-api-version': '2',
'Authorization': 'Bearer {}'.format(auth_token)
}

url_result = urlparse.urlparse(url)
if url_result.netloc.endswith('.googleapis.com'):
auth_token, _ = app_identity.get_access_token(
'https://www.googleapis.com/auth/cloud-platform')
if auth_token:
headers['Authorization'] = 'OAuth %s' % auth_token

for retry in xrange(6):
result = yield context.urlfetch(url, headers=headers)
status = result.status_code
Expand All @@ -56,7 +57,6 @@ def get(url):
len(content) / 1024,
len(dec.unconsumed_tail) / 1024)
raise ndb.Return(content)

logging.error("unable to fetch '%s': status code %d", url, status)
raise ndb.Return(None)

Expand Down
1 change: 1 addition & 0 deletions gubernator/gcs_async_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ def setUp(self):
self.testbed.init_urlfetch_stub()
self.testbed.init_blobstore_stub()
self.testbed.init_datastore_v3_stub()
self.testbed.init_app_identity_stub()
# redirect GCS calls to the local proxy
gcs_async.GCS_API_URL = gcs.common.local_api_url()

Expand Down
1 change: 1 addition & 0 deletions gubernator/main_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def init_stubs(self):
self.testbed.init_urlfetch_stub()
self.testbed.init_blobstore_stub()
self.testbed.init_datastore_v3_stub()
self.testbed.init_app_identity_stub()
# redirect GCS calls to the local proxy
gcs_async.GCS_API_URL = gcs.common.local_api_url()

Expand Down

0 comments on commit c824fbf

Please sign in to comment.