Add token-based authentication to health check endpoint

This commit is contained in:
vvzvlad
2025-02-07 00:11:47 +03:00
parent 5ff32e4769
commit 0ed4d71b96
+9 -2
View File
@@ -384,8 +384,15 @@ async def get_post(channel: str, post_id: int, token: str | None = None):
raise HTTPException(status_code=500, detail=error_message) from e
@app.get("/health")
async def health_check():
@app.get("/health/{token}")
async def health_check(token: str | None = None):
if Config["token"]:
if token != Config["token"]:
logger.error(f"Invalid token for health check: {token}, expected: {Config['token']}")
raise HTTPException(status_code=403, detail="Invalid token")
else:
logger.info(f"Valid token for health check: {token}")
try:
me = await client.client.get_me()