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
- func FindFile(explicit string, getenv func(string) string) string
- func Keys() []string
- func Normalize(key, raw string) (string, error)
- func Resolve(file string, getenv func(string) string) (Config, []Entry, error)
- func SetFile(path, key, raw string) (string, error)
- type Agent
- type Config
- type Console
- type Entry
- type Log
- type Setting
- type Updates
Constants ¶
const ( OriginDefault = "default" OriginFile = "file" OriginEnv = "environment" )
Origins of a value.
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.
const MinMetricsInterval = time.Second
MinMetricsInterval is the shortest accepted metrics interval.
Variables ¶
This section is empty.
Functions ¶
func FindFile ¶
FindFile returns the configuration file to use: the explicit path, else REGULUS_CONFIG, else DefaultFile when it exists, else "".
func Normalize ¶
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 ¶
Resolve loads the configuration the way the hub would (defaults, file, environment) and returns it with every setting's value and origin.
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.
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 Load ¶
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.
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 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`.
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.