Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ScopeClause ¶
ScopeClause returns the JSONB containment predicate and its bound arguments for the caller resolved from ctx: empty clause with nil args for system callers and requests with no resolved tenant (unscoped); "1 = 0" with nil args for non-system callers with no dimensions (fail-closed, see below); or the containment clause with one bound argument for a resolved tenant. Callers must spread args (e.g. db.Where(clause, args...)) rather than assume exactly one value.
func ScopeDB ¶
ScopeDB applies ScopeClause to db as a WHERE clause, for callers using GORM's query builder instead of raw SQL.
func TenancyJSON ¶
TenancyJSON returns the caller's tenancy map as JSONB for storage on created resources. System and unscoped/absent callers get an empty map, which no tenant-scoped query can ever match.
func WithTenant ¶
func WithTenant(ctx context.Context, t *ResolvedTenant) context.Context
WithTenant attaches a resolved tenant identity to the context.
Types ¶
type ResolvedTenant ¶
ResolvedTenant holds the tenant identity resolved from gateway-injected request headers.
func FromContext ¶
func FromContext(ctx context.Context) *ResolvedTenant
FromContext returns the tenant identity attached to ctx, or nil if none was resolved.
type Resolver ¶
Resolver resolves the caller's tenant context from trusted gateway-injected request headers and fails closed when required identity is missing.
func NewResolver ¶
func NewResolver(cfg config.TenantConfig) Resolver
NewResolver returns a tenant enforcement Resolver configured from cfg. Callers decide whether to mount it based on cfg.Enabled; the resolver itself does not check it.