Skip to content
Open
Show file tree
Hide file tree
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
12 changes: 9 additions & 3 deletions src/google/appengine/api/images/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,12 @@
from six.moves import range


_USE_GRPC = bool(os.environ.get('USE_CUSTOM_IMAGES_GRPC_SERVICE'))
# Image server configuration environment variable names.
USE_CUSTOM_IMAGES_GRPC_SERVICE = 'APPENGINE_USE_CUSTOM_IMAGES_GRPC_SERVICE'
IMAGES_SERVICE_ENDPOINT = 'APPENGINE_IMAGES_SERVICE_ENDPOINT'


_USE_GRPC = bool(os.environ.get(USE_CUSTOM_IMAGES_GRPC_SERVICE))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like I found a pre-existing bug:
In Python, bool() evaluates to True for any non-empty string. If a developer explicitly tries to disable the service by setting APPENGINE_USE_CUSTOM_IMAGES_GRPC_SERVICE: "false" or "0" in their app.yaml, it will be incorrectly evaluated as True.



class _FakeRpc(object):
Expand All @@ -69,9 +74,10 @@ def get_result(self):

def _make_grpc_call(method_name, request):
"""Creates an authenticated gRPC channel and makes an RPC call."""
endpoint = os.environ.get('IMAGES_SERVICE_ENDPOINT')
endpoint = os.environ.get(IMAGES_SERVICE_ENDPOINT)
if not endpoint:
raise ValueError("IMAGES_SERVICE_ENDPOINT environment variable not set")
raise ValueError(
"%s environment variable not set" % IMAGES_SERVICE_ENDPOINT)

parsed = six.moves.urllib.parse.urlparse(endpoint)
target_host = parsed.netloc + ':443'
Expand Down
8 changes: 4 additions & 4 deletions tests/google/appengine/api/images/images_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ class ImagesGrpcTest(absltest.TestCase):

def setUp(self):
super().setUp()
os.environ['USE_CUSTOM_IMAGES_GRPC_SERVICE'] = 'True'
os.environ[images.USE_CUSTOM_IMAGES_GRPC_SERVICE] = 'True'
self.use_grpc_patcher = mock.patch('google.appengine.api.images._USE_GRPC', True)
self.use_grpc_patcher.start()
os.environ['IMAGES_SERVICE_ENDPOINT'] = 'https://localhost'
os.environ[images.IMAGES_SERVICE_ENDPOINT] = 'https://localhost'

def tearDown(self):
self.use_grpc_patcher.stop()
super().tearDown()
del os.environ['USE_CUSTOM_IMAGES_GRPC_SERVICE']
del os.environ['IMAGES_SERVICE_ENDPOINT']
del os.environ[images.USE_CUSTOM_IMAGES_GRPC_SERVICE]
del os.environ[images.IMAGES_SERVICE_ENDPOINT]

@mock.patch('google.appengine.api.images._make_grpc_call')
def test_execute_transforms_async_grpc(self, mock_make_grpc_call):
Expand Down