qfa.api.dependencies#

FastAPI dependency functions for authentication and service injection.

Functions

authenticate_request(request, credentials)

Validate a Bearer token from the Authorization header.

get_orchestrator(request)

Return the orchestrator from app state.

get_usage_repo(request)

Return the usage repository from app state, or raise 503 if disabled.

require_superuser(tenant)

FastAPI dependency that authenticates and checks superuser status.

qfa.api.dependencies.get_orchestrator(request: Request) Orchestrator[source]#

Return the orchestrator from app state.

Parameters:

request (Request) – The incoming HTTP request.

Returns:

The orchestrator service instance.

Return type:

Orchestrator

qfa.api.dependencies.get_usage_repo(request: Request) UsageRepositoryPort[source]#

Return the usage repository from app state, or raise 503 if disabled.

Parameters:

request (Request) – The incoming HTTP request.

Returns:

The usage repository instance.

Return type:

UsageRepositoryPort

Raises:

HTTPException – 503 if usage tracking is not enabled.

async qfa.api.dependencies.authenticate_request(request: Request, credentials: HTTPAuthorizationCredentials = Security(dependency=<fastapi.security.http.HTTPBearer object>, use_cache=True, scope=None, scopes=None)) TenantApiKey[source]#

Validate a Bearer token from the Authorization header.

Parameters:
  • request (Request) – The incoming HTTP request.

  • credentials (HTTPAuthorizationCredentials) – The parsed Authorization header credentials.

Returns:

The authenticated tenant API key.

Return type:

TenantApiKey

Raises:

AuthenticationError – If the credentials are missing or invalid.

qfa.api.dependencies.require_superuser(tenant: TenantApiKey = Depends(dependency=<function authenticate_request>, use_cache=True, scope=None)) TenantApiKey[source]#

FastAPI dependency that authenticates and checks superuser status.

Parameters:

tenant (TenantApiKey) – The authenticated tenant (injected by authenticate_request).

Returns:

The authenticated superuser tenant.

Return type:

TenantApiKey

Raises:

AuthorizationError – If the tenant is not a superuser.