MCPcopy
hub / github.com/grafana/dskit / TenantID

Function TenantID

tenant/resolver.go:24–42  ·  view source on GitHub ↗

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. If the org

(ctx context.Context)

Source from the content-addressed store, hash-verified

22//
23//nolint:revive
24func TenantID(ctx context.Context) (string, error) {
25 //lint:ignore faillint wrapper around upstream method
26 orgIDs, err := user.ExtractOrgID(ctx)
27 if err != nil {
28 return "", err
29 }
30 orgID, remaining, hasMoreIDs := stringsCut(orgIDs, tenantIDsSeparator)
31 tenantID := TrimMetadata(orgID)
32 if err := ValidTenantID(tenantID); err != nil {
33 return "", err
34 }
35 for hasMoreIDs {
36 orgID, remaining, hasMoreIDs = stringsCut(remaining, tenantIDsSeparator)
37 if tenantID != TrimMetadata(orgID) {
38 return "", user.ErrTooManyOrgIDs
39 }
40 }
41 return tenantID, nil
42}
43
44// TenantIDs returns all tenant IDs from the context. It should return
45// normalized list of ordered and distinct tenant IDs (as produced by

Callers 4

TestTenantIDsFunction · 0.85
TenantIDMethod · 0.85
BenchmarkTenantIDFunction · 0.85

Calls 4

ExtractOrgIDFunction · 0.92
stringsCutFunction · 0.85
TrimMetadataFunction · 0.85
ValidTenantIDFunction · 0.85

Tested by 2

TestTenantIDsFunction · 0.68
BenchmarkTenantIDFunction · 0.68