tenant

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2026 License: Apache-2.0 Imports: 13 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ScopeClause

func ScopeClause(ctx context.Context) (clause string, args []any)

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

func ScopeDB(db *gorm.DB, ctx context.Context) *gorm.DB

ScopeDB applies ScopeClause to db as a WHERE clause, for callers using GORM's query builder instead of raw SQL.

func TenancyJSON

func TenancyJSON(ctx context.Context) datatypes.JSON

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

type ResolvedTenant struct {
	Dimensions map[string]string
	System     bool
}

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

type Resolver interface {
	ResolveTenant(next http.Handler) http.Handler
}

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.

Jump to

Keyboard shortcuts

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