Skip to content

Commit 9cd75a8

Browse files
committed
fix: move healthcheck to unauth router to allow cli healthchecks
1 parent ff75793 commit 9cd75a8

File tree

3 files changed

+24
-12
lines changed

3 files changed

+24
-12
lines changed

src/rmmtxauthz/web/application.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from .mediamtx import mtxrouter
1717
from .instructions import router as irouter
1818
from .interop import interoprouter
19-
19+
from .health import hrouter
2020

2121
LOGGER = logging.getLogger(__name__)
2222

@@ -47,6 +47,7 @@ def get_app_no_init() -> FastAPI:
4747
app.include_router(crudrouter, prefix="/api/v1/users", tags=["users"])
4848
app.include_router(mtxrouter, prefix="/api/v1/mediamtx", tags=["mediamtx"])
4949
app.include_router(irouter, prefix="/api/v1", tags=["instructions"])
50+
app.include_router(hrouter, prefix="/api/v1", tags=["health"])
5051
return app
5152

5253

src/rmmtxauthz/web/health.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""Health check"""
2+
3+
import logging
4+
5+
from fastapi import APIRouter
6+
from libpvarki.schemas.product import ProductHealthCheckResponse
7+
8+
from ..db.user import User
9+
10+
LOGGER = logging.getLogger(__name__)
11+
12+
hrouter = APIRouter()
13+
14+
15+
@hrouter.get("/healthcheck")
16+
async def request_healthcheck() -> ProductHealthCheckResponse:
17+
"""Check that we are healthy, return accordingly"""
18+
users_count = 0
19+
async for _user in User.list():
20+
users_count += 1
21+
return ProductHealthCheckResponse(healthy=True, extra=f"DB works, {users_count} users found")

src/rmmtxauthz/web/instructions.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from pydantic import BaseModel, Field, ConfigDict
1010
from fastapi import APIRouter, Depends, Request, HTTPException
1111
from libpvarki.middleware import MTLSHeader
12-
from libpvarki.schemas.product import UserCRUDRequest, ProductHealthCheckResponse
12+
from libpvarki.schemas.product import UserCRUDRequest
1313

1414
from ..db.user import User
1515
from ..db.errors import NotFound
@@ -87,13 +87,3 @@ async def user_intructions(user: UserCRUDRequest, request: Request, language: st
8787
)
8888

8989
return {"callsign": dbuser.username, "instructions": json.dumps(instructions_data), "language": language}
90-
91-
92-
@router.get("/healthcheck")
93-
async def request_healthcheck(request: Request) -> ProductHealthCheckResponse:
94-
"""Check that we are healthy, return accordingly"""
95-
comes_from_rm(request)
96-
users_count = 0
97-
async for _user in User.list():
98-
users_count += 1
99-
return ProductHealthCheckResponse(healthy=True, extra=f"DB works, {users_count} users found")

0 commit comments

Comments
 (0)