Skip to content

Commit c824fbf

Browse files
committed
mock app_identity
1 parent c493d69 commit c824fbf

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

gubernator/gcs_async.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import json
1616
import logging
17+
import urlparse
1718
import zlib
1819

1920
import google.appengine.ext.ndb as ndb
@@ -27,19 +28,19 @@
2728
@ndb.tasklet
2829
def get(url):
2930
context = ndb.get_context()
30-
31-
auth_token, _ = app_identity.get_access_token(
32-
'https://www.googleapis.com/auth/cloud-platform')
33-
logging.info(
34-
'Using token {} to represent identity {}'.format(
35-
auth_token, app_identity.get_service_account_name()))
3631

37-
logging.info('token: %s', 'Bearer {}'.format(auth_token))
3832
headers = {
3933
'accept-encoding': 'gzip, *',
4034
'x-goog-api-version': '2',
41-
'Authorization': 'Bearer {}'.format(auth_token)
4235
}
36+
37+
url_result = urlparse.urlparse(url)
38+
if url_result.netloc.endswith('.googleapis.com'):
39+
auth_token, _ = app_identity.get_access_token(
40+
'https://www.googleapis.com/auth/cloud-platform')
41+
if auth_token:
42+
headers['Authorization'] = 'OAuth %s' % auth_token
43+
4344
for retry in xrange(6):
4445
result = yield context.urlfetch(url, headers=headers)
4546
status = result.status_code
@@ -56,7 +57,6 @@ def get(url):
5657
len(content) / 1024,
5758
len(dec.unconsumed_tail) / 1024)
5859
raise ndb.Return(content)
59-
6060
logging.error("unable to fetch '%s': status code %d", url, status)
6161
raise ndb.Return(None)
6262

gubernator/gcs_async_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ def setUp(self):
8888
self.testbed.init_urlfetch_stub()
8989
self.testbed.init_blobstore_stub()
9090
self.testbed.init_datastore_v3_stub()
91+
self.testbed.init_app_identity_stub()
9192
# redirect GCS calls to the local proxy
9293
gcs_async.GCS_API_URL = gcs.common.local_api_url()
9394

gubernator/main_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ def init_stubs(self):
6868
self.testbed.init_urlfetch_stub()
6969
self.testbed.init_blobstore_stub()
7070
self.testbed.init_datastore_v3_stub()
71+
self.testbed.init_app_identity_stub()
7172
# redirect GCS calls to the local proxy
7273
gcs_async.GCS_API_URL = gcs.common.local_api_url()
7374

0 commit comments

Comments
 (0)