tenant

package
v1.18.1 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2024 License: Apache-2.0 Imports: 7 Imported by: 11

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractTenantIDFromHTTPRequest

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

ExtractTenantIDFromHTTPRequest extracts a single TenantID through a given resolver directly from a HTTP request.

func JoinTenantIDs added in v1.7.0

func JoinTenantIDs(tenantIDs []string) string

func NormalizeTenantIDs

func NormalizeTenantIDs(tenantIDs []string) []string

NormalizeTenantIDs is creating a normalized form by sortiing 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 added in v1.7.0

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

func WithDefaultResolver

func WithDefaultResolver(r Resolver)

WithDefaultResolver updates the resolver used for the package methods.

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://cortexmetrics.io/docs/guides/limitations/#tenant-id-naming)

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)
}

type SingleResolver

type SingleResolver struct {
}

func NewSingleResolver

func NewSingleResolver() *SingleResolver

NewSingleResolver creates a tenant resolver, which restricts all requests to be using a single tenant only. This allows a wider set of characters to be used within the tenant ID and should not impose a breaking change.

func (*SingleResolver) TenantID

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

func (*SingleResolver) TenantIDs

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

Jump to

Keyboard shortcuts

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