Skip to content

Commit

Permalink
feat(ui): add endpoints to gather and spoof data for UI to start prop…
Browse files Browse the repository at this point in the history
…erly
  • Loading branch information
brucetony committed Apr 11, 2024
1 parent 2c8b554 commit 3fae44e
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 50 deletions.
81 changes: 31 additions & 50 deletions hub_adapter/routers/hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,60 +14,16 @@
from hub_adapter.core import route
from hub_adapter.models.hub import Project, AllProjects, ApprovalStatus, AnalysisOrProjectNode, \
ListAnalysisOrProjectNodes, \
AnalysisNode, ListAnalysisNodes, RegistryProject, AnalysisImageUrl
AnalysisNode, ListAnalysisNodes, RegistryProject, AnalysisImageUrl, ListContainers

hub_router = APIRouter(
dependencies=[Security(verify_idp_token), Depends(add_hub_jwt), Security(idp_oauth2_scheme_pass),
Security(httpbearer)],
# dependencies=[Depends(add_hub_jwt)],
tags=["Hub"],
responses={404: {"description": "Not found"}},
)


# @hub_router.get("/hub/images", response_model=ImageDataResponse)
# async def get_images():
# """Return list of images for the frontend."""
# # TODO: replace with data from https://api.privateaim.net/master-images
#
# dummy_data = {
# "pullImages": [
# {
# "id": "59081687-3dfe-46cf-afb5-07c562a002af",
# "train_class_id": "choochoo",
# "repo_tag": "0.5.23-pull",
# "job_id": "49e79b47-686b-4fb8-9259-fd0035b0b7f6",
# "status": "pulled"
# }
# ],
# "pushImages": [
# {
# "id": "4a941577-46ce-4220-8ca0-181cf45abe29",
# "train_class_id": "choochoo",
# "repo_tag": "latest",
# "job_id": "5efabb71-ba5d-4d00-9ed4-f27eb6a52e8f",
# "status": "waiting_to_push"
# }
# ],
# }
# return dummy_data
#
#
# @hub_router.get("/hub/vault/status")
# async def get_vault_status():
# """Spoof vault status."""
# dummy_data = {
# "initialized": True,
# "sealed": False,
# "authenticated": True,
# "config": {
# "stationID": "4c0e4a1a-795b",
# "stationName": "Test FLAME Node Central",
# }
# }
# return dummy_data


@route(
request_method=hub_router.get,
path="/projects",
Expand Down Expand Up @@ -373,25 +329,50 @@ def get_registry_metadata_for_url(
headers={"WWW-Authenticate": "Bearer"},
)

node_external_name = registry_metadata[EXTERNAL_NAME]
registry_project_external_name = registry_metadata[EXTERNAL_NAME]

if REGISTRY not in registry_metadata or HOST not in registry_metadata[REGISTRY]:
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail=f"No registry is associated with node {node_external_name}",
detail=f"No registry is associated with node {registry_project_external_name}",
headers={"WWW-Authenticate": "Bearer"},
)

host = registry_metadata[REGISTRY][HOST]

return host, node_external_name, analysis_metadata[ID]
return host, registry_project_external_name, analysis_metadata[ID]


@hub_router.get("/analysis/image/{analysis_id}", response_model=AnalysisImageUrl)
async def get_analysis_image_url(
compiled_info: tuple = Depends(get_registry_metadata_for_url),
) -> dict:
"""Build an analysis image URL using its metadata from the Hub."""
host, node_external_name, analysis_id = compiled_info
compiled_url = {"image_url": f"{host}/{node_external_name}/{analysis_id}"}
host, registry_project_external_name, analysis_id = compiled_info
compiled_url = {"image_url": f"{host}/{registry_project_external_name}/{analysis_id}"}
return compiled_url


@route(
request_method=hub_router.get,
path="/analysis-nodes",
modified_path="/containers",
status_code=status.HTTP_200_OK,
service_url=hub_adapter_settings.HUB_SERVICE_URL,
response_model=ListContainers,
query_params=["include"],
post_processing_func="parse_containers",
)
async def list_analyses_as_containers(
request: Request,
response: Response,
include: Annotated[
str | None,
Query(
description="Whether to include additional data for the given parameter. Can only be 'node'/'analysis'",
pattern="^(node|analysis)$", # Must be "node" or "analysis" or null,
),
] = "analysis",
):
"""Gets all analyses and formats the data for the UI as "containers"."""
pass
44 changes: 44 additions & 0 deletions hub_adapter/routers/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from hub_adapter.conf import hub_adapter_settings
from hub_adapter.models.conf import KeycloakConfig
from hub_adapter.models.podorc import ImageDataResponse

metadata_router = APIRouter(
# dependencies=[Security(oauth2_scheme)],
Expand All @@ -27,3 +28,46 @@ async def get_node_version():
"""Return version of the node software/API."""
# TODO: move version definition to frontend
return {"appVersion": "0.1.0-gatewayapi"}


@metadata_router.get("/vault/status")
async def get_vault_status():
"""Spoof vault status."""
dummy_data = {
"initialized": True,
"sealed": False,
"authenticated": True,
"config": {
"stationID": "4c0e4a1a-795b",
"stationName": "Test FLAME Node Central",
}
}
return dummy_data


@metadata_router.get("/hub/images", response_model=ImageDataResponse)
async def get_images():
"""Return list of images for the frontend."""
# TODO: replace with data from https://api.privateaim.net/master-images

dummy_data = {
"pullImages": [
{
"id": "59081687-3dfe-46cf-afb5-07c562a002af",
"train_class_id": "choochoo",
"repo_tag": "0.5.23-pull",
"job_id": "49e79b47-686b-4fb8-9259-fd0035b0b7f6",
"status": "pulled"
}
],
"pushImages": [
{
"id": "4a941577-46ce-4220-8ca0-181cf45abe29",
"train_class_id": "choochoo",
"repo_tag": "latest",
"job_id": "5efabb71-ba5d-4d00-9ed4-f27eb6a52e8f",
"status": "waiting_to_push"
}
],
}
return dummy_data

0 comments on commit 3fae44e

Please sign in to comment.