config

package
v0.1.0 Latest Latest
Warning

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

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

Documentation

Overview

Package config loads and validates the configuration of the foreman CLI: defaults, a YAML file, FOREMAN_* environment variables and flags, in increasing precedence. The library itself is configured in code with foreman.Config.

cfg, err := config.Load(path, os.Getenv)
err = cfg.Validate(true)

Index

Constants

View Source
const EnvPrefix = "FOREMAN_"

EnvPrefix prefixes every environment variable.

Variables

View Source
var ErrInvalid = errors.New("config: invalid")

ErrInvalid wraps every validation problem; the CLI exits with code 2.

Functions

func ParseDuration

func ParseDuration(s string) (time.Duration, error)

ParseDuration parses Go duration strings plus whole days with a d suffix ("14d"), optionally followed by a Go duration ("1d12h").

func RedactURL

func RedactURL(raw string) string

RedactURL hides the password of a connection string, given either as a postgres:// URL or in keyword/value form ("host=db password=secret").

Types

type Config

type Config struct {
	// DatabaseURL is the Postgres connection string (flag or env only).
	DatabaseURL string `yaml:"-"`
	// DatabaseURLFile names a file holding the connection string.
	DatabaseURLFile string `yaml:"database_url_file"`
	// Schema holding the Foreman tables.
	Schema string `yaml:"schema"`
	// Output is text or json.
	Output string `yaml:"output"`
	// Timeout bounds each command.
	Timeout Duration `yaml:"timeout"`
	Log     Log      `yaml:"log"`
}

Config is the configuration of the foreman CLI. The database URL is a secret: it comes from FOREMAN_DATABASE_URL, --database-url, or the file named by database_url_file, never from the config file itself.

func Default

func Default() Config

Default returns the defaults.

func Load

func Load(path string, getenv func(string) string) (Config, error)

Load builds the configuration: defaults, then the YAML file (path from --config or FOREMAN_CONFIG), then environment variables. Flags are applied by the caller afterwards with Apply. Validation is a separate step.

func (Config) Redacted

func (c Config) Redacted() (string, error)

Redacted returns the configuration as YAML with the password of the database URL replaced by "redacted".

func (*Config) ResolveSecrets

func (c *Config) ResolveSecrets() error

ResolveSecrets reads DatabaseURLFile when DatabaseURL is empty.

func (Config) Validate

func (c Config) Validate(needDatabase bool) error

Validate reports every problem at once.

type Duration

type Duration time.Duration

Duration is a time.Duration written as a Go duration string with an optional d (24h) suffix, for example "30s" or "14d".

func (Duration) MarshalYAML

func (d Duration) MarshalYAML() (any, error)

MarshalYAML writes the duration string.

func (Duration) Std

func (d Duration) Std() time.Duration

Std returns the time.Duration.

func (*Duration) UnmarshalYAML

func (d *Duration) UnmarshalYAML(n *yaml.Node) error

UnmarshalYAML parses a duration string.

type Log

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

Log configures CLI logging.

Jump to

Keyboard shortcuts

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