Skip to content

Commit fcd3a9a

Browse files
fix
1 parent 8dbf3af commit fcd3a9a

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

gen3workflow/routes/s3.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from datetime import datetime, timezone
22
import hashlib
3+
import traceback
34
from typing import Tuple
45
import urllib.parse
56

@@ -42,6 +43,7 @@ def get_access_token(headers: Headers) -> Tuple[str, str]:
4243
(str, str): the user's access token or "" if not found, and the user's ID if the token is
4344
a client_credentials token
4445
"""
46+
# TODO unit tests for this function
4547
auth_header = headers.get("authorization")
4648
if not auth_header:
4749
return "", ""
@@ -51,13 +53,15 @@ def get_access_token(headers: Headers) -> Tuple[str, str]:
5153
raise HTTPException(HTTP_401_UNAUTHORIZED, err_msg)
5254
try:
5355
if "Credential=" in auth_header: # format 1 (see docstring)
54-
access_key_id = auth_header.split("Credential=")[1].split("/")[0]
56+
access_token = auth_header.split("Credential=")[1].split("/")[0]
57+
user_id = None
5558
else: # format 2 (see docstring)
5659
access_key_id = auth_header.split("AWS ")[1]
5760
access_key_id = ":".join(access_key_id.split(":")[:-1])
58-
access_token, user_id = access_key_id.split(";userId=")
61+
access_token, user_id = access_key_id.split(";userId=")
5962
return access_token, user_id
6063
except Exception as e:
64+
traceback.print_exc()
6165
logger.error(
6266
f"Unexpected format; unable to extract access token from authorization header: {e}"
6367
)
@@ -248,6 +252,7 @@ async def s3_endpoint(path: str, request: Request):
248252
data=body,
249253
)
250254

255+
logger.info(f"DEBUG: aws response = {response.status_code}")
251256
if response.status_code != 200:
252257
logger.debug(f"Received a non-200 status code from AWS: {response.status_code}")
253258
# no need to log 404 errors except in debug mode: they are are expected when running
@@ -259,7 +264,17 @@ async def s3_endpoint(path: str, request: Request):
259264
# return the response from AWS S3.
260265
# mask the details of 403 errors from the end user: authentication is done internally by this
261266
# function, so 403 errors are internal service errors
262-
resp_contents = response.content if response.status_code != 403 else None
267+
resp_contents = (
268+
response.content if response.status_code != HTTP_403_FORBIDDEN else None
269+
)
270+
logger.info(f"DEBUG: aws resp_contents = {resp_contents}")
271+
if "Content-Type" in response.headers:
272+
return Response(
273+
content=resp_contents,
274+
status_code=response.status_code,
275+
headers=response.headers,
276+
media_type=response.headers["Content-Type"],
277+
)
263278
return Response(
264279
content=resp_contents,
265280
status_code=response.status_code,

0 commit comments

Comments
 (0)