diff --git a/.pylintrc b/.pylintrc index 9ccceba..e81c362 100644 --- a/.pylintrc +++ b/.pylintrc @@ -65,11 +65,7 @@ disable=print-statement, unpacking-in-except, old-raise-syntax, backtick, - long-suffix, - old-ne-operator, - old-octal-literal, import-star-module-level, - non-ascii-bytes-literal, raw-checker-failed, bad-inline-option, locally-disabled, @@ -117,7 +113,6 @@ disable=print-statement, range-builtin-not-iterating, filter-builtin-not-iterating, using-cmp-argument, - eq-without-hash, div-method, idiv-method, rdiv-method, @@ -329,13 +324,6 @@ max-line-length=100 # Maximum number of lines in a module. max-module-lines=1000 -# List of optional constructs for which whitespace checking is disabled. `dict- -# separator` is used to allow tabulation in dicts, etc.: {1 : 1,\n222: 2}. -# `trailing-comma` allows a space between comma and closing bracket: (a, ). -# `empty-line` allows space-only lines. -no-space-check=trailing-comma, - dict-separator - # Allow the body of a class to be on the same line as the declaration if body # contains single statement. single-line-class-stmt=no diff --git a/service/microservice.py b/service/microservice.py index 82e4296..5c1ee68 100755 --- a/service/microservice.py +++ b/service/microservice.py @@ -1,6 +1,6 @@ """Main application module""" import os -from urllib.parse import urlparse +from urllib import parse import sentry_sdk import falcon import requests @@ -18,23 +18,34 @@ def start_service(): def cloud_storage_service(_req, resp): """Send the request through to the cloudstorage microservice""" - path = urlparse(_req.uri).path[1:] + parsed = parse.urlparse(_req.uri) + + # strip off leading / + path = parsed.path[1:] # determine whether to use amazon s3 or azure blob storage # Use 'az' at beginning of the path to signal that file is from azure # eg. https://domain.com/az/some_file.pdf microservice_url = os.environ.get('CLOUDSTORAGE_URL') # default to s3 + request_params = { + 'name':path, + 'apikey':os.environ.get('CLOUDSTORAGE_API_KEY') + } + if path[0:3] == 'az/': microservice_url = microservice_url.replace('1.0', '2.0', 1) - path = path[3:] + request_params['name'] = path[3:] # remove az from name + + # pass thru querystring + parsed_query_dict = parse.parse_qs(parsed.query) + for param, val in parsed_query_dict.items(): + request_params[param] = val[0] response = requests.get( microservice_url, - params={ - 'name':path, - 'apikey':os.environ.get('CLOUDSTORAGE_API_KEY') - } + params=request_params, + timeout=300 ) resp.status = falcon.get_http_status(response.status_code) resp.content_type = response.headers['Content-Type'] diff --git a/tests/test_service.py b/tests/test_service.py index a6a56ed..4d971fa 100755 --- a/tests/test_service.py +++ b/tests/test_service.py @@ -21,8 +21,8 @@ def client(): @pytest.fixture def mock_env(monkeypatch): """ mock environment var """ - for key in ENV_VARS: - monkeypatch.setenv(key, ENV_VARS[key]) + for key, val in ENV_VARS.items(): + monkeypatch.setenv(key, val) def test_endpoint(client, mock_env): # pylint: disable=unused-argument @@ -42,7 +42,7 @@ def test_endpoint(client, mock_env): assert response.content == content # happy path azure blob storage - response = client.simulate_get('/az/dummy.pdf') + response = client.simulate_get('/az/dummy.pdf?src=abc') assert response.status_code == 200 assert response.headers['Content-Type'] == 'application/pdf' assert response.content == content