tenant

package
v0.0.0-...-c73f165 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2024 License: Apache-2.0 Imports: 7 Imported by: 159

Documentation

Index

Constants

View Source
const (
	// MaxTenantIDLength is the max length of single tenant ID in bytes
	MaxTenantIDLength = 150
)

Variables

This section is empty.

Functions

func ExtractTenantIDFromHTTPRequest

func ExtractTenantIDFromHTTPRequest(req *http.Request) (string, context.Context, error)

ExtractTenantIDFromHTTPRequest extracts a single tenant ID directly from a HTTP request.

func JoinTenantIDs

func JoinTenantIDs(tenantIDs []string) string

JoinTenantIDs returns all tenant IDs concatenated with the separator character `|`

func NormalizeTenantIDs

func NormalizeTenantIDs(tenantIDs []string) []string

NormalizeTenantIDs creates a normalized form by sorting and de-duplicating the list of tenantIDs

func TenantID

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

TenantID returns exactly a single tenant ID from the context. It should be used when a certain endpoint should only support exactly a single tenant ID. It returns an error user.ErrNoOrgID if there is no tenant ID supplied or user.ErrTooManyOrgIDs if there are multiple tenant IDs present.

ignore stutter warning

func TenantIDs

func TenantIDs(ctx context.Context) ([]string, error)

TenantIDs returns all tenant IDs from the context. It should return normalized list of ordered and distinct tenant IDs (as produced by NormalizeTenantIDs).

ignore stutter warning

func TenantIDsFromOrgID

func TenantIDsFromOrgID(orgID string) ([]string, error)

TenantIDsFromOrgID extracts different tenants from an orgID string value

ignore stutter warning

func ValidTenantID

func ValidTenantID(s string) error

ValidTenantID returns an error if the single tenant ID is invalid, nil otherwise

Types

type MultiResolver

type MultiResolver struct{}

func NewMultiResolver

func NewMultiResolver() *MultiResolver

NewMultiResolver creates a tenant resolver, which allows request to have multiple tenant ids submitted separated by a '|' character. This enforces further limits on the character set allowed within tenants as detailed here: https://grafana.com/docs/mimir/latest/configure/about-tenant-ids/

func (*MultiResolver) TenantID

func (t *MultiResolver) TenantID(ctx context.Context) (string, error)

func (*MultiResolver) TenantIDs

func (t *MultiResolver) TenantIDs(ctx context.Context) ([]string, error)

type Resolver

type Resolver interface {
	// TenantID returns exactly a single tenant ID from the context. It should be
	// used when a certain endpoint should only support exactly a single
	// tenant ID. It returns an error user.ErrNoOrgID if there is no tenant ID
	// supplied or user.ErrTooManyOrgIDs if there are multiple tenant IDs present.
	TenantID(context.Context) (string, error)

	// TenantIDs returns all tenant IDs from the context. It should return
	// normalized list of ordered and distinct tenant IDs (as produced by
	// NormalizeTenantIDs).
	TenantIDs(context.Context) ([]string, error)
}

Jump to

Keyboard shortcuts

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