diff --git a/api/chalicelib/utils/helper.py b/api/chalicelib/utils/helper.py index 41408088b..5370c8f67 100644 --- a/api/chalicelib/utils/helper.py +++ b/api/chalicelib/utils/helper.py @@ -1,4 +1,3 @@ -import logging import math import random import re @@ -9,7 +8,6 @@ from urllib.parse import urlparse from decouple import config import schemas -from chalicelib.utils import smtp from chalicelib.utils.TimeUTC import TimeUTC @@ -319,3 +317,19 @@ def obfuscate(text, keep_last: int = 4): if len(text) <= keep_last: return "*" * len(text) return "*" * (len(text) - keep_last) + text[-keep_last:] + + +def cast_session_id_to_string(data): + if not isinstance(data, dict) and not isinstance(data, list): + return data + if isinstance(data, list): + for i, item in enumerate(data): + data[i] = cast_session_id_to_string(item) + elif isinstance(data, dict): + keys = data.keys() + if "sessionId" in keys: + data["sessionId"] = str(data["sessionId"]) + else: + for key in keys: + data[key] = cast_session_id_to_string(data[key]) + return data diff --git a/api/or_dependencies.py b/api/or_dependencies.py index 824670687..77bcb9c44 100644 --- a/api/or_dependencies.py +++ b/api/or_dependencies.py @@ -8,6 +8,7 @@ from starlette.requests import Request from starlette.responses import Response, JSONResponse import schemas +from chalicelib.utils import helper async def OR_context(request: Request) -> schemas.CurrentContext: @@ -33,6 +34,9 @@ class ORRoute(APIRoute): if isinstance(response, JSONResponse): response: JSONResponse = response body = json.loads(response.body.decode('utf8')) + body=helper.cast_session_id_to_string(body) + response = JSONResponse(content=body, status_code=response.status_code, headers=response.headers, + media_type=response.media_type, background=response.background) if response.status_code == 200 \ and body is not None and isinstance(body, dict) \ and body.get("errors") is not None: diff --git a/ee/api/or_dependencies.py b/ee/api/or_dependencies.py index 421f0853f..0d0ea342a 100644 --- a/ee/api/or_dependencies.py +++ b/ee/api/or_dependencies.py @@ -11,6 +11,7 @@ from starlette.requests import Request from starlette.responses import Response, JSONResponse import schemas_ee +from chalicelib.utils import helper from chalicelib.core import traces @@ -37,7 +38,12 @@ class ORRoute(APIRoute): if isinstance(response, JSONResponse): response: JSONResponse = response body = json.loads(response.body.decode('utf8')) - if response.status_code == 200 and body is not None and body.get("errors") is not None: + body = helper.cast_session_id_to_string(body) + response = JSONResponse(content=body, status_code=response.status_code, headers=response.headers, + media_type=response.media_type, background=response.background) + if response.status_code == 200 \ + and body is not None and isinstance(body, dict) \ + and body.get("errors") is not None: if "not found" in body["errors"][0]: response.status_code = status.HTTP_404_NOT_FOUND else: