qfa.api.dependencies#
FastAPI dependency functions for authentication and service injection.
Functions
|
Validate a Bearer token from the Authorization header. |
|
Build a FastAPI dependency that enters |
|
Return the analyze service from app state. |
|
Return the auth orchestrator from app state. |
|
Return the coding service from app state. |
|
Return the sensitivity-detection service from app state. |
|
Return the summarisation service from app state. |
|
Return the usage repository from app state. |
|
FastAPI dependency that authenticates and checks superuser status. |
- qfa.api.dependencies.get_sensitivity_service(request: Request) SensitivityService[source]#
Return the sensitivity-detection service from app state.
One provider per use-case service (ADR-017): the detect-sensitive handler depends on this service alone, not on the type that reaches every use case.
- Parameters:
request (Request) – The incoming HTTP request.
- Returns:
The sensitivity-detection service instance.
- Return type:
- qfa.api.dependencies.get_coding_service(request: Request) CodingService[source]#
Return the coding service from app state.
One provider per use-case service, per ADR-017: the assign-codes route annotates against
CodingServicealone, so its dependency surface is readable from the handler signature.- Parameters:
request (Request) – The incoming HTTP request.
- Returns:
The coding service instance.
- Return type:
- qfa.api.dependencies.get_analyze_service(request: Request) AnalyzeService[source]#
Return the analyze service from app state.
One provider per use-case service (ADR-017): the analyze route depends on this rather than on a shared service, so its type signature names exactly the service it uses.
- Parameters:
request (Request) – The incoming HTTP request.
- Returns:
The analyze service instance.
- Return type:
- qfa.api.dependencies.get_summarize_service(request: Request) SummarizeService[source]#
Return the summarisation service from app state.
One provider per use-case service, so each route handler annotates against the single service it actually uses (ADR-017).
- Parameters:
request (Request) – The incoming HTTP request.
- Returns:
The summarisation service instance.
- Return type:
- qfa.api.dependencies.get_auth_orchestrator(request: Request) AuthOrchestrator[source]#
Return the auth orchestrator from app state.
- Parameters:
request (Request) – The incoming HTTP request.
- Returns:
The auth orchestrator service instance.
- Return type:
- qfa.api.dependencies.get_usage_repo(request: Request) UsageRepositoryPort[source]#
Return the usage repository from app state.
- Parameters:
request (Request) – The incoming HTTP request.
- Returns:
The usage repository instance.
- Return type:
- 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:
- Raises:
AuthenticationError – If the credentials are missing or invalid.
- qfa.api.dependencies.call_scope_for(operation: Operation) Callable[[...], AsyncIterator[CallContext]][source]#
Build a FastAPI dependency that enters
call_scopeforoperation.The returned dependency reads the authenticated tenant from
authenticate_request(), enterscall_scopefor the duration of the request, and yields the resultingCallContext. It is the driving adapter’s contribution to the cross-adapter correlation bridge: the route declares which operation it represents, and the dependency arranges forcurrent_call_contextto be set before the route body (and the application service beneath it) runs.This is then used for anything that requires the call context, such at usage tracking in
TrackingLLMAdapter.Use inline at the route, e.g.
Depends(call_scope_for(Operation.ANALYZE)). FastAPI evaluates the default value once at module-load time (when the route function is defined), so there’s no per-request cost to inlining.- Parameters:
operation (Operation) – The public use-case operation this dependency represents.
- Returns:
A FastAPI dependency suitable for
Depends(...).- Return type:
Callable[…, AsyncIterator[CallContext]]
- 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:
- Raises:
AuthorizationError – If the tenant is not a superuser.