config

package
v0.1.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package config loads the hub configuration. Sources are applied in this order, each one overriding the previous: built-in defaults, configuration file (YAML), environment variables, command-line flags.

Index

Constants

View Source
const (
	OriginDefault = "default"
	OriginFile    = "file"
	OriginEnv     = "environment"
)

Origins of a value.

View Source
const DefaultFile = "/etc/regulus/config.yaml"

DefaultFile is where the package installs the hub configuration. The hub itself only reads a file it is told about (--config); the console and the `regulus config` commands fall back to this one when it exists.

View Source
const MinMetricsInterval = time.Second

MinMetricsInterval is the shortest accepted metrics interval.

Variables

This section is empty.

Functions

func FindFile

func FindFile(explicit string, getenv func(string) string) string

FindFile returns the configuration file to use: the explicit path, else REGULUS_CONFIG, else DefaultFile when it exists, else "".

func Keys

func Keys() []string

Keys lists the keys of the settings.

func Normalize

func Normalize(key, raw string) (string, error)

Normalize checks a value typed for a setting and returns it in canonical form (for example "9090" becomes ":9090"). The error says what is wrong in words fit for a person typing it.

func Resolve

func Resolve(file string, getenv func(string) string) (Config, []Entry, error)

Resolve loads the configuration the way the hub would (defaults, file, environment) and returns it with every setting's value and origin.

func SetFile

func SetFile(path, key, raw string) (string, error)

SetFile changes one setting in the YAML file at path, keeping comments and the rest of the file as they are, and returns the canonical value written. The new file is checked as a whole before anything is written, and it is written in place so the owner and mode of the file stay.

Types

type Agent

type Agent struct {
	// Hub is the address of the hub's agent listener, "host:port".
	Hub string `yaml:"hub"`
	// Token is the one-time enrollment token. It is only needed the first
	// time; once the agent is enrolled it is ignored.
	Token string `yaml:"token"`
	// CAFingerprint is the fingerprint of the hub's CA, shown with the token.
	// The agent only trusts a hub that has this CA.
	CAFingerprint string `yaml:"ca_fingerprint"`
	// DataDir holds the agent's key and certificates.
	DataDir string `yaml:"data_dir"`
	Log     Log    `yaml:"log"`
	// Updates lets the hub update this agent: the agent fetches the release the
	// hub offers and leaves it to the installer unit that runs as root
	// (regulus-agent-update.path, enabled by the installer). On its own the
	// setting does nothing.
	Updates bool `yaml:"updates"`
	// EnrollOnly enrolls and exits without connecting. The installer uses it
	// to enroll as the service user before the service starts. Command line
	// only.
	EnrollOnly bool `yaml:"-"`
}

Agent is the configuration of a remote agent (`regulus agent`).

func DefaultAgent

func DefaultAgent() Agent

DefaultAgent returns the built-in defaults of an agent.

func LoadAgent

func LoadAgent(args []string, getenv func(string) string, output io.Writer) (Agent, error)

LoadAgent builds the agent configuration like Load does for the hub: defaults, then the file, then the REGULUS_AGENT_* variables, then the flags.

func (Agent) Validate

func (c Agent) Validate() error

Validate reports whether the configuration is usable.

type Config

type Config struct {
	// Listen is the address the HTTP server listens on.
	Listen string `yaml:"listen"`
	// AgentListen is the address where remote agents connect (gRPC over TLS
	// with client certificates). Empty keeps remote agents off: only the
	// built-in agent can then connect.
	AgentListen string `yaml:"agent_listen"`
	// DataDir is the directory where the hub stores its database.
	DataDir string `yaml:"data_dir"`
	// BuiltinAgent runs an agent inside the hub, so the hub's own server is
	// managed like any other.
	BuiltinAgent bool `yaml:"builtin_agent"`
	// MetricsInterval is how often agents report their metrics to the hub.
	MetricsInterval time.Duration `yaml:"metrics_interval"`
	Log             Log           `yaml:"log"`
	Console         Console       `yaml:"console"`
	Updates         Updates       `yaml:"updates"`
}

Config is the complete hub configuration.

func Default

func Default() Config

Default returns the built-in defaults.

func Load

func Load(args []string, getenv func(string) string, output io.Writer) (Config, error)

Load builds the configuration from args (the command-line flags without the program and subcommand names) and the environment. getenv is usually os.Getenv. Flag usage and parse errors are written to output.

func LoadWith

func LoadWith(name string, args []string, getenv func(string) string, output io.Writer, extra func(*flag.FlagSet)) (Config, error)

LoadWith is Load for commands that take flags of their own besides the configuration ones: name is shown in the usage, and extra defines the other flags on the flag set before the arguments are parsed.

func (Config) Get

func (c Config) Get(key string) (string, bool)

Get returns the value of a setting in the form Set accepts.

func (Config) Validate

func (c Config) Validate() error

Validate reports whether the configuration is usable.

type Console

type Console struct {
	// TUI turns the full-screen console on. When false, `regulus` prints the
	// same information as plain text.
	TUI bool `yaml:"tui"`
}

Console configures the interactive terminal console (`regulus`).

type Entry

type Entry struct {
	Setting
	Value  string
	Origin string
}

Entry is a setting with its current value and where the value comes from.

type Log

type Log struct {
	// Level is one of debug, info, warn, error.
	Level string `yaml:"level"`
	// Format is one of text, json.
	Format string `yaml:"format"`
}

Log configures logging.

type Setting

type Setting struct {
	// Key is the dotted YAML path, such as log.level.
	Key string
	// Env is the environment variable that overrides it, if any.
	Env         string
	Description string
	// Choices lists the accepted values when there is a fixed set.
	Choices []string
	// Restart is true when the hub reads the setting only at start.
	Restart bool
	// contains filtered or unexported fields
}

Setting describes one hub setting that people can read and change with the console or `regulus config`.

func Lookup

func Lookup(key string) (Setting, bool)

Lookup returns the setting with the given key.

func Settings

func Settings() []Setting

Settings returns the settings in the order they are shown.

type Updates

type Updates struct {
	// Check lets the hub ask GitHub for new releases every few hours. Turn it
	// off on a hub that must not contact the internet.
	Check bool `yaml:"check"`
	// Apply lets the hub ask for a downloaded release to be installed, by the
	// root-owned helper that systemd starts (regulus-update.path). The
	// installer turns it on together with that unit; without the unit nothing
	// would pick the request up.
	Apply bool `yaml:"apply"`
}

Updates configures how the hub looks for new releases. What happens when one is found (the mode and the channel) is chosen in the dashboard.

Jump to

Keyboard shortcuts

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