ontocast.api.tenancy_resolution¶
Shared HTTP request tenancy resolution for API routes.
Attributes¶
Classes¶
Functions:¶
apply_request_tenancy(request, tools, *, active_tenant, active_project, initialize_vector_store)
async
¶
Resolve tenant/project and return the ToolBox that serves that partition.
If tenant or project appears in the query string, resolve with
defaults and hand back a ToolBox bound to that scope; otherwise return the
startup ToolBox and the active_* scope unchanged.
This used to retarget the shared ToolBox in place, so every request
mutated process-wide state -- dataset names, collection names, the ontology
catalog -- behind a single lock that serialized all multi-tenant traffic.
Now each scope owns a ToolBox (over a deep-copied Config, sharing the
expensive runtime), so isolation is structural and different tenants run
concurrently.
Returns:
| Type | Description |
|---|---|
ToolBox
|
|
str
|
passed in, for everything downstream of this call. |
Source code in ontocast/api/tenancy_resolution.py
make_scoped_toolbox_resolver(tools, *, active_tenant, active_project, server_config)
¶
Build the per-request ToolBox resolver a sub-router depends on.
Every router that serves tenant-scoped data needs the same dependency:
resolve this request's tenant/project partition and hand the handler the
ToolBox that serves it, because with per-scope ToolBoxes the enclosing
tools is the wrong one whenever the client passes ?tenant= or
?project=. The /ontologies and /shapes routers each carried a
byte-identical copy of that closure, differing only in its name.
Vector-store initialization is decided once here, from the configured ontology context mode, for the same reason: both copies computed it and a third router would have computed it again.
Source code in ontocast/api/tenancy_resolution.py
request_has_tenancy_query_params(request)
¶
resolve_tenant_project(tenant, project)
¶
Apply defaults to a requested tenant/project and strip both.
Raises:
| Type | Description |
|---|---|
RequestParamError
|
A value was given but is blank after stripping. |
Source code in ontocast/api/tenancy_resolution.py
stores_use_tenancy_partitions(tools)
¶
True when triple store and/or Qdrant should be retargeted for tenant/project.