Documentation
¶
Overview ¶
Package instances resolves the per-request Dilion instance.
An "instance" is a fully isolated database (auth.* + dilion_*), a scope larger than a tenant/project. Multi-instance operation is an embedder customisation (ports.InstanceResolver + dilion.WithInstanceResolver): the built-in daemon and every example run a single instance under ports.DefaultInstanceID, served by StaticResolver, and behave exactly as they did before instances existed.
Instance selection is entirely the embedder's business: there is no built-in HTTP routing and no token↔instance binding. The embedder puts the instance id on the context with ports.ContextWithInstance (typically in its own middleware) and every Dilion component below resolves its resources from that context through a Registry.
Caching: constructed per-instance objects (today: the privacy Engine) are cached by instance id and never invalidated. A resolver must therefore return stable results for a given id — changing the pool, KMS, policy or PII field definitions behind an id requires a restart.
Index ¶
- Variables
- func Current(ctx context.Context) string
- type Config
- type PoolFunc
- type Registry
- func (r *Registry) Engine(ctx context.Context) (*privacy.Engine, error)
- func (r *Registry) EngineFor(ctx context.Context, id string) (*privacy.Engine, error)
- func (r *Registry) KMS(ctx context.Context) (ports.KMS, error)
- func (r *Registry) KMSFor(ctx context.Context, id string) (ports.KMS, error)
- func (r *Registry) List(ctx context.Context) ([]string, error)
- func (r *Registry) PIIFields(ctx context.Context) ([]byte, error)
- func (r *Registry) PolicyYAML(ctx context.Context) ([]byte, error)
- func (r *Registry) Pool(ctx context.Context) (*pgxpool.Pool, error)
- func (r *Registry) PoolFor(ctx context.Context, id string) (*pgxpool.Pool, error)
- func (r *Registry) PrivacyService(ctx context.Context) (privacy.Service, error)
- func (r *Registry) Resolver() ports.InstanceResolver
- type StaticResolver
- func (s *StaticResolver) ID() string
- func (s *StaticResolver) KMS(_ context.Context, instanceID string) (ports.KMS, error)
- func (s *StaticResolver) List(context.Context) ([]string, error)
- func (s *StaticResolver) PIIFields(_ context.Context, instanceID string) ([]byte, error)
- func (s *StaticResolver) PolicyYAML(_ context.Context, instanceID string) ([]byte, error)
- func (s *StaticResolver) Pool(_ context.Context, instanceID string) (*pgxpool.Pool, error)
Constants ¶
This section is empty.
Variables ¶
var ErrUnknownInstance = errors.New("instances: unknown instance")
ErrUnknownInstance is returned when a context selects an instance the resolver does not serve.
Functions ¶
Types ¶
type Config ¶
type Config struct {
Resolver ports.InstanceResolver
// Hooks, Clock, Connectors and TombstoneKey are deployment-wide and shared
// by every instance's privacy Engine.
Hooks *hooks.Registry
Clock ports.Clock
Connectors map[string]ports.Connector
TombstoneKey []byte
Logger *slog.Logger
}
Config are the cross-instance dependencies of the Registry. Everything instance-specific (pool, KMS, policy, PII field definitions) comes from the resolver instead.
type PoolFunc ¶
PoolFunc resolves the database pool of the instance selected on ctx. It is the narrow dependency the request-path packages (auth, api, iam, audit) take instead of a fixed *pgxpool.Pool.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry resolves instance resources from a context and owns the lazily constructed per-instance objects.
func (*Registry) Engine ¶
Engine returns the compliance engine of the instance selected on ctx, constructing it on first use. Engines are cached per instance id forever.
func (*Registry) PIIFields ¶
PIIFields resolves the fixed PII field definitions of the instance on ctx.
func (*Registry) PolicyYAML ¶
PolicyYAML resolves the compliance policy document of the instance on ctx.
func (*Registry) Pool ¶
Pool resolves the pool of the instance selected on ctx. Its signature is PoolFunc, so it can be handed straight to auth/api/iam/audit.
func (*Registry) PrivacyService ¶
PrivacyService is the api.ServiceProvider form of Engine.
func (*Registry) Resolver ¶
func (r *Registry) Resolver() ports.InstanceResolver
Resolver exposes the underlying resolver.
type StaticResolver ¶
type StaticResolver struct {
// contains filtered or unexported fields
}
StaticResolver is a ports.InstanceResolver over one fixed set of resources. It backs the single-instance default: WithPool/WithDSN, WithKMS, WithPolicyYAML and WithPIIFieldsYAML are wrapped under ports.DefaultInstanceID.
func NewStaticResolver ¶
func NewStaticResolver(id string, pool *pgxpool.Pool, kms ports.KMS, policyYAML, piiFieldsYAML []byte) *StaticResolver
NewStaticResolver builds a resolver serving exactly one instance id. An empty id defaults to ports.DefaultInstanceID. policyYAML and piiFieldsYAML may be nil (built-in policies / free-form PII fields).
func (*StaticResolver) ID ¶
func (s *StaticResolver) ID() string
ID is the single instance id this resolver serves.