Documentation
¶
Overview ¶
Package config loads layered configuration and records where each value came from.
Layers, lowest precedence first: defaults, user file, project file, RELGAP_* env vars, flags. Files are checked against schemas/config-v1.json before they are merged.
Index ¶
- Constants
- Variables
- func CacheDirPath(lookup LookupFunc, goos string) (string, error)
- func EnvKeys() ([]string, error)
- func EnvVarName(key string) string
- func FindProjectFile(dir, stopDir string) (string, error)
- func Template() []byte
- func UserConfigPath(lookup LookupFunc, goos string) (string, error)
- func ValidateFile(path string) error
- func WriteTemplate(path string, force bool) error
- type Cache
- type Config
- type Detectors
- type EnvVar
- type File
- type GitHub
- type GitLab
- type GitLabHost
- type IgnoreRule
- type Images
- type LLM
- type LookupFunc
- type Options
- type Policy
- type Problem
- type Result
- type Scan
- type Source
- type SourceKind
- type ToolOverride
- type ValidationError
Constants ¶
const ( EnvPrefix = "RELGAP_" EnvConfigFile = EnvPrefix + "CONFIG" )
Environment variable names.
const ( AppName = "relgap" UserFileName = "config.yaml" ProjectFileName = ".relgap.yaml" )
const SchemaVersion = 1
SchemaVersion is the config schema_version this binary reads.
Variables ¶
var ErrExists = errors.New("file exists")
ErrExists reports that WriteTemplate found a file at its path.
var ErrInvalid = errors.New("invalid configuration")
ErrInvalid is wrapped by every configuration error.
Functions ¶
func CacheDirPath ¶
func CacheDirPath(lookup LookupFunc, goos string) (string, error)
CacheDirPath returns $XDG_CACHE_HOME/relgap.
func EnvKeys ¶ added in v0.6.0
EnvKeys returns the config keys that environment variables can set: scalars and string lists.
func EnvVarName ¶
EnvVarName returns the environment variable for a dotted key: "." and "-" become "_", so cache.ttl is RELGAP_CACHE_TTL.
func FindProjectFile ¶
FindProjectFile walks up from dir to the git root, or to stopDir when that comes first, looking for .relgap.yaml. Outside a git repository and stopDir it reads only dir. It returns "" when there is none.
func Template ¶ added in v0.4.0
func Template() []byte
Template returns the commented config file that config init writes. Every key except schema_version is commented out at its default.
func UserConfigPath ¶
func UserConfigPath(lookup LookupFunc, goos string) (string, error)
UserConfigPath returns $XDG_CONFIG_HOME/relgap/config.yaml. macOS uses ~/.config too, not ~/Library.
func ValidateFile ¶
ValidateFile checks one config file against the schema.
Types ¶
type Cache ¶
type Cache struct {
Dir string `json:"dir" jsonschema_description:"Cache directory. Empty means $XDG_CACHE_HOME/relgap."`
TTLOverride map[string]string `json:"ttl_override" jsonschema_description:"Per-source TTL overrides as Go durations, e.g. {endoflife: 24h}."`
}
Cache configures the on-disk HTTP cache.
type Config ¶
type Config struct {
SchemaVersion int `json:"schema_version" jsonschema:"enum=1" jsonschema_description:"Config file format version."`
GitHub GitHub `json:"github"`
Cache Cache `json:"cache"`
Scan Scan `json:"scan"`
Tools map[string]ToolOverride `json:"tools" jsonschema_description:"Local tool overrides and additions, keyed by tool name."`
Aliases map[string]string `json:"aliases" jsonschema_description:"Maps a raw pin name (e.g. TG_VERSION) to a tool name."`
Ignore []IgnoreRule `` /* 148-byte string literal not displayed */
Policy Policy `json:"policy"`
LLM LLM `json:"llm"`
GitLab GitLab `json:"gitlab"`
Images Images `json:"images"`
}
Config defines every configuration key. The JSON tags are the key names, and schemas/config-v1.json is generated from this type.
type Detectors ¶
type Detectors struct {
CIActions bool `` /* 153-byte string literal not displayed */
Generic bool `json:"generic" jsonschema_description:"Detect NAME_VERSION=x.y.z assignments in extra_files."`
}
Detectors toggles opt-in pin detectors.
type EnvVar ¶ added in v0.6.0
EnvVar is an environment variable that the binary reads, other than the config keys.
type File ¶
type File struct {
Kind SourceKind `json:"kind"`
Path string `json:"path"`
Found bool `json:"found"`
Explicit bool `json:"explicit,omitempty"` // set by --config or RELGAP_CONFIG
}
File is a config file location and whether it exists.
type GitHub ¶
type GitHub struct {
Host string `` /* 172-byte string literal not displayed */
Concurrency int `json:"concurrency" jsonschema:"minimum=1,maximum=64" jsonschema_description:"Maximum concurrent requests per tool."`
}
GitHub configures the GitHub API client.
type GitLab ¶ added in v0.11.0
type GitLab struct {
Hosts []GitLabHost `json:"hosts" jsonschema_description:"Self-managed GitLab hosts. A git source on a host that isn't listed stays unresolved."`
}
GitLab configures self-managed GitLab hosts.
type GitLabHost ¶ added in v0.11.0
type GitLabHost struct {
Host string `` /* 147-byte string literal not displayed */
TokenEnv string `` /* 240-byte string literal not displayed */
}
GitLabHost is one self-managed GitLab host.
type IgnoreRule ¶
type IgnoreRule struct {
Tool string `` /* 156-byte string literal not displayed */
Name string `` /* 199-byte string literal not displayed */
Path string `` /* 177-byte string literal not displayed */
}
IgnoreRule suppresses the pins that match every field it sets: a tool, a raw name, a path.
type Images ¶ added in v0.11.0
type Images struct {
Registries []string `` /* 208-byte string literal not displayed */
}
Images configures the image registries outdated reads tags from.
type LLM ¶
type LLM struct {
Provider string `` /* 169-byte string literal not displayed */
Model string `` /* 197-byte string literal not displayed */
BaseURL string `` /* 229-byte string literal not displayed */
APIKeyEnv string `` /* 211-byte string literal not displayed */
API string `` /* 238-byte string literal not displayed */
AWSProfile string `` /* 219-byte string literal not displayed */
MaxInputTokens int `` /* 226-byte string literal not displayed */
Timeout string `` /* 211-byte string literal not displayed */
}
LLM configures the optional, off-by-default summarizer.
type LookupFunc ¶
LookupFunc reads one environment variable.
type Options ¶
type Options struct {
Environ []string
Cwd string
GOOS string // defaults to runtime.GOOS
// ExplicitFile replaces project-file discovery. RELGAP_CONFIG is used when empty.
ExplicitFile string
// StopDir ends the project-file search like a git root does. Empty means the git root.
StopDir string
// FlagKeys maps flag names to config keys. Only flags the user set are applied.
Flags *pflag.FlagSet
FlagKeys map[string]string
}
Options controls Load.
type Policy ¶
type Policy struct {
FailOn []string `` /* 244-byte string literal not displayed */
MaxBehind string `` /* 170-byte string literal not displayed */
MinConfidence float64 `` /* 176-byte string literal not displayed */
VulnSeverity string `` /* 204-byte string literal not displayed */
}
Policy holds CI defaults for --fail-on and related flags.
type Problem ¶
type Problem = yamlschema.Problem
Problem is one configuration error and where it is.
type Result ¶
type Result struct {
Config Config
Files []File
// UnknownEnv lists ignored RELGAP_* variables that match no key.
UnknownEnv []string
// contains filtered or unexported fields
}
Result is the effective configuration with provenance.
type Scan ¶
type Scan struct {
Roots []string `json:"roots" jsonschema_description:"Directories scanned by drift and pins when no roots are given."`
Exclude []string `json:"exclude" jsonschema_description:"Glob patterns excluded from scanning."`
Detectors Detectors `json:"detectors"`
ExtraFiles []string `` /* 145-byte string literal not displayed */
}
Scan configures pin discovery.
type Source ¶
type Source struct {
Kind SourceKind `json:"kind"`
Name string `json:"name,omitempty"` // path, env var or flag
}
Source is where an effective value came from.
type SourceKind ¶
type SourceKind string
SourceKind says which layer set a value.
const ( SourceDefault SourceKind = "default" SourceUser SourceKind = "user" SourceProject SourceKind = "project" SourceEnv SourceKind = "env" SourceFlag SourceKind = "flag" )
Config layers, lowest precedence first.
type ToolOverride ¶
type ToolOverride struct {
Repo string `` /* 201-byte string literal not displayed */
Host string `` /* 206-byte string literal not displayed */
}
ToolOverride is a local registry entry.
type ValidationError ¶
type ValidationError struct {
Problems []Problem
}
ValidationError lists every Problem found. It unwraps to ErrInvalid.
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string
func (*ValidationError) Header ¶
func (*ValidationError) Header() string
Header introduces the problem list in error output.
func (*ValidationError) ProblemLines ¶
func (e *ValidationError) ProblemLines() []string
ProblemLines returns one line per problem, with its origin and position.
func (*ValidationError) Unwrap ¶
func (*ValidationError) Unwrap() error