instances

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2026 License: Apache-2.0 Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Constants

This section is empty.

Variables

View Source
var ErrUnknownInstance = errors.New("instances: unknown instance")

ErrUnknownInstance is returned when a context selects an instance the resolver does not serve.

Functions

func Current

func Current(ctx context.Context) string

Current returns the instance id selected on ctx.

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

type PoolFunc func(context.Context) (*pgxpool.Pool, error)

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 New

func New(cfg Config) (*Registry, error)

New builds a Registry over a resolver.

func (*Registry) Engine

func (r *Registry) Engine(ctx context.Context) (*privacy.Engine, error)

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

func (r *Registry) EngineFor(ctx context.Context, id string) (*privacy.Engine, error)

EngineFor returns an explicit instance's compliance engine.

func (*Registry) KMS

func (r *Registry) KMS(ctx context.Context) (ports.KMS, error)

KMS resolves the KMS of the instance selected on ctx.

func (*Registry) KMSFor

func (r *Registry) KMSFor(ctx context.Context, id string) (ports.KMS, error)

KMSFor resolves an explicit instance's KMS.

func (*Registry) List

func (r *Registry) List(ctx context.Context) ([]string, error)

List enumerates the known instance ids.

func (*Registry) PIIFields

func (r *Registry) PIIFields(ctx context.Context) ([]byte, error)

PIIFields resolves the fixed PII field definitions of the instance on ctx.

func (*Registry) PolicyYAML

func (r *Registry) PolicyYAML(ctx context.Context) ([]byte, error)

PolicyYAML resolves the compliance policy document of the instance on ctx.

func (*Registry) Pool

func (r *Registry) Pool(ctx context.Context) (*pgxpool.Pool, error)

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

func (r *Registry) PoolFor(ctx context.Context, id string) (*pgxpool.Pool, error)

PoolFor resolves an explicit instance's pool.

func (*Registry) PrivacyService

func (r *Registry) PrivacyService(ctx context.Context) (privacy.Service, error)

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.

func (*StaticResolver) KMS

func (s *StaticResolver) KMS(_ context.Context, instanceID string) (ports.KMS, error)

func (*StaticResolver) List

func (s *StaticResolver) List(context.Context) ([]string, error)

func (*StaticResolver) PIIFields

func (s *StaticResolver) PIIFields(_ context.Context, instanceID string) ([]byte, error)

func (*StaticResolver) PolicyYAML

func (s *StaticResolver) PolicyYAML(_ context.Context, instanceID string) ([]byte, error)

func (*StaticResolver) Pool

func (s *StaticResolver) Pool(_ context.Context, instanceID string) (*pgxpool.Pool, error)

Jump to

Keyboard shortcuts

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