Skip to content

Commit

Permalink
Merge pull request #5 from SFDigitalServices/EPR-639_multiple_storage…
Browse files Browse the repository at this point in the history
…_accounts

Epr 639 multiple storage accounts
  • Loading branch information
josh-chou authored Apr 12, 2023
2 parents 03f821c + 2a8b054 commit dd8e4fb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 22 deletions.
12 changes: 0 additions & 12 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
25 changes: 18 additions & 7 deletions service/microservice.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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']
Expand Down
6 changes: 3 additions & 3 deletions tests/test_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit dd8e4fb

Please sign in to comment.