From 7ec3d19c87df2c92eac2308dbdad060547d63a31 Mon Sep 17 00:00:00 2001 From: sanderegg <35365065+sanderegg@users.noreply.github.com> Date: Mon, 4 Nov 2024 17:54:13 +0100 Subject: [PATCH] migrated service extras endpoint --- .../api/rest/_service_extras.py | 37 +++++++++++++++++-- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/services/director/src/simcore_service_director/api/rest/_service_extras.py b/services/director/src/simcore_service_director/api/rest/_service_extras.py index 1c30f411e22..f301a74a429 100644 --- a/services/director/src/simcore_service_director/api/rest/_service_extras.py +++ b/services/director/src/simcore_service_director/api/rest/_service_extras.py @@ -1,14 +1,43 @@ -import arrow -from fastapi import APIRouter +import logging +from typing import Annotated, Any + +from fastapi import APIRouter, Depends, FastAPI, HTTPException, status +from models_library.generics import Envelope from models_library.services_types import ServiceKey, ServiceVersion +from servicelib.fastapi.dependencies import get_app + +from ... import exceptions, registry_proxy router = APIRouter() +log = logging.getLogger(__name__) + @router.get("/service_extras/{service_key}/{service_version}") async def list_service_extras( + the_app: Annotated[FastAPI, Depends(get_app)], service_key: ServiceKey, service_version: ServiceVersion, ): - # NOTE: sync url in docker/healthcheck.py with this entrypoint! - return f"{__name__}.health_check@{arrow.utcnow().isoformat()}" + log.debug( + "Client does service_extras_by_key_version_get request with service_key %s, service_version %s", + service_key, + service_version, + ) + try: + service_extras = await registry_proxy.get_service_extras( + the_app, service_key, service_version + ) + return Envelope[dict[str, Any]](data=service_extras) + except exceptions.ServiceNotAvailableError as err: + raise HTTPException( + status_code=status.HTTP_404_NOT_FOUND, detail=f"{err}" + ) from err + except exceptions.RegistryConnectionError as err: + raise HTTPException( + status_code=status.HTTP_401_UNAUTHORIZED, detail=f"{err}" + ) from err + except Exception as err: + raise HTTPException( + status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=f"{err}" + ) from err