Dependency that checks for a valid admin API key in the X-Admin-Key header.
(key: str = Security(api_key_header))
| 12 | api_key_header = APIKeyHeader(name="X-Admin-Key", auto_error=False) |
| 13 | |
| 14 | async def get_admin_access(key: str = Security(api_key_header)): |
| 15 | """ |
| 16 | Dependency that checks for a valid admin API key in the X-Admin-Key header. |
| 17 | """ |
| 18 | if not ADMIN_API_KEY: |
| 19 | # This is a server configuration error, not a client error. |
| 20 | raise HTTPException( |
| 21 | status_code=500, detail="Admin API key is not configured on the server." |
| 22 | ) |
| 23 | |
| 24 | if key and hmac.compare_digest(key, ADMIN_API_KEY): |
| 25 | # If the key is present and correct, allow access. |
| 26 | return True |
| 27 | else: |
| 28 | # Otherwise, deny access. |
| 29 | raise HTTPException( |
| 30 | status_code=403, detail="You are not authorized to access this resource." |
| 31 | ) |
nothing calls this directly
no outgoing calls
no test coverage detected