tenant

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0 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

Overview

Package tenant holds the rules for tenants, plans and their limits (ADR 0029). It has no I/O, so the Raft FSM and the API use the same rules.

Index

Constants

View Source
const (
	// SystemTenantID mirrors store.SystemTenantID; it is repeated here so the
	// package stays free of store dependencies.
	SystemTenantID = "_system"
	// DefaultTenantID is the tenant created at bootstrap in every auth mode.
	DefaultTenantID = "default"
	// DefaultPlanID is the built-in plan without limits; it cannot be deleted.
	DefaultPlanID = "default"
	// SystemPlanID belongs to the system tenant only; it cannot be changed,
	// deleted or assigned to another tenant.
	SystemPlanID = "system"
)

Reserved IDs (ADR 0025, 0027, 0029).

View Source
const (
	SourceAdmin     = "admin"
	SourceAuto      = "auto"
	SourceBootstrap = "bootstrap"
)

Tenant sources (tenants.source).

View Source
const (
	LimitMonitors      = "maxMonitors"
	LimitMinInterval   = "minIntervalSeconds"
	LimitChannels      = "maxChannels"
	LimitStatusPages   = "maxStatusPages"
	LimitPrivateProbes = "maxPrivateProbes"
)

Limit names as they appear in limits_json.

View Source
const OrgIDRule = "organization ID must be 1 to 128 characters of A-Z, a-z, 0-9, '.', '_', '@' or '-'"

OrgIDRule describes ValidOrgID for error messages.

Variables

View Source
var ErrInvalidLimits = errors.New("invalid limits")

ErrInvalidLimits is wrapped by every validation error of ParseLimits and ParseOverrides.

Functions

func Protected

func Protected(tenantID string) bool

Protected reports whether a tenant may never be suspended or deleted.

func SanitizeName

func SanitizeName(name, fallback string) string

SanitizeName turns an untrusted display name (e.g. an organization name from a token) into a valid tenant name: control and format characters are dropped, white space is collapsed and the result is cut to 100 characters. It returns fallback if nothing usable is left.

func ValidID

func ValidID(id string) bool

ValidID reports whether id is a usable tenant or plan ID: 1 to 64 bytes of lower-case ASCII letters, digits and '-', starting with a letter or digit. UUIDs qualify. Reserved IDs such as "_system" do not.

func ValidName

func ValidName(name string) bool

ValidName reports whether name is 1 to 100 characters of valid UTF-8 without control characters and without leading or trailing space.

func ValidOrgID

func ValidOrgID(id string) bool

ValidOrgID reports whether id is a usable organization ID: 1 to 128 bytes of ASCII letters, digits, '.', '_', '@' and '-' (ADR 0027).

Types

type Limits

type Limits struct {
	MaxMonitors        *int `json:"maxMonitors,omitempty"`
	MinIntervalSeconds *int `json:"minIntervalSeconds,omitempty"`
	MaxChannels        *int `json:"maxChannels,omitempty"`
	MaxStatusPages     *int `json:"maxStatusPages,omitempty"`
	MaxPrivateProbes   *int `json:"maxPrivateProbes,omitempty"`
}

Limits are the limits of a plan. A nil field is unlimited.

func Effective

func Effective(plan Limits, o Overrides) Limits

Effective returns the limits of a tenant: each override replaces the plan value, a nil override lifts it.

func ParseLimits

func ParseLimits(raw []byte) (Limits, error)

ParseLimits parses and validates the limits of a plan. Empty input and null fields mean unlimited. Unknown fields, non-integers and out-of-range values are rejected.

func (Limits) Canonical

func (l Limits) Canonical() []byte

Canonical returns the limits as compact JSON with fields in a fixed order, so that every replica stores the same bytes.

type Overrides

type Overrides map[string]*int

Overrides are per-tenant changes to the plan limits. A name that is absent keeps the plan value; a name mapped to nil lifts the limit for the tenant.

func ParseOverrides

func ParseOverrides(raw []byte) (Overrides, error)

ParseOverrides parses and validates per-tenant overrides. Unlike plan limits, a null value is kept: it lifts the plan limit for the tenant.

func (Overrides) Canonical

func (o Overrides) Canonical() []byte

Canonical returns the overrides as compact JSON with sorted keys. Nil values are kept as null.

Jump to

Keyboard shortcuts

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