bootstrap

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2026 License: MIT Imports: 32 Imported by: 0

Documentation

Overview

Package bootstrap loads configuration and assembles the application: it resolves secret placeholders, opens the database provider, converts config entities to the core entity model, and wires the registry, authorizer, cost gate, engine, and tools. It is the only place that imports gopkg.in/yaml.v3 and x/providers.

Index

Constants

This section is empty.

Variables

View Source
var ErrRuntimeClosed = errors.New("bootstrap: runtime closed")

ErrRuntimeClosed is returned when a closed runtime is used.

ErrUnsupportedDriver is returned for a driver with no provider yet.

Functions

func Load

func Load(path string) (*config.Config, error)

Load reads and validates a YAML config file.

func RedactDSN

func RedactDSN(dsn string) string

RedactDSN returns dsn with any password replaced by ***, for safe logging. It handles PostgreSQL URI form (scheme://user:pass@host) and MySQL DSN form (user:pass@tcp(host)); DSNs without a password are returned unchanged.

func ValidateFile

func ValidateFile(path string, resolver SecretResolver) error

ValidateFile parses, defaults, validates, and resolves secrets without opening database connections.

Types

type App

type App struct {
	Provider                   Provider
	Providers                  map[string]Provider
	Prepared                   map[string]*store.PreparedDB
	Sources                    map[string]tool.DataSource
	Dialect                    dialect.Dialect
	Registry                   *entity.Registry
	Authorizer                 rbac.Authorizer
	Masker                     mask.Masker
	Gate                       cost.Gate
	Engine                     *engine.Engine
	Tools                      *tool.Registry
	ToolFlags                  config.ToolFlags
	DefaultRole                string
	QueryTimeout               time.Duration
	MaxRows                    int64
	MaxProcedureRows           int64
	MaxReturnedBytes           int64
	MaxINListSize              int
	MaxFilterConditions        int
	MaxGroupByFields           int
	MaxAggregates              int
	MaxExpand                  int
	CacheMaxEntryRows          int
	CacheMaxEntryBytes         int64
	TransactionBeginTimeout    time.Duration
	TransactionCommitTimeout   time.Duration
	TransactionRollbackTimeout time.Duration
	Auditor                    audit.Auditor
	Hooks                      *hook.Hooks
	Cache                      cache.Cache[[]map[string]any]
	Feedback                   cost.FeedbackStore
	Analyze                    cost.AnalyzePolicy
	Budget                     budget.Manager
	Transactions               *tool.TransactionManager
	TxBeginners                map[string]store.TxBeginner
	// contains filtered or unexported fields
}

App is the assembled application, ready to serve.

func Assemble

func Assemble(cfg *config.Config) (*App, error)

Assemble opens the provider and wires the application from cfg, using the default EnvFileResolver for secret placeholders.

func AssembleWithProvider

func AssembleWithProvider(cfg *config.Config, prov Provider) (*App, error)

AssembleWithProvider wires the application using an injected provider (for testing with fakes).

func AssembleWithProviders

func AssembleWithProviders(cfg *config.Config, providers map[string]Provider) (*App, error)

AssembleWithProviders wires named providers. It is intended for tests and embedders; ownership transfers to the returned App on success.

func AssembleWithResolver

func AssembleWithResolver(cfg *config.Config, r SecretResolver) (*App, error)

AssembleWithResolver resolves secrets with the given resolver, opens the provider, and wires the application. Use a custom resolver to integrate secret managers (Vault, AWS Secrets Manager, etc.) without coupling core to any specific backend.

func (*App) Close

func (a *App) Close() error

Close preserves the original unbounded close contract. Callers that need a shutdown deadline should use CloseContext.

func (*App) CloseContext

func (a *App) CloseContext(ctx context.Context) error

CloseContext stops engine admission and drains all execution before rolling back transactions and releasing audit/provider resources.

func (*App) Ping added in v0.1.6

func (a *App) Ping(ctx context.Context) error

Ping verifies every configured database is reachable. It backs the /readyz/db readiness probe and stays off the tool execution path: it uses the provider's native connection ping when exposed and falls back to a trivial query otherwise.

func (*App) ToolContext

func (a *App) ToolContext(role string) tool.Context

ToolContext builds a per-request tool.Context for the given role.

func (*App) ToolContextForSubject

func (a *App) ToolContextForSubject(role string, subject map[string]any) tool.Context

ToolContextForSubject builds a per-request tool.Context for a role plus subject attributes (referenced by row-level ${subject.x} policies).

type EnvFileResolver

type EnvFileResolver struct {
	AllowedRoots []string
}

EnvFileResolver resolves ${ENV} (environment variables) and ${file:/path} (file contents, e.g. Kubernetes Secret volume mounts).

func (EnvFileResolver) Resolve

func (r EnvFileResolver) Resolve(s string) (string, error)

Resolve implements SecretResolver.

type Provider

type Provider = coreprovider.Provider

Provider aggregates the core interfaces a database adapter must satisfy.

type Runtime

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

Runtime owns the atomically replaceable App snapshot used by serving handlers. A successful reload publishes the new App before draining and closing the old one; a failed build leaves the current App untouched.

func NewRuntime

func NewRuntime(app *App) *Runtime

NewRuntime creates a runtime using Load followed by Assemble for reloads.

func NewRuntimeWithBuilder

func NewRuntimeWithBuilder(app *App, build func(string) (*App, error)) *Runtime

NewRuntimeWithBuilder creates a runtime with an injected reload builder. It is useful for embedders and tests that assemble providers themselves.

func (*Runtime) Acquire

func (r *Runtime) Acquire() (*App, func(), error)

Acquire leases the current snapshot until the returned release function is called. It retries when racing with retirement.

func (*Runtime) Close

func (r *Runtime) Close() error

Close stops new acquisitions, drains leases, and closes the current App.

func (*Runtime) Current

func (r *Runtime) Current() *App

Current returns the currently published App, or nil after Close. Handlers that execute work must use Acquire so the App cannot close during the call.

func (*Runtime) DatabasesReady added in v0.1.6

func (r *Runtime) DatabasesReady(ctx context.Context) error

DatabasesReady pings every database of the current snapshot. It backs the /readyz/db readiness probe.

func (*Runtime) Reload

func (r *Runtime) Reload(path string) error

Reload performs parse/default/validate/secret-resolution/assembly before atomically publishing the new App. Build failure preserves the old snapshot.

func (*Runtime) RollbackSession

func (r *Runtime) RollbackSession(session string)

RollbackSession rolls back transactions associated with a disconnected MCP session when the transport exposes a stable non-empty session ID.

func (*Runtime) SnapshotReady added in v0.1.6

func (r *Runtime) SnapshotReady(context.Context) error

SnapshotReady reports whether a configuration snapshot is currently published and servable. It backs the /readyz/snapshot readiness probe.

func (*Runtime) Watch

func (r *Runtime) Watch(ctx context.Context, path string, interval time.Duration, onError func(error)) error

Watch polls path for content changes and reloads it. Reload errors are reported through onError and do not stop the watcher or replace the old App.

type SecretResolver

type SecretResolver interface {
	Resolve(s string) (string, error)
}

SecretResolver resolves ${...} placeholders in a string (e.g. a DSN). EnvFileResolver is the built-in implementation; custom implementations can back this by Vault, AWS Secrets Manager, GCP Secret Manager, etc., without coupling core to any specific backend.

Jump to

Keyboard shortcuts

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