pub struct RlsContext {
pub tenant_id: String,
pub operator_id: String,
pub agent_id: String,
/* private fields */
}Expand description
RLS context carrying tenant identity for data isolation.
Fields§
§tenant_id: StringThe unified tenant ID — the primary identity for data isolation. Empty string means no tenant scope.
operator_id: StringLegacy: The operator (vendor) this context is scoped to. Set to the same value as tenant_id during the transition period.
agent_id: StringLegacy: The agent (reseller) this context is scoped to. Set to the same value as tenant_id during the transition period.
Implementations§
Source§impl RlsContext
impl RlsContext
Sourcepub fn tenant(tenant_id: &str) -> RlsContext
pub fn tenant(tenant_id: &str) -> RlsContext
Create a context scoped to a specific tenant (the unified identity).
Sourcepub fn operator(operator_id: &str) -> RlsContext
pub fn operator(operator_id: &str) -> RlsContext
Create a context scoped to a specific operator.
Legacy — use tenant() for new code.
Sourcepub fn agent(agent_id: &str) -> RlsContext
pub fn agent(agent_id: &str) -> RlsContext
Create a context scoped to a specific agent (reseller).
Legacy — use tenant() for new code.
Sourcepub fn operator_and_agent(operator_id: &str, agent_id: &str) -> RlsContext
pub fn operator_and_agent(operator_id: &str, agent_id: &str) -> RlsContext
Create a context scoped to both operator and agent.
Legacy — use tenant() for new code.
Sourcepub fn super_admin(_token: SuperAdminToken) -> RlsContext
pub fn super_admin(_token: SuperAdminToken) -> RlsContext
Create a super admin context that bypasses tenant isolation.
Requires a SuperAdminToken — which can only be created via
named constructors (for_system_process, for_webhook, for_auth).
Uses nil UUID for all IDs to avoid ''::uuid cast errors
in PostgreSQL RLS policies (PostgreSQL doesn’t short-circuit OR).
Sourcepub fn empty() -> RlsContext
pub fn empty() -> RlsContext
Create an empty context (no tenant, no super admin).
Used for system-level operations that must not operate within any tenant scope (startup introspection, migrations, health checks).
Sourcepub fn has_tenant(&self) -> bool
pub fn has_tenant(&self) -> bool
Returns true if this context has a tenant scope.
Sourcepub fn has_operator(&self) -> bool
pub fn has_operator(&self) -> bool
Returns true if this context has an operator scope.
Sourcepub fn bypasses_rls(&self) -> bool
pub fn bypasses_rls(&self) -> bool
Returns true if this context bypasses tenant isolation.
Trait Implementations§
Source§impl Clone for RlsContext
impl Clone for RlsContext
Source§fn clone(&self) -> RlsContext
fn clone(&self) -> RlsContext
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more