|
1 | | -import arrow |
2 | | -from fastapi import APIRouter |
| 1 | +import logging |
| 2 | +from typing import Annotated, Any |
| 3 | + |
| 4 | +from fastapi import APIRouter, Depends, FastAPI, HTTPException, status |
| 5 | +from models_library.generics import Envelope |
3 | 6 | from models_library.services_types import ServiceKey, ServiceVersion |
| 7 | +from servicelib.fastapi.dependencies import get_app |
| 8 | + |
| 9 | +from ... import exceptions, registry_proxy |
4 | 10 |
|
5 | 11 | router = APIRouter() |
6 | 12 |
|
| 13 | +log = logging.getLogger(__name__) |
| 14 | + |
7 | 15 |
|
8 | 16 | @router.get("/service_extras/{service_key}/{service_version}") |
9 | 17 | async def list_service_extras( |
| 18 | + the_app: Annotated[FastAPI, Depends(get_app)], |
10 | 19 | service_key: ServiceKey, |
11 | 20 | service_version: ServiceVersion, |
12 | 21 | ): |
13 | | - # NOTE: sync url in docker/healthcheck.py with this entrypoint! |
14 | | - return f"{__name__}.health_check@{arrow.utcnow().isoformat()}" |
| 22 | + log.debug( |
| 23 | + "Client does service_extras_by_key_version_get request with service_key %s, service_version %s", |
| 24 | + service_key, |
| 25 | + service_version, |
| 26 | + ) |
| 27 | + try: |
| 28 | + service_extras = await registry_proxy.get_service_extras( |
| 29 | + the_app, service_key, service_version |
| 30 | + ) |
| 31 | + return Envelope[dict[str, Any]](data=service_extras) |
| 32 | + except exceptions.ServiceNotAvailableError as err: |
| 33 | + raise HTTPException( |
| 34 | + status_code=status.HTTP_404_NOT_FOUND, detail=f"{err}" |
| 35 | + ) from err |
| 36 | + except exceptions.RegistryConnectionError as err: |
| 37 | + raise HTTPException( |
| 38 | + status_code=status.HTTP_401_UNAUTHORIZED, detail=f"{err}" |
| 39 | + ) from err |
| 40 | + except Exception as err: |
| 41 | + raise HTTPException( |
| 42 | + status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=f"{err}" |
| 43 | + ) from err |
0 commit comments