preflight

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2026 License: GPL-3.0 Imports: 14 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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TCPAddrFromDBConfig

func TCPAddrFromDBConfig(db config.DatabaseConfig) string

TCPAddrFromDBConfig returns host:port for the configured database, or "" if the database is local-only (SQLite, or postgres without a TCP address). For PostgreSQL it parses the libpq DSN form `postgres://user:pass@host:port/db?...` or the `key=value` form (`host=... port=...`).

func TCPAddrFromHTTPURL

func TCPAddrFromHTTPURL(httpURL string) string

TCPAddrFromHTTPURL extracts host:port from an http:// or https:// URL. Returns empty string if the URL cannot be parsed or has no host. Defaults to 80 for http and 443 for https when the URL omits a port.

func TCPAddrFromRedisURL

func TCPAddrFromRedisURL(redisURL string) string

TCPAddrFromRedisURL extracts host:port from a redis:// URL. Returns empty string if the URL cannot be parsed or has no host. Defaults to port 6379 if the URL omits a port.

Types

type Checker

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

Checker runs system checks and caches the latest report. It separates static (startup) checks from dynamic (re-runnable) checks.

func NewChecker

func NewChecker(deps RuntimeDeps) *Checker

NewChecker creates a Checker with the given runtime dependencies. Call Init to populate static results and run the first dynamic check.

func (*Checker) Init

func (c *Checker) Init(ctx context.Context, configReport, dockerReport *Report)

Init records the startup check results (config + docker) as static, then runs a first dynamic check pass. This should be called once during server startup, after all dependencies are initialized.

func (*Checker) Latest

func (c *Checker) Latest() *Report

Latest returns the most recent cached report. Returns nil if Init has not been called yet.

func (*Checker) RunDynamic

func (c *Checker) RunDynamic(ctx context.Context) *Report

RunDynamic re-runs only the dynamic checks and updates the cached report. Returns the combined (static + fresh dynamic) report.

type Report

type Report struct {
	RanAt   time.Time `json:"ran_at"`
	Results []Result  `json:"results"`
	Summary Summary   `json:"summary"`
}

Report collects all check results.

func RunConfigChecks

func RunConfigChecks(cfg *config.Config) *Report

RunConfigChecks evaluates checks that need only the parsed config. Safe to call immediately after config.Load().

func (*Report) Add

func (r *Report) Add(res Result)

Add appends a result to the report and updates the summary.

func (*Report) HasErrors

func (r *Report) HasErrors() bool

HasErrors returns true if any result has SeverityError.

func (*Report) HasWarnings

func (r *Report) HasWarnings() bool

HasWarnings returns true if any result has SeverityWarning or above.

func (*Report) Log

func (r *Report) Log()

Log emits each non-OK result via slog at the appropriate level.

type Result

type Result struct {
	Name     string   `json:"name"`
	Severity Severity `json:"severity"`
	Message  string   `json:"message"`
	Category string   `json:"category"` // "config", "docker", "runtime"
}

Result describes the outcome of a single check.

func CheckRedisAuth added in v0.0.4

func CheckRedisAuth(cfg *config.RedisConfig) Result

CheckRedisAuth dials the configured Redis URL without AUTH, sends a PING, and classifies the reply. Applies across backends — unauth'd Redis is a footgun whether workers live in a Docker network namespace, a bwrap sandbox, or a host-network process.

Severities:

  • SeverityOK: Redis replies `-NOAUTH` (authentication required).
  • SeverityError: Redis replies `+PONG` (auth not required).
  • SeverityInfo: TLS Redis (`rediss://` — plain-TCP probe skipped), Redis not reachable, generic unexpected reply. Surfaced as Info so the operator investigates rather than getting a silent OK.

Called explicitly from both backends' RunPreflight so both coverage modes benefit from the same check. Two call sites are small enough not to warrant a registry abstraction; revisit if a third backend ships.

type RuntimeDeps

type RuntimeDeps struct {
	StorePath       string                          // pkg-store volume root (for disk space check)
	DBPing          func(ctx context.Context) error // database health
	BackendPing     func(ctx context.Context) error // backend health (Docker socket, process backend liveness, etc.)
	RedisPing       func(ctx context.Context) error // Redis health (nil = no Redis)
	IDPCheck        func(ctx context.Context) error // OIDC IdP health (nil = no OIDC)
	VaultCheck      func(ctx context.Context) error // vault health (nil = no vault)
	VaultTokenOK    func() bool                     // AppRole auth health — last login ok and token not yet expired (nil = no AppRole)
	UpdateAvailable func() string                   // latest version when an update is recommended; "" otherwise
	ServerVersion   string
}

RuntimeDeps provides the dependencies for dynamic (re-runnable) checks. All function fields are called on demand; nil means the check is skipped.

type Severity

type Severity int

Severity classifies the urgency of a check result. Values are ordered so that higher severity sorts first in descending order.

const (
	SeverityOK      Severity = iota // check passed
	SeverityInfo                    // informational (operator awareness)
	SeverityWarning                 // security hazard or likely misconfiguration
	SeverityError                   // blocks startup
)

func (Severity) MarshalJSON

func (s Severity) MarshalJSON() ([]byte, error)

MarshalJSON serializes Severity as a lowercase JSON string.

func (Severity) String

func (s Severity) String() string

String returns the lowercase name of the severity.

func (*Severity) UnmarshalJSON

func (s *Severity) UnmarshalJSON(b []byte) error

UnmarshalJSON parses a Severity from a JSON string.

type Summary

type Summary struct {
	Errors   int `json:"errors"`
	Warnings int `json:"warnings"`
	Info     int `json:"info"`
	OK       int `json:"ok"`
}

Summary counts results by severity.

Jump to

Keyboard shortcuts

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