Skip to content
This repository was archived by the owner on Sep 16, 2022. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions python/src/cloudstorage/storage_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@
from google.appengine.api import app_identity


def _is_local_service_account():
service_account_name = app_identity.get_service_account_name()
return service_account_name == '' or service_account_name.endswith('@localhost')


def _get_storage_api(retry_params, account_id=None):
"""Returns storage_api instance for API methods.

Expand All @@ -66,9 +71,8 @@ def _get_storage_api(retry_params, account_id=None):

# when running local unit tests, the service account is test@localhost
# from google.appengine.api.app_identity.app_identity_stub.APP_SERVICE_ACCOUNT_NAME
service_account = app_identity.get_service_account_name()
if (common.local_run() and not common.get_access_token()
and (not service_account or service_account.endswith('@localhost'))):
# call get_service_account_name rarely: it can raise OverQuotaException
if (common.local_run() and not common.get_access_token() and _is_local_service_account()):
api.api_url = common.local_api_url()
if common.get_access_token():
api.token = common.get_access_token()
Expand Down