Documentation
¶
Overview ¶
Package server runs backd's server roles (API, worker, provisioning, the executor and egress bootstrap): settings, config loading and startup checks, the MongoDB client, and the dev-mode reloader.
Index ¶
- Constants
- func Provision(ctx context.Context, a *App) error
- func Run(ctx context.Context, role string, getenv func(string) string, logOut io.Writer, ...) error
- func Serve(ctx context.Context, a *App) error
- func ServeEgress(getenv func(string) string, stderr io.Writer) error
- func ServeExecutor(getenv func(string) string, stderr io.Writer) error
- func Worker(ctx context.Context, a *App) error
- type App
- func (a *App) Client() *mongo.Client
- func (a *App) Close()
- func (a *App) Handler() http.Handler
- func (a *App) HandlerConfig() httpapi.Config
- func (a *App) InternalHandler() http.Handler
- func (a *App) Log() *slog.Logger
- func (a *App) OpenEvents() func()
- func (a *App) Provisioner() *mongodb.Provisioner
- func (a *App) RealmUsers() func(string) *auth.Users
- func (a *App) Registry() *registry.Registry
- func (a *App) Rescan(ctx context.Context, req triggers.RescanRequest) (triggers.RescanResult, error)
- func (a *App) SetOptions(o Options)
- func (a *App) Settings() *settings.Settings
- func (a *App) UsersOf(ctx context.Context, realm string) (*auth.Users, error)
- type Options
Constants ¶
const EgressHelp = `Runs backd's egress role: the only way a function process reaches the
network. An HTTP forward/CONNECT proxy that resolves every target itself
and refuses loopback, private, link-local (metadata), CGNAT, multicast and
unspecified addresses; each function process authenticates with a token
scoped to its own invocation (minted by ` + "`backd-server executor`" + `), so the proxy
enforces that invocation's allowlist too.
Environment:
BACKD_EGRESS_KEY required: the secret shared with the executor
(32+ characters), verifies each process's token
EGRESS_ADDR listen address (default :3128)
EGRESS_ALLOW_PRIVATE comma-separated host:port exceptions to the
private-address block (backd's callback listener)
LOG_LEVEL debug, info, warn or error (default info)
It must be the executor network's only route out; MongoDB and backd's
other endpoints must stay unreachable from it (network placement, not
something this process enforces).
`
const ExecutorHelp = `Runs server-side functions for backd: each call in its own Deno process, with only the function's permissions and limits. Needs Deno ` + registry.DenoVersion + ` (the backd-executor image has it), never CONFIG_DIR or MongoDB. Environment: BACKD_EXECUTOR_TOKEN required: the secret shared with backd (32+ characters) EXECUTOR_ADDR listen address (default :9100) EXECUTOR_DIR writable directory for the bundle cache (default: a backd-executor directory in the temp dir) EXECUTOR_MAX_PROCESSES functions running at once (default 64) EXECUTOR_PROXY backd-server egress's base URL (e.g. http://backd-egress:3128); without it, function processes get no outbound network beyond --allow-net on this host BACKD_EGRESS_KEY required with EXECUTOR_PROXY (32+ characters): signs each invocation's egress credentials DENO the Deno binary (default deno on the PATH) LOG_LEVEL debug, info, warn or error (default info) It must only be reachable by backd, and reach only backd's internal listener and backd-server egress. `
Variables ¶
This section is empty.
Functions ¶
func Run ¶
func Run(ctx context.Context, role string, getenv func(string) string, logOut io.Writer, o Options) error
Run runs a server role (serve, worker or provision) with its flags. Outside dev mode, or for provision, any startup error is final. In dev mode (BACKD_DEV), serve and worker don't exit on what the developer edits (see runDev).
Types ¶
type App ¶
type App struct {
// contains filtered or unexported fields
}
App holds what every command needs: settings, logger, registry, MongoDB client.
func NewApp ¶
func NewApp(cfg settings.Settings, log *slog.Logger, reg *registry.Registry, client *mongo.Client, fingerprint string) *App
NewApp is an app on a config that is already loaded and a connected client, for the tools that work on the database directly without the startup checks (Setup does them).
func Setup ¶
Setup loads the settings and the config and connects to MongoDB: what every role and direct tool needs. Any error is final (Run is the dev-mode start that waits instead).
func (*App) HandlerConfig ¶
func (*App) InternalHandler ¶
InternalHandler serves the internal listener (functions only).
func (*App) OpenEvents ¶
func (a *App) OpenEvents() func()
OpenEvents prepares this instance's realtime consumer when BACKD_EVENTS allows it. Nothing is read until a subscriber arrives, so it costs nothing on an instance without any. It returns the function that closes it.
func (*App) Provisioner ¶
func (a *App) Provisioner() *mongodb.Provisioner
func (*App) RealmUsers ¶
RealmUsers returns the user service of every auth-enabled realm, built on first use. They share one Hasher, so the hashing concurrency cap applies per process.
func (*App) Rescan ¶
func (a *App) Rescan(ctx context.Context, req triggers.RescanRequest) (triggers.RescanResult, error)
Rescan reads a collection's stored documents again and queues the trigger jobs their changes would have queued (`backd-server triggers rescan`).
func (*App) SetOptions ¶
SetOptions applies the role flags before the role runs.