Documentation
¶
Overview ¶
Package tenant carries the tenant identity on context.Context and is the single structural enforcement point for fabriq's tenancy invariant.
Only auth middleware stamps tenants (from validated claims — never from forwarded headers). Every fabriq entry point calls Require and fails with ErrNoTenant on an unstamped context. Tenant IDs are validated at stamp time so that every name derived from them (graph names, index names, stream keys, cache prefixes) is safe by construction.
Index ¶
- Variables
- func FromContext(ctx context.Context) (string, error)
- func MustWithScope(ctx context.Context, scope string) context.Context
- func MustWithTenant(ctx context.Context, id string) context.Context
- func Require(ctx context.Context) (string, error)
- func ScopeFromContext(ctx context.Context) (string, bool)
- func ScopeOrEmpty(ctx context.Context) string
- func Valid(id string) bool
- func WithScope(ctx context.Context, scope string) (context.Context, error)
- func WithTenant(ctx context.Context, id string) (context.Context, error)
Constants ¶
This section is empty.
Variables ¶
var ErrNoTenant = errors.New("fabriq: no tenant in context")
ErrNoTenant is the canonical "unstamped context" error. The root fabriq package aliases it as fabriq.ErrNoTenant.
var ErrTenantHookTripped = errors.New("fabriq: tenant guard tripped")
ErrTenantHookTripped is returned by the relational backstop hook when a query reaches an engine without a tenant predicate. Aliased at root.
Functions ¶
func FromContext ¶
FromContext returns the tenant stamped on ctx, or ErrNoTenant.
func MustWithScope ¶
MustWithScope is WithScope for wiring code with static ids; it panics on invalid input.
func MustWithTenant ¶
MustWithTenant is WithTenant for wiring code with static ids; it panics on invalid input.
func Require ¶
Require asserts that ctx is tenant-stamped and returns the tenant id. It is FromContext under the guard's name: fabric entry points call Require so call sites read as the structural assertions they are.
func ScopeFromContext ¶
ScopeFromContext returns the scope stamped on ctx and ok=false when the context is unscoped. Unlike tenant, scope is optional — absence is legal.
func ScopeOrEmpty ¶
ScopeOrEmpty returns the scope stamped on ctx, or "" when unscoped. Use this for SET LOCAL app.scope_id and SQL arguments (empty = "see all in tenant").
Types ¶
This section is empty.