diff --git a/docs/source/apidocs/index.rst b/docs/source/apidocs/index.rst new file mode 100644 index 0000000000000000000000000000000000000000..d2fe18f8015c460fa139fd612d7d9e425304b272 --- /dev/null +++ b/docs/source/apidocs/index.rst @@ -0,0 +1,11 @@ +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>`_ diff --git a/docs/source/module/api/v1/processes.rst b/docs/source/module/api/v1/processes.rst new file mode 100644 index 0000000000000000000000000000000000000000..82aa87628771ec27ee360bf8c2ac4a79eef248ed --- /dev/null +++ b/docs/source/module/api/v1/processes.rst @@ -0,0 +1,6 @@ +``gso.api.v1.processes`` +============================ + +.. automodule:: gso.api.v1.processes + :members: + :show-inheritance: diff --git a/gso/api/v1/processes.py b/gso/api/v1/processes.py index a5f120397a57c9fa688e0058719c64c113d34181..32eb104c5860c60e99d6ae34cdbf37edba075a34 100644 --- a/gso/api/v1/processes.py +++ b/gso/api/v1/processes.py @@ -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() diff --git a/gso/middlewares.py b/gso/middlewares.py index e0d276e3558c72d43127310cdd5576a062cb2be3..58106502b70a794cde29cfb714ce61101d056dbb 100644 --- a/gso/middlewares.py +++ b/gso/middlewares.py @@ -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)