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 ¶
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).
const ( SourceAdmin = "admin" SourceAuto = "auto" SourceBootstrap = "bootstrap" )
Tenant sources (tenants.source).
const ( LimitMonitors = "maxMonitors" LimitMinInterval = "minIntervalSeconds" LimitChannels = "maxChannels" LimitStatusPages = "maxStatusPages" LimitPrivateProbes = "maxPrivateProbes" )
Limit names as they appear in limits_json.
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 ¶
var ErrInvalidLimits = errors.New("invalid limits")
ErrInvalidLimits is wrapped by every validation error of ParseLimits and ParseOverrides.
Functions ¶
func SanitizeName ¶
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 ¶
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 ¶
ValidName reports whether name is 1 to 100 characters of valid UTF-8 without control characters and without leading or trailing space.
func ValidOrgID ¶
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 ¶
Effective returns the limits of a tenant: each override replaces the plan value, a nil override lifts it.
func ParseLimits ¶
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.
type Overrides ¶
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 ¶
ParseOverrides parses and validates per-tenant overrides. Unlike plan limits, a null value is kept: it lifts the plan limit for the tenant.