MCPcopy Create free account
hub / github.com/Roy3838/Observer / get_admin_access

Function get_admin_access

api/admin_auth.py:14–31  ·  view source on GitHub ↗

Dependency that checks for a valid admin API key in the X-Admin-Key header.

(key: str = Security(api_key_header))

Source from the content-addressed store, hash-verified

12api_key_header = APIKeyHeader(name="X-Admin-Key", auto_error=False)
13
14async 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 )

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected