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)
| 22 | // |
| 23 | //nolint:revive |
| 24 | func 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 |