tenant

package
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 21, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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.

View Source
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

func FromContext(ctx context.Context) (string, error)

FromContext returns the tenant stamped on ctx, or ErrNoTenant.

func MustWithScope

func MustWithScope(ctx context.Context, scope string) context.Context

MustWithScope is WithScope for wiring code with static ids; it panics on invalid input.

func MustWithTenant

func MustWithTenant(ctx context.Context, id string) context.Context

MustWithTenant is WithTenant for wiring code with static ids; it panics on invalid input.

func Require

func Require(ctx context.Context) (string, error)

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

func ScopeFromContext(ctx context.Context) (string, bool)

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

func ScopeOrEmpty(ctx context.Context) string

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").

func Valid

func Valid(id string) bool

Valid reports whether id is a well-formed tenant identifier.

func WithScope

func WithScope(ctx context.Context, scope string) (context.Context, error)

WithScope returns a context stamped with an optional secondary scope, or an error if the scope is not a well-formed identifier. Scope is OPTIONAL: an unscoped context reads everything in the tenant; a scoped context reads its own scope plus shared (NULL-scope) rows.

func WithTenant

func WithTenant(ctx context.Context, id string) (context.Context, error)

WithTenant returns a context stamped with the tenant id, or an error if the id is not a well-formed tenant identifier.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL