settings

package
v0.1.11 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package settings is the typed runtime-settings registry: a code-defined catalog of keys with kinds, defaults, and validators, backed by the `settings` table. Boot-level configuration lives in TOML (internal/config); everything an administrator may change while the node runs lives here. Values the docs mark as "recommended defaults" (MTU, ports, DNS, interface cap) are ordinary registry entries an administrator can override.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidEndpoint

func ValidEndpoint(s string) error

ValidEndpoint validates the host or host:port form written to client configuration Endpoint lines. URLs, paths, control characters, whitespace, invalid bracket notation, and ports outside 1..65535 are rejected. Bare IPv6 addresses are accepted and bracketed by the client-config renderer.

func ValidSubnet

func ValidSubnet(s string) error

ValidSubnet is shared validation used by the interface service and tests for pool-shaped strings.

func ValidateStoredValue added in v0.1.9

func ValidateStoredValue(def Definition, stored string) error

ValidateStoredValue uses the current setting contract without opening a node or changing its cache. Secret values must already be decrypted by the caller.

Types

type Definition

type Definition struct {
	Key        string
	Kind       Kind
	Default    any
	Min, Max   int64
	Options    []string
	Validator  func(v any) error
	Category   string // general|networking|accounting|security|backup|drift|interfaces
	Secret     bool
	Advanced   bool // hidden behind the Settings UI "advanced" gate
	Persistent bool // change requires the owning feature to re-render state
}

Definition is one registry entry. Min/Max apply to KindInt; Options restrict KindString to an enum; Validator adds cross-field or structural rules on the typed value.

func Defaults

func Defaults() []Definition

Defaults is the Phase 1 catalog. Every value here is a *recommended default* chosen from upstream constraints (docs/operations/deployment.md) — administrators may change any of it; final guidance follows the Phase 11 production matrix. Phases add keys; keys are never renamed (Settings/API contract).

type Item

type Item struct {
	Definition
	Value   any
	IsZero  bool // value equals the default (row absent)
	Updated time.Time
}

Item is a resolved setting returned to UIs/CLI.

type Kind

type Kind int
const (
	KindString Kind = iota
	KindInt
	KindBool
	KindStringList // JSON array of strings
	KindSecret     // stored encrypted with the master key (never logged)
)

func (Kind) String

func (k Kind) String() string

type Registry

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

Registry is safe for concurrent use. Values are cached in memory and invalidated on write; this is a read-heavy, write-rare table.

func New

func New(db *database.DB, ring *secrets.KeyRing, defs []Definition) (*Registry, error)

func (*Registry) All

func (r *Registry) All(ctx context.Context) ([]Item, error)

All resolves every definition (settings screens). Secret values are redacted to "<set>"/"" — never returned in plaintext.

func (*Registry) Definitions

func (r *Registry) Definitions() []Definition

Definitions returns the catalog (order undefined).

func (*Registry) Get

func (r *Registry) Get(ctx context.Context, key string) (any, error)

Get returns the typed value (default when no row). Unknown keys error.

func (*Registry) GetBool

func (r *Registry) GetBool(ctx context.Context, key string) (bool, error)

func (*Registry) GetInt

func (r *Registry) GetInt(ctx context.Context, key string) (int, error)

func (*Registry) GetSecret

func (r *Registry) GetSecret(ctx context.Context, key string) (string, error)

GetSecret returns the decrypted secret value ("" when unset). It is the only accessor that yields plaintext; the value must never be logged.

func (*Registry) GetString

func (r *Registry) GetString(ctx context.Context, key string) (string, error)

Typed getters. A wrong-kind expectation is a programmer error surfaced as an error, not a panic.

func (*Registry) GetStringList

func (r *Registry) GetStringList(ctx context.Context, key string) ([]string, error)

func (*Registry) Reset

func (r *Registry) Reset(ctx context.Context, key string) error

Reset removes an override; the default applies again.

func (*Registry) Set

func (r *Registry) Set(ctx context.Context, key string, value any) error

Set validates and stores a typed value (panel form).

func (*Registry) SetBatch

func (r *Registry) SetBatch(ctx context.Context, updates []Update) error

SetBatch validates and encodes every update before writing any of them, then commits the complete set in one SQLite transaction. Failed validation, encryption, writes, and commits leave both persisted state and cache intact.

func (*Registry) SetRaw

func (r *Registry) SetRaw(ctx context.Context, key, raw string) error

SetRaw validates and stores a textual input (CLI/API form); parsing is kind-driven. Secret values are plaintext on input, encrypted at rest.

func (*Registry) Validate

func (r *Registry) Validate(key string, value any) error

Validate checks a value against the key's constraints WITHOUT persisting — the panel uses it to validate form input before committing a sequence of writes (e.g. onboarding validates node.endpoint before creating the owner).

type Update

type Update struct {
	Key   string
	Value any
}

Update is one typed setting value in an atomic SetBatch operation.

Jump to

Keyboard shortcuts

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