settings

package
v0.8.5 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package settings reads backd's runtime configuration from environment variables.

Index

Constants

View Source
const DefaultImageMaxPixels = 40_000_000

DefaultImageMaxPixels is the pixel limit for image versions when none is set.

Variables

This section is empty.

Functions

func AggregateLimitsFrom added in v0.8.5

func AggregateLimitsFrom(getenv func(string) string) (registry.AggregateLimits, error)

AggregateLimitsFrom reads the instance's aggregation limits (BACKD_AGGREGATE_TIME and BACKD_AGGREGATE_MAX_GROUPS). A collection's aggregate.limits may only lower them.

func ExpandLimitsFrom added in v0.8.5

func ExpandLimitsFrom(getenv func(string) string) (registry.ExpandLimits, error)

ExpandLimitsFrom reads the instance's reference expansion limits (BACKD_EXPAND_MAX_DEPTH, _PATHS, _ARRAY and _DOCS). A collection's reference may only lower the array limit.

func ImageMaxPixels added in v0.8.1

func ImageMaxPixels(getenv func(string) string) (int64, error)

ImageMaxPixels reads BACKD_IMAGE_MAX_PIXELS: a positive number of pixels.

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

func TriggerLimitsFrom added in v0.8.5

func TriggerLimitsFrom(getenv func(string) string) (registry.TriggerLimits, error)

TriggerLimitsFrom reads the instance's trigger limits: BACKD_TRIGGER_MAX_CHAIN, how deep a chain of writes caused by trigger runs may go. A realm's `triggers:` may only lower it.

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
	// 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
	// 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
	// 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.

Jump to

Keyboard shortcuts

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