18 lines
562 B
Python
18 lines
562 B
Python
"""Security helpers for high-power operational endpoints."""
|
|
from __future__ import annotations
|
|
|
|
from fastapi import Header, HTTPException
|
|
|
|
from .config import ADMIN_TOKEN
|
|
|
|
|
|
def require_admin_token(x_admin_token: str | None = Header(default=None, alias="X-Admin-Token")) -> None:
|
|
"""Require the configured admin token when ADMIN_TOKEN is set.
|
|
|
|
In development (no ADMIN_TOKEN configured), this is a no-op.
|
|
"""
|
|
if not ADMIN_TOKEN:
|
|
return
|
|
if x_admin_token != ADMIN_TOKEN:
|
|
raise HTTPException(status_code=403, detail="Forbidden")
|