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 ¶
const EnvPrefix = "FOREMAN_"
EnvPrefix prefixes every environment variable.
Variables ¶
var ErrInvalid = errors.New("config: invalid")
ErrInvalid wraps every validation problem; the CLI exits with code 2.
Functions ¶
func ParseDuration ¶
ParseDuration parses Go duration strings plus whole days with a d suffix ("14d"), optionally followed by a Go duration ("1d12h").
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 Load ¶
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 ¶
Redacted returns the configuration as YAML with the password of the database URL replaced by "redacted".
func (*Config) ResolveSecrets ¶
ResolveSecrets reads DatabaseURLFile when DatabaseURL is empty.
type 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 ¶
MarshalYAML writes the duration string.