diff --git a/gateway/core.py b/gateway/core.py index 9a7eb4d..8d74370 100644 --- a/gateway/core.py +++ b/gateway/core.py @@ -49,9 +49,6 @@ async def make_request( query = {} async with httpx.AsyncClient(headers=headers) as client: - print(url) - print(query) - print(data) r = await client.request(url=url, method=method, params=query, data=data) resp_data = r.json() return resp_data, r.status_code diff --git a/gateway/models.py b/gateway/models.py index e273593..ec565c9 100644 --- a/gateway/models.py +++ b/gateway/models.py @@ -171,28 +171,54 @@ class ImageDataResponse(BaseModel): # Hub Models ## String Models -class IncludeNode(BaseModel): - """Include node.""" - include: str = "node" - - class ApprovalStatus(Enum): """Status of project possibilities.""" approved: str = "approved" rejected: str = "rejected" -class AnalysisNodeRunStatus(Enum): - """Possible values for analysis run status.""" +class AnalysisBuildStatus(Enum): + """Possible values for analysis build status.""" starting: str = "starting" started: str = "started" + stopping: str = "stopping" + stopped: str = "stopped" + finished: str = "finished" + failed: str = "failed" + + +class AnalysisRunStatus(Enum): + """Possible values for analysis run status.""" running: str = "running" + starting: str = "starting" + started: str = "started" stopping: str = "stopping" stopped: str = "stopped" finished: str = "finished" failed: str = "failed" +class AnalysisResultStatus(Enum): + """Possible values for analysis build status.""" + started: str = "started" + downloading: str = "downloading" + downloaded: str = "downloaded" + extracting: str = "extracting" + extracted: str = "extracted" + finished: str = "finished" + failed: str = "failed" + + +class ConfigurationStatus(Enum): + """"Possible values for configuration status.""" + base: str = "base" + security_configured: str = "security_configured" + resource_configured: str = "resource_configured" + hash_generated: str = "hash_generated" + hash_signed: str = "hash_signed" + finished: str = "finished" + + ## Response Models class BaseHubResponse(BaseModel): """Common attributes of Hub responses.""" @@ -201,6 +227,14 @@ class BaseHubResponse(BaseModel): updated_at: datetime.datetime +class Registry(BaseHubResponse): + """Details the registry information.""" + name: str | None = None + host: str | None = None + account_name: str | None = None + account_secret: str | None = None + + class MasterImage(BaseHubResponse): """Master image details.""" path: str @@ -254,16 +288,39 @@ class ListAnalysisOrProjectNodes(BaseModel): data: list[AnalysisOrProjectNode] +class Analysis(BaseHubResponse): + """Model representing a single analysis.""" + name: str | None = None + nodes: int + configuration_status: ConfigurationStatus + build_status: AnalysisBuildStatus + run_status: AnalysisRunStatus + result_status: AnalysisResultStatus + registry: Registry | None = None + registry_id: uuid.UUID | None = None + realm_id: uuid.UUID + user_id: uuid.UUID + project_id: uuid.UUID + project: Project | None = None + master_image_id: uuid.UUID + master_image: MasterImage | None = None + + class AnalysisNode(AnalysisOrProjectNode): """Node analysis response model.""" - run_status: AnalysisNodeRunStatus + run_status: AnalysisRunStatus | None = None index: int artifact_tag: str | None = None artifact_digest: str | None = None analysis_id: uuid.UUID analysis_realm_id: uuid.UUID + analysis: Analysis | None = None node: Node | None = None +class PartialAnalysisNode(AnalysisNode): + """Node analysis""" + + class ListAnalysisNodes(BaseModel): data: list[AnalysisNode] diff --git a/gateway/routers/hub.py b/gateway/routers/hub.py index c2a1d25..b0d1581 100644 --- a/gateway/routers/hub.py +++ b/gateway/routers/hub.py @@ -2,7 +2,7 @@ import uuid from typing import Annotated -from fastapi import APIRouter, Security, Query, Body, Path +from fastapi import APIRouter, Security, Query, Path from starlette import status from starlette.requests import Request from starlette.responses import Response @@ -11,7 +11,7 @@ from gateway.conf import gateway_settings from gateway.core import route from gateway.models import ImageDataResponse, ContainerResponse, Project, AllProjects, \ - ApprovalStatus, AnalysisOrProjectNode, ListAnalysisNodes, ListAnalysisOrProjectNodes + ApprovalStatus, AnalysisOrProjectNode, ListAnalysisNodes, ListAnalysisOrProjectNodes, AnalysisNode hub_router = APIRouter( dependencies=[Security(hub_oauth2_scheme)], @@ -138,7 +138,7 @@ async def list_specific_project( query_params=["filter_id", "filter_approval_status", "filter_project_id", "filter_project_realm_id", "filter_node_id", "filter_node_realm_id"], ) -async def list_project_node( +async def list_projects_and_nodes( request: Request, response: Response, filter_id: Annotated[ @@ -184,23 +184,21 @@ async def list_project_node( @route( request_method=hub_router.post, - path="/project-nodes", + path="/project-nodes/{project_id}", status_code=status.HTTP_200_OK, service_url=gateway_settings.HUB_SERVICE_URL, response_model=AnalysisOrProjectNode, - body_params=["project_id", "node_id"], - query_params=["approval_status"], + body_params=["approval_status"], ) -async def create_project_node( +async def accept_reject_project_node( request: Request, response: Response, - project_id: Annotated[uuid.UUID, Body(description="Project ID as UUID")], - node_id: Annotated[uuid.UUID, Body(description="Node ID as UUID")], + project_id: Annotated[uuid.UUID, Path(description="Project object UUID (not project ID).")], approval_status: Annotated[ApprovalStatus, Query( description="Set the approval status of project for the node. Either 'rejected' or 'approved'" )], ): - """Create a project at a specific node and set the approval status.""" + """Set the approval status of a project.""" pass @@ -213,7 +211,7 @@ async def create_project_node( query_params=["filter_id", "filter_approval_status", "filter_project_id", "filter_project_realm_id", "filter_node_id", "filter_node_realm_id", "include"], ) -async def list_analyses_of_node( +async def list_analyses_of_nodes( request: Request, response: Response, include: Annotated[ @@ -274,3 +272,39 @@ async def list_analyses_of_node( ): """List analyses for a node.""" pass + + +@route( + request_method=hub_router.get, + path="/analysis-nodes/{analysis_id}", + status_code=status.HTTP_200_OK, + service_url=gateway_settings.HUB_SERVICE_URL, + response_model=AnalysisNode, +) +async def list_specific_analysis( + analysis_id: Annotated[uuid.UUID, Path(description="Analysis UUID.")], + request: Request, + response: Response, +): + """List project for a given UUID.""" + pass + + +@route( + request_method=hub_router.post, + path="/analysis-nodes/{analysis_id}", + status_code=status.HTTP_200_OK, + service_url=gateway_settings.HUB_SERVICE_URL, + response_model=AnalysisNode, + body_params=["approval_status"], +) +async def accept_reject_analysis_node( + request: Request, + response: Response, + analysis_id: Annotated[uuid.UUID, Path(description="Analysis object UUID (not analysis_id).")], + approval_status: Annotated[ApprovalStatus, Query( + description="Set the approval status of project for the node. Either 'rejected' or 'approved'" + )], +): + """Set the approval status of a analysis.""" + pass