preflight

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2026 License: GPL-3.0 Imports: 12 Imported by: 0

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.

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 // OpenBao health (nil = no vault)
	VaultTokenOK    func() bool                     // AppRole token health (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