Skip to content

Commit

Permalink
more logs
Browse files Browse the repository at this point in the history
  • Loading branch information
paulineribeyre committed Oct 17, 2024
1 parent a0d5cb4 commit 16c63e7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
8 changes: 3 additions & 5 deletions gen3workflow/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,12 @@ async def get_token_claims(self) -> dict:
"user", "openid", audience="openid", purpose="access"
)(self.bearer_token)
except Exception as e:
err_msg = "Could not verify, parse, and/or validate provided access token"
logger.error(
f"Could not get token claims:\n{e.detail if hasattr(e, 'detail') else e}",
f"{err_msg}:\n{e.detail if hasattr(e, 'detail') else e}",
exc_info=True,
)
raise HTTPException(
HTTP_401_UNAUTHORIZED,
"Could not verify, parse, and/or validate scope from provided access token.",
)
raise HTTPException(HTTP_401_UNAUTHORIZED, err_msg)

return token_claims

Expand Down
19 changes: 16 additions & 3 deletions gen3workflow/routes/ga4gh_tes.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from fastapi import APIRouter, Depends, HTTPException, Request
from starlette.status import HTTP_200_OK, HTTP_401_UNAUTHORIZED, HTTP_403_FORBIDDEN

from gen3workflow import logger
from gen3workflow.auth import Auth
from gen3workflow.config import config

Expand All @@ -31,6 +32,7 @@ async def get_request_body(request: Request):
async def service_info(request: Request):
res = await request.app.async_client.get(f"{config['TES_SERVER_URL']}/service-info")
if res.status_code != HTTP_200_OK:
logger.error(f"TES server error: {res.text}")
raise HTTPException(res.status_code, res.text)
return res.json()

Expand All @@ -43,7 +45,9 @@ async def create_task(request: Request, auth=Depends(Auth)):
# add the `AUTHZ` tag to the task, so access can be checked by the other endpoints
user_id = (await auth.get_token_claims()).get("sub")
if not user_id:
raise HTTPException(HTTP_401_UNAUTHORIZED, "No user sub in token")
err_msg = "No user sub in token"
logger.error(err_msg)
raise HTTPException(HTTP_401_UNAUTHORIZED, err_msg)
if "tags" not in body:
body["tags"] = {}
body["tags"]["AUTHZ"] = f"/users/{user_id}/gen3-workflow/tasks/TASK_ID_PLACEHOLDER"
Expand All @@ -52,6 +56,7 @@ async def create_task(request: Request, auth=Depends(Auth)):
f"{config['TES_SERVER_URL']}/tasks", json=body
)
if res.status_code != HTTP_200_OK:
logger.error(f"TES server error: {res.text}")
raise HTTPException(res.status_code, res.text)
return res.json()

Expand All @@ -77,6 +82,7 @@ async def list_tasks(request: Request, auth=Depends(Auth)):
f"{config['TES_SERVER_URL']}/tasks", params=query_params
)
if res.status_code != HTTP_200_OK:
logger.error(f"TES server error: {res.text}")
raise HTTPException(res.status_code, res.text)
listed_tasks = res.json()

Expand Down Expand Up @@ -114,13 +120,16 @@ async def get_task(request: Request, task_id: str, auth=Depends(Auth)):
f"{config['TES_SERVER_URL']}/tasks/{task_id}", params=query_params
)
if res.status_code != HTTP_200_OK:
logger.error(f"TES server error: {res.text}")
raise HTTPException(res.status_code, res.text)

# check if this user has access to see this task
body = res.json()
authz_path = body.get("tags", {}).get("AUTHZ")
if not authz_path:
raise HTTPException(HTTP_403_FORBIDDEN, "No authz tag in task body")
err_msg = "No authz tag in task body"
logger.error(err_msg)
raise HTTPException(HTTP_403_FORBIDDEN, err_msg)
authz_path = authz_path.replace("TASK_ID_PLACEHOLDER", task_id)
await auth.authorize("create", [authz_path])

Expand All @@ -134,11 +143,14 @@ async def cancel_task(request: Request, task_id: str, auth=Depends(Auth)):
f"{config['TES_SERVER_URL']}/tasks/{task_id}"
)
if res.status_code != HTTP_200_OK:
logger.error(f"TES server error: {res.text}")
raise HTTPException(res.status_code, res.text)
body = res.json()
authz_path = body.get("tags", {}).get("AUTHZ")
if not authz_path:
raise HTTPException(HTTP_403_FORBIDDEN, "No authz tag in task body")
err_msg = "No authz tag in task body"
logger.error(err_msg)
raise HTTPException(HTTP_403_FORBIDDEN, err_msg)
authz_path = authz_path.replace("TASK_ID_PLACEHOLDER", task_id)
await auth.authorize("delete", [authz_path])

Expand All @@ -147,6 +159,7 @@ async def cancel_task(request: Request, task_id: str, auth=Depends(Auth)):
f"{config['TES_SERVER_URL']}/tasks/{task_id}:cancel"
)
if res.status_code != HTTP_200_OK:
logger.error(f"TES server error: {res.text}")
raise HTTPException(res.status_code, res.text)

return res.json()

0 comments on commit 16c63e7

Please sign in to comment.