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 EnvVarName(key string) string
- func FindProjectFile(dir string) (string, error)
- func UserConfigPath(lookup LookupFunc, goos string) (string, error)
- func ValidateFile(path string) error
- type Cache
- type Config
- type Detectors
- type File
- type GitHub
- type IgnoreRule
- 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 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 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 looking for .relgap.yaml. It returns "" when there is none.
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 `` /* 127-byte string literal not displayed */
Policy Policy `json:"policy"`
LLM LLM `json:"llm"`
}
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 `json:"ci_actions" jsonschema_description:"Detect tool versions in CI workflow files."`
Generic bool `json:"generic" jsonschema_description:"Detect NAME_VERSION=x.y.z assignments in extra_files."`
}
Detectors toggles opt-in pin detectors.
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 `` /* 128-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 IgnoreRule ¶
type IgnoreRule struct {
Tool string `json:"tool" jsonschema:"required,minLength=1"`
Path string `` /* 143-byte string literal not displayed */
}
IgnoreRule suppresses a tool, optionally only under matching paths.
type LLM ¶
type LLM struct {
Provider string `` /* 149-byte string literal not displayed */
Model string `json:"model"`
BaseURL string `json:"base_url"`
APIKeyEnv string `` /* 191-byte string literal not displayed */
AWSProfile string `json:"aws_profile"`
MaxInputTokens int `json:"max_input_tokens" jsonschema:"minimum=1"`
}
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
// 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 `json:"fail_on" jsonschema:"enum=breaking,enum=deprecation,enum=eol,enum=vuln,enum=drift,enum=outdated"`
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 `json:"extra_files" jsonschema_description:"Extra glob patterns scanned by the generic detector."`
}
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 `json:"repo" jsonschema:"required,pattern=^[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+$" jsonschema_description:"GitHub owner/repo."`
}
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