Add token-based authentication to health check endpoint
This commit is contained in:
+9
-2
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user