Documentation
¶
Overview ¶
Package config resolves configuration once, with precedence flags, then TOKENHOUND_* environment, then user config, then project tokenhound.yaml, then defaults, into tokenhound.Options.
Index ¶
Constants ¶
const BaselineFile = iconfig.BaselineFile
BaselineFile is the default baseline file name at the scan root.
const ProjectFile = iconfig.ProjectFile
ProjectFile is the project config file name at the scan root.
Variables ¶
This section is empty.
Functions ¶
func BaselinePath ¶ added in v0.2.0
BaselinePath returns the absolute path of the baseline file the configuration of in names: the baseline key (a project-tier value only when it stays inside Root), or <Root>/.tokenhound-baseline.json. The baseline file itself is never read. A bad configuration returns an *Error, as Load does, and so does a project-tier or default path that leads outside Root through a symlink.
func Load ¶
func Load(in Input) (tokenhound.Options, error)
Load resolves the configuration of one run into tokenhound.Options: flags, then TOKENHOUND_* environment variables, then the user file <user config dir>/tokenhound/config.yaml, then the project tokenhound.yaml, then defaults. The project file is untrusted: it cannot set network, alerts, hook or ping, disable verification, set a timeout or lower a limit, and its fail_on is unioned on top of every other layer (tighten only); each ignored value is an untrusted_config_key warning. The project ignore file (ignore_file, or <Root>/.tokenhound-ignore) and the user machine ignore file <user config dir>/tokenhound/ignore are parsed into Options.Ignore; a configured ignore file that is missing, or a malformed rule, is an *Error. The baseline file (baseline, or <Root>/.tokenhound-baseline.json) is parsed into Options.Baseline unless SkipBaseline is set; an absent file is no baseline (with new_only on, a baseline_missing warning), an invalid or newer one is an *Error. new_only sets FailOn.NewOnly and is ignored from the project tier. The Options carry parsed values only (a CA bundle as its bytes, never a path), every value explicitly, Network.FromEnv set, and the config warnings in Warnings. Sources and run settings (IncludeTestKeys, Deterministic, ToolVersion) are left for the caller. A bad configuration returns an *Error.
Types ¶
type Error ¶
type Error struct {
Issues []Issue
}
Error is a configuration that cannot be used: a file that cannot be read, an unsupported version or a schema violation. It lists every issue.
type Flags ¶
type Flags struct {
// Verify is false for --no-verify. Leave it nil for --no-verify=false, so a
// lower layer that disables verification is not overridden.
Verify *bool
// FailOnStatus is --fail-on-status, for example "live,unknown". An empty string
// is an empty list, which disables status failures; the CLI rejects an empty
// --fail-on-status as a usage error.
FailOnStatus *string
// FailOnWarnings is --fail-on-warnings, for example "timeout".
FailOnWarnings *string
// FailOnMinDollars is --fail-on-min-dollars.
FailOnMinDollars *string
// Timeout is --timeout.
Timeout *string
// NewOnly is --new-only.
NewOnly *bool
}
Flags are command line overrides. A nil field is not set; string fields hold the raw flag text (lists comma separated, durations like 90s).
type Input ¶
type Input struct {
// Root is the project root: the scan root directory ("" means the working
// directory). The project file is <Root>/tokenhound.yaml.
Root string
// ConfigFile replaces <Root>/tokenhound.yaml (--config). It stays project tier,
// because its content may come from the repository. A relative path resolves
// against the working directory; relative paths inside the file resolve against Root. A missing file, or one that is not a regular file, is an error.
ConfigFile string
// Flags override every other layer, with one exception: a project-tier fail_on
// is unioned on top of every layer including flags, so it can only add statuses
// or warning codes, or lower the minimum.
Flags Flags
// LookupEnv reads an environment variable (nil means os.LookupEnv).
LookupEnv func(string) (string, bool)
// UserConfigDir returns the user config directory (nil means
// os.UserConfigDir); an error skips the user tier.
UserConfigDir func() (string, error)
// SkipBaseline leaves the baseline file unread: Options.Baseline stays nil and no
// baseline_missing warning is added. The baseline verb sets it, because the
// baseline it writes must never depend on the one it replaces.
SkipBaseline bool
}
Input says where to resolve configuration from. Nil lookups use the process environment and os.UserConfigDir.
type Issue ¶
type Issue struct {
// File is the config file as displayed, or the environment variable or flag
// name; empty when the issue is about reading a file at all.
File string
// Line is the 1-based line in File, or 0 when File has no lines.
Line int
// Field is the config key, for example fail_on.status[1].
Field string
// Message says what is wrong. It never contains the config value.
Message string
}
Issue is one config problem.