app

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: Apache-2.0 Imports: 42 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 app is the composition root of `bubbles serve`: it opens the store, loads the TLS material, builds the HTTPS and onboarding handlers, binds both listeners, runs the background jobs and shuts everything down gracefully.

Index

Constants

View Source
const (
	SANWatchInterval   = 5 * time.Minute
	RenewCheckInterval = 12 * time.Hour
	// SessionPurgeInterval is how often expired sessions and old password
	// reset rows are deleted.
	SessionPurgeInterval = time.Hour
)

Job intervals (pipeline step 18).

View Source
const DefaultShutdownTimeout = 10 * time.Second

DefaultShutdownTimeout bounds the graceful drain on shutdown.

View Source
const DrainTimeout = 3 * time.Second

DrainTimeout bounds how long a reset waits for requests in flight (after closing the gate and the WebSockets) before it deletes anything anyway.

View Source
const MaintenanceRetryAfter = "5"

MaintenanceRetryAfter is the Retry-After (seconds) of a maintenance 503.

Variables

This section is empty.

Functions

func CertManager

func CertManager(cfg config.Config, logger *slog.Logger, opts Options) (*tlsca.Manager, error)

CertManager builds the TLS certificate manager for cfg: bring-your-own files when --tls-cert/--tls-key are set, else the local CA in <data>/tls with the leaf SANs discovered from the LAN addresses, host name, mDNS name and --tls-extra-dns. `bubbles cert reissue` uses it too.

func DefaultLANAddrs

func DefaultLANAddrs() ([]netip.Addr, error)

DefaultLANAddrs returns the host's ranked private LAN addresses.

func SANSource

func SANSource(cfg config.Config, lanAddrs func() ([]netip.Addr, error), hostname func() (string, error)) func() (tlsca.SANs, error)

SANSource returns the leaf SAN discovery function for cfg.

Types

type App

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

App is a running bubbles server.

func New

func New(ctx context.Context, cfg config.Config, logger *slog.Logger, opts Options) (_ *App, err error)

New wires the server for cfg. The data directory must have been prepared with config.EnsureDataDir and locked by the caller. Both listeners are bound before New returns (see HTTPSAddr and HTTPAddr), but nothing is served until Run.

func (*App) Certs

func (a *App) Certs() *tlsca.Manager

Certs is the TLS certificate manager (a factory reset that rotates the CA replaces it).

func (*App) HTTPAddr

func (a *App) HTTPAddr() net.Addr

HTTPAddr is the bound onboarding listener address.

func (*App) HTTPSAddr

func (a *App) HTTPSAddr() net.Addr

HTTPSAddr is the bound HTTPS listener address.

func (*App) HTTPSPort

func (a *App) HTTPSPort() int

HTTPSPort is the bound HTTPS port.

func (*App) OnboardingURLs

func (a *App) OnboardingURLs() []string

OnboardingURLs returns the onboarding base URLs, best first.

func (*App) RefreshMDNS

func (a *App) RefreshMDNS()

RefreshMDNS re-announces the TXT record after the CA fingerprint changed.

func (*App) Reset

func (a *App) Reset(ctx context.Context, req reset.Request) (*reset.Result, error)

Reset runs req on the live server (pipeline steps 19 and 20): the steps of internal/reset with hooks that enter maintenance mode, close every WebSocket with 4011 (content) or 4010 (factory), wait for requests in flight, and for a factory reset tear the services down, swap the CA when asked and rebuild everything on the new database. Confirmation and password checks are the caller's. If a step fails after maintenance mode began, the server stays in maintenance: a restart completes the reset.

func (*App) Run

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

Run serves both listeners and runs the jobs until ctx is done or a listener fails, then shuts down gracefully within the shutdown timeout.

func (*App) Shutdown

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

Shutdown stops accepting connections, drains in-flight requests until ctx expires (then closes them), and closes the database. It is idempotent.

func (*App) URLs

func (a *App) URLs() []string

URLs returns the HTTPS base URLs of this server, best first.

type Job

type Job struct {
	Name     string
	Interval time.Duration
	Run      func(context.Context) error
}

Job is a periodic background task.

type LogFiles

type LogFiles interface {
	// Reopen closes the live file, runs clear, then opens a fresh file.
	Reopen(clear func() error) error
}

LogFiles is a log file writer a factory reset can wipe while the server runs (logging.RotatingWriter).

type Options

type Options struct {
	// Stderr receives the startup banner; nil discards it.
	Stderr io.Writer
	// Now is the clock; nil means time.Now.
	Now func() time.Time
	// NewTicker creates job tickers; nil means time.NewTicker.
	NewTicker func(time.Duration) Ticker
	// LANAddrs returns the ranked private LAN addresses; nil means
	// DefaultLANAddrs.
	LANAddrs func() ([]netip.Addr, error)
	// Hostname returns the OS host name; nil means os.Hostname.
	Hostname func() (string, error)
	// ShutdownTimeout bounds the graceful drain; 0 means DefaultShutdownTimeout.
	ShutdownTimeout time.Duration
	// AuthParams are the argon2id parameters for new password hashes; the
	// zero value means auth.DefaultParams (tests pass cheap ones).
	AuthParams auth.Params
	// BackupWorkFactor is the scrypt work factor (log2 N) for admin backups;
	// 0 means age's default (tests pass a cheap one).
	BackupWorkFactor int
	// AdminPassword fixes the password of the bootstrapped admin instead of a
	// generated one (tests).
	AdminPassword string
	// LogFiles is the writer behind the server log; a factory reset wipes
	// the log directory through it. Nil: the directory is wiped directly.
	LogFiles LogFiles
}

Options are the injectable dependencies of App. The zero value uses the real clock, tickers, network interfaces and host name.

type Ticker

type Ticker interface {
	C() <-chan time.Time
	Stop()
}

Ticker is the part of time.Ticker the job runner uses; tests inject fakes.

Jump to

Keyboard shortcuts

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