From 731f47d9395d3f51a27bbffe0b72c8e885065a41 Mon Sep 17 00:00:00 2001 From: Taha Yassine Kraiem Date: Tue, 15 Nov 2022 14:02:29 +0100 Subject: [PATCH] chore(chalice): return error if unprocessed file is huge chore(chalice): fixed add webhook --- api/chalicelib/core/assist.py | 10 ++++++---- api/routers/core.py | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/api/chalicelib/core/assist.py b/api/chalicelib/core/assist.py index 0a5e5e59d..7fd68e029 100644 --- a/api/chalicelib/core/assist.py +++ b/api/chalicelib/core/assist.py @@ -1,5 +1,5 @@ from os import access, R_OK -from os.path import exists as path_exists +from os.path import exists as path_exists, getsize import jwt import requests @@ -207,9 +207,11 @@ def get_raw_mob_by_id(project_id, session_id): path_to_file = efs_path + "/" + __get_mob_path(project_id=project_id, session_id=session_id) if path_exists(path_to_file): if not access(path_to_file, R_OK): - raise HTTPException(400, f"Replay file found under: {efs_path};" - f" but it is not readable, please check permissions") - + raise HTTPException(400, f"Replay file found under: {efs_path};" + + f" but it is not readable, please check permissions") + # getsize return size in bytes, UNPROCESSED_MAX_SIZE is in Kb + if (getsize(path_to_file) / 1000) >= config("UNPROCESSED_MAX_SIZE", cast=int, default=200 * 1000): + raise HTTPException(413, "Replay file too large") return path_to_file return None diff --git a/api/routers/core.py b/api/routers/core.py index 9a0032329..76383668d 100644 --- a/api/routers/core.py +++ b/api/routers/core.py @@ -867,7 +867,7 @@ def delete_slack_integration(integrationId: int, context: schemas.CurrentContext return webhook.delete(context.tenant_id, integrationId) -@app.post('/webhooks', tags=["webhooks"]) +@app.put('/webhooks', tags=["webhooks"]) def add_edit_webhook(data: schemas.CreateEditWebhookSchema = Body(...), context: schemas.CurrentContext = Depends(OR_context)): return {"data": webhook.add_edit(tenant_id=context.tenant_id, data=data.dict(), replace_none=True)}