config

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: Apache-2.0 Imports: 19 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 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

View Source
const (
	EnvPrefix     = "RELGAP_"
	EnvConfigFile = EnvPrefix + "CONFIG"
)

Environment variable names.

View Source
const (
	AppName         = "relgap"
	UserFileName    = "config.yaml"
	ProjectFileName = ".relgap.yaml"
)
View Source
const SchemaVersion = 1

SchemaVersion is the config schema_version this binary reads.

Variables

View Source
var ErrExists = errors.New("file exists")

ErrExists reports that WriteTemplate found a file at its path.

View Source
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

func EnvKeys() ([]string, error)

EnvKeys returns the config keys that environment variables can set: scalars and string lists.

func EnvVarName

func EnvVarName(key string) string

EnvVarName returns the environment variable for a dotted key: "." and "-" become "_", so cache.ttl is RELGAP_CACHE_TTL.

func FindProjectFile

func FindProjectFile(dir, stopDir string) (string, error)

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

func ValidateFile(path string) error

ValidateFile checks one config file against the schema.

func WriteTemplate added in v0.4.0

func WriteTemplate(path string, force bool) error

WriteTemplate writes Template to path and creates its directory. It replaces an existing file only when force is set.

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.

func Default

func Default() Config

Default returns the built-in configuration. Slices and maps are non-nil so that config show lists every key.

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

type EnvVar struct {
	Name string
	Desc string
}

EnvVar is an environment variable that the binary reads, other than the config keys.

func EnvVars added in v0.6.0

func EnvVars() []EnvVar

EnvVars returns the environment variables relgap reads besides RELGAP_CONFIG and the RELGAP_<KEY> config variables. A test in scripts/gendocs checks the list against the code.

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.

func Locate

func Locate(opts Options) ([]File, error)

Locate returns the user and project config files that Load reads. The project entry has an empty Path when none was found.

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 IgnoreRule

type IgnoreRule struct {
	Tool string `` /* 145-byte string literal not displayed */
	Path string `` /* 143-byte string literal not displayed */
}

IgnoreRule suppresses a tool, optionally only under matching paths.

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

type LookupFunc func(key string) (string, bool)

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.

func Load

func Load(opts Options) (*Result, error)

Load builds the effective configuration.

func (*Result) Keys

func (r *Result) Keys() []string

Keys returns every effective leaf key, sorted.

func (*Result) Raw

func (r *Result) Raw() map[string]any

Raw returns the effective configuration as a nested map.

func (*Result) Source

func (r *Result) Source(key string) Source

Source returns where key's value came from. A key without its own record inherits the source of its nearest parent.

func (*Result) Value

func (r *Result) Value(key string) any

Value returns the effective value of a leaf key.

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.

func (Source) String

func (s Source) String() string

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

Jump to

Keyboard shortcuts

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