config

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: Apache-2.0 Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const ProjectFile = iconfig.ProjectFile

ProjectFile is the project config file name at the scan root.

Variables

This section is empty.

Functions

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 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.

func (*Error) Error

func (e *Error) Error() string

Error returns one line per 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
}

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)
}

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.

func (Issue) String

func (i Issue) String() string

String formats the issue as "file:line: field: message".

Jump to

Keyboard shortcuts

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