Skip to content
Snippets Groups Projects
Commit 8ffd0382 authored by Neda Moeini's avatar Neda Moeini
Browse files

Applied review suggestions.

parent e18f04fd
No related branches found
No related tags found
1 merge request!142Added middleware to modify porecess details response and replace the callback...
Pipeline #85401 failed
API Reference
=============
This page contains auto-generated API reference documentation [#f1]_.
.. toctree::
:titlesonly:
gso/gso
.. [#f1] Created with `sphinx-autodoc2 <https://github.com/chrisjsewell/sphinx-autodoc2>`_
``gso.api.v1.processes``
============================
.. automodule:: gso.api.v1.processes
:members:
:show-inheritance:
......@@ -24,18 +24,14 @@ class CallBackResultsBaseModel(OrchestratorBaseModel):
def callback_results(step_id: UUID) -> dict[str, Any]:
"""Retrieve callback results for a specific process step.
Args:
----
step_id (UUID): The unique identifier of the process step.
Returns:
-------
dict: Dictionary containing callback results.
Raises:
------
HTTPException: 404 status code if the specified step_id is not found or if
the 'callback_result' key is not present in the state.
:param step_id: The unique identifier of the process step.
:type step_id: UUID
:return: Dictionary containing callback results.
:rtype: dict[str, Any]
:raises HTTPException: 404 status code if the specified step_id is not found or if the 'callback_result' key
is not present in the state.
"""
step = ProcessStepTable.query.filter(ProcessStepTable.step_id == step_id).first()
......
......@@ -17,19 +17,21 @@ class ModifyProcessEndpointResponse(BaseHTTPMiddleware):
async def dispatch(self, request: Request, call_next: Callable) -> Response:
"""Middleware to modify the response for Process details endpoint.
Args:
----
request (Request): The incoming HTTP request.
call_next (Callable): The next middleware or endpoint in the stack.
Returns:
-------
Response: The modified HTTP response.
:param request: The incoming HTTP request.
:type request: Request
:param call_next: The next middleware or endpoint in the stack.
:type call_next: Callable
:return: The modified HTTP response.
:rtype: Response
"""
response = await call_next(request)
path_pattern = r"/api/processes/([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})"
path_pattern = re.compile(
r"/api/processes/([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})"
)
match = re.match(path_pattern, request.url.path)
match = path_pattern.match(request.url.path)
if match and response.status_code == HTTP_200_OK:
# Modify the response body as needed
......@@ -38,7 +40,7 @@ class ModifyProcessEndpointResponse(BaseHTTPMiddleware):
response_body += chunk
try:
json_content = json.loads(response_body)
await self.modify_response_body(json_content, request)
await self._modify_response_body(json_content, request)
modified_response_body = json.dumps(json_content).encode()
headers = dict(response.headers)
headers["content-length"] = str(len(modified_response_body))
......@@ -58,13 +60,11 @@ class ModifyProcessEndpointResponse(BaseHTTPMiddleware):
async def _get_token(request: Request) -> str:
"""Get the token from the request headers.
Args:
----
request (Request): The incoming HTTP request.
:param request: The incoming HTTP request.
:type request: Request
Returns:
-------
str: The token from the request headers in specific format.
:return: The token from the request headers in specific format.
:rtype: str
"""
bearer_prefix = "Bearer "
authorization_header = request.headers.get("Authorization")
......@@ -74,13 +74,15 @@ class ModifyProcessEndpointResponse(BaseHTTPMiddleware):
return f"?token={token}"
return ""
async def modify_response_body(self, response_body: dict[str, Any], request: Request) -> None:
async def _modify_response_body(self, response_body: dict[str, Any], request: Request) -> None:
"""Modify the response body as needed.
Args:
----
response_body (Dict[str, Any]): The response body in dictionary format.
request (Request): The incoming HTTP request.
:param response_body: The response body in dictionary format.
:type response_body: dict[str, Any]
:param request: The incoming HTTP request.
:type request: Request
:return: None
"""
max_output_length = 500
token = await self._get_token(request)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment