settings

package
v0.9.14 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: MIT Imports: 15 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 settings reads backd's runtime configuration from environment variables.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadKeyMaterial

func LoadKeyMaterial(getenv func(string) string, name string) (string, error)

LoadKeyMaterial reads secret key material from the environment variable name, or from the file named by name+"_FILE" (trimmed of surrounding whitespace); the two are mutually exclusive. Returns "" if neither is set. Exported for `backd-server secret rotate-key`, which reads BACKD_SECRETS_NEW_KEY the same way outside of Load.

func LoadMetrics added in v0.4.0

func LoadMetrics(getenv func(string) string, reserved ...string) (addr, token string, err error)

LoadMetrics reads METRICS_ADDR and METRICS_TOKEN, shared by every backd command that can serve /metrics. reserved are the addresses the process serves other things on: metrics must have a listener of their own.

func RealtimeLimitsFrom added in v0.8.5

func RealtimeLimitsFrom(getenv func(string) string) (realtime.Limits, error)

RealtimeLimitsFrom reads the instance's realtime limits: BACKD_REALTIME_MAX_SUBSCRIPTIONS_PER_STREAM, BACKD_REALTIME_MAX_STREAMS_PER_USER, BACKD_REALTIME_MAX_STREAMS, BACKD_REALTIME_BUFFER (bytes per stream), BACKD_REALTIME_MEMORY (bytes for all buffers) and BACKD_REALTIME_HEARTBEAT (a duration).

Types

type ProvisionMode

type ProvisionMode string

ProvisionMode controls what startup provisioning does to MongoDB.

const (
	// ProvisionApply creates missing collections, validators and indexes.
	ProvisionApply ProvisionMode = "apply"
	// ProvisionVerify only compares MongoDB against the config and fails on differences.
	ProvisionVerify ProvisionMode = "verify"
)

type Settings

type Settings struct {
	ConfigDir     string
	MongoURI      string
	HTTPAddr      string
	ProvisionMode ProvisionMode
	LogLevel      slog.Level
	MaxBodyBytes  int64
	// MaxUploadBytes caps one file of a proxy upload (BACKD_MAX_UPLOAD_BYTES), apart from
	// MaxBodyBytes, which is for JSON.
	MaxUploadBytes int64
	// ImageMaxPixels is the most pixels (width × height) an image may have to get
	// versions (BACKD_IMAGE_MAX_PIXELS); a file field may only lower it.
	ImageMaxPixels int64
	// ImageTimeout bounds the making of one image's versions (BACKD_IMAGE_TIMEOUT).
	ImageTimeout time.Duration
	// Expand are the instance's limits for reference expansion (BACKD_EXPAND_MAX_*).
	Expand registry.ExpandLimits
	// Aggregate are the instance's limits for aggregations (BACKD_AGGREGATE_*).
	Aggregate registry.AggregateLimits
	// RateLimit are the instance's request limits (BACKD_RATE_LIMIT*): on unless BACKD_DEV.
	RateLimit registry.RateSettings
	// DeploymentID is BACKD_DEPLOYMENT_ID (default "default"): what keeps the trigger dispatcher
	// of this backd deployment apart from another one's when both share a MongoDB cluster.
	DeploymentID string
	// Env is BACKD_ENV (default empty): what this instance is for, such as development, staging
	// or production. Only imports use it, to warn about data that doesn't belong in it.
	Env string
	// TriggerLimits are the instance's trigger limits (BACKD_TRIGGER_MAX_CHAIN).
	TriggerLimits registry.TriggerLimits
	// Realtime are the instance's realtime limits (BACKD_REALTIME_*); zero fields mean the defaults.
	Realtime realtime.Limits
	// ImageConcurrency is how many images one worker process makes versions of at once
	// (BACKD_IMAGE_CONCURRENCY); 0 derives it from the container's CPU and memory limits.
	ImageConcurrency int
	MongoOpTimeout   time.Duration
	ShutdownTimeout  time.Duration
	// PasswordHashConcurrency caps concurrent password hashes; 0 means
	// auth.DefaultHashConcurrency (CPU and memory limits).
	PasswordHashConcurrency int
	// TrustedProxies are networks whose X-Forwarded-For header is believed.
	TrustedProxies []netip.Prefix
	// Functions: the executor (BACKD_EXECUTOR_URL, BACKD_EXECUTOR_TOKEN),
	// the internal listener it and the functions reach backd on
	// (BACKD_INTERNAL_ADDR, as BACKD_CALLBACK_URL from their side), and the
	// key callback tokens are signed with (BACKD_CALLBACK_KEY).
	ExecutorURL   string
	ExecutorToken string
	// EgressProxy (EXECUTOR_PROXY) and EgressKey (BACKD_EGRESS_KEY) are how push providers are
	// reached: through the egress proxy, with a token the worker signs for each delivery unit.
	// Without a proxy the senders dial the providers directly, and only public addresses.
	EgressProxy  string
	EgressKey    string
	InternalAddr string
	CallbackURL  string
	CallbackKey  string
	// BackdURL is backd's public address (BACKD_URL), the base of the links
	// in emails; a realm's email.public_url overrides it. No trailing slash.
	BackdURL string
	// SecretsKey is the master key functions' secrets (roadmap F5) are
	// encrypted under (BACKD_SECRETS_KEY, or BACKD_SECRETS_KEY_FILE for a
	// file holding it). Empty when neither is set: functions that declare
	// secrets are refused at startup (checked against the config, so it
	// isn't here).
	SecretsKey []byte
	// Dev enables BACKD_DEV: functions rebuild automatically when their
	// sources change. Local development only; serve refuses it unless
	// HTTPAddr is bound to localhost.
	Dev bool
	// DisableAdminAPI is BACKD_ADMIN_API=false: this instance serves no
	// /_admin route at all (they answer 404 like any unknown route), for public
	// instances when an internal one has the admin API.
	DisableAdminAPI bool
	// AdminUI is BACKD_ADMIN_UI=true: this instance serves the admin web
	// interface. It needs the admin API on the same instance.
	AdminUI bool
	// AdminUIIdle is BACKD_ADMIN_UI_IDLE: how long the admin UI may sit
	// untouched before it signs out and revokes its session (default 30m).
	AdminUIIdle time.Duration
	// DevAnyAddr (BACKD_DEV_ANY_ADDR) lets dev mode run on an address that
	// isn't localhost, for a container whose ports are published on the
	// host's localhost only.
	DevAnyAddr bool
	// DevLinks is BACKD_DEV_LINKS: extra links the dev landing page at /
	// shows, "Label=URL;Label=URL" — the local tools next to the API,
	// like a MinIO console. Dev mode only.
	DevLinks string
	// Deno is the deno binary dev mode bundles with; "" means "deno" on
	// the PATH (BACKD_DEV only; `functions build` reads DENO itself).
	Deno string
	// WorkerConcurrency caps how many async jobs one worker process runs
	// at once (WORKER_CONCURRENCY, roadmap F11); default 10.
	WorkerConcurrency int
	// Events is BACKD_EVENTS (default true): this instance may read the change stream for
	// realtime subscribers and serve /_realtime. Triggers is BACKD_TRIGGERS (default true): it may
	// hold the trigger dispatcher's lease. Neither reads anything until there is something to
	// serve (design/triggers-and-realtime.md §3).
	Events   bool
	Triggers bool
	// MetricsAddr (METRICS_ADDR) is where a process serves /metrics; empty
	// means it doesn't. MetricsToken (METRICS_TOKEN) makes it ask for that
	// bearer token. The port must be private (design/metrics.md).
	MetricsAddr  string
	MetricsToken string
}

Settings is the complete runtime configuration.

func Load

func Load(getenv func(string) string) (Settings, error)

Load reads settings through getenv (usually os.Getenv). It reports every problem at once rather than stopping at the first.

Directories

Path Synopsis
Package limits reads the instance limits that also decide whether a config is valid (image pixels, reference expansion, aggregation, trigger chains) from the environment.
Package limits reads the instance limits that also decide whether a config is valid (image pixels, reference expansion, aggregation, trigger chains) from the environment.

Jump to

Keyboard shortcuts

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