override

package
v1.8.2 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package override provides per-tenant config override entities and store interface.

Index

Constants

View Source
const (
	// ContextKeyTenantID is the context key for tenant ID (matches flag.ContextKeyTenantID).
	ContextKeyTenantID contextKey = "vault.tenant_id"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ListOpts

type ListOpts struct {
	Limit  int
	Offset int
}

ListOpts configures list queries for overrides.

type Override

type Override struct {
	core.Entity
	ID       id.ID             `json:"id"`
	Key      string            `json:"key"`
	Value    any               `json:"value"`
	AppID    string            `json:"app_id"`
	TenantID string            `json:"tenant_id"`
	Metadata map[string]string `json:"metadata,omitempty"`
}

Override represents a per-tenant override for a config entry.

type Resolver

type Resolver struct {
	// contains filtered or unexported fields
}

Resolver resolves config values with per-tenant override support.

Resolution order:

  1. If tenant ID is present in context, look up tenant override → use if found.
  2. Fall back to app-level config value.
  3. Cache results when a cache TTL is configured.

func NewResolver

func NewResolver(configStore config.Store, overrideStore Store, opts ...ResolverOption) *Resolver

NewResolver creates a config resolver with override support.

func (*Resolver) Invalidate

func (r *Resolver) Invalidate(key, appID string)

Invalidate removes cached entries for a specific config key and app ID.

func (*Resolver) InvalidateAll

func (r *Resolver) InvalidateAll()

InvalidateAll removes all cached entries.

func (*Resolver) Resolve

func (r *Resolver) Resolve(ctx context.Context, key, appID string) (any, error)

Resolve returns the effective value for a config key and app ID.

It extracts the tenant ID from the context and checks for a tenant override first. If no override is found or there is no tenant context, it returns the app-level config value.

type ResolverOption

type ResolverOption func(*Resolver)

ResolverOption configures the Resolver.

func WithCacheTTL

func WithCacheTTL(ttl time.Duration) ResolverOption

WithCacheTTL enables result caching with the given TTL.

func WithLogger

func WithLogger(l log.Logger) ResolverOption

WithLogger sets the logger for the resolver.

type Store

type Store interface {
	// GetOverride retrieves a tenant override by key, app ID, and tenant ID.
	GetOverride(ctx context.Context, key, appID, tenantID string) (*Override, error)

	// SetOverride creates or updates a tenant override.
	SetOverride(ctx context.Context, o *Override) error

	// DeleteOverride removes a tenant override.
	DeleteOverride(ctx context.Context, key, appID, tenantID string) error

	// ListOverridesByTenant returns all overrides for a specific tenant.
	ListOverridesByTenant(ctx context.Context, appID, tenantID string) ([]*Override, error)

	// ListOverridesByKey returns all tenant overrides for a specific config key.
	ListOverridesByKey(ctx context.Context, key, appID string) ([]*Override, error)

	// CountOverrides returns the total number of tenant overrides for an app,
	// across every key and tenant.
	CountOverrides(ctx context.Context, appID string) (int64, error)
}

Store defines the persistence interface for per-tenant overrides.

Jump to

Keyboard shortcuts

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