Documentation
¶
Overview ¶
Package validate infers validation rules from key name suffixes and runs them against parsed values. The suffix table is also the source of truth for masking, so that `show`, `diff --values`, and `validate` all agree on which keys are sensitive.
Index ¶
Constants ¶
const Masked = "****"
Masked is the canonical masked representation used across all commands.
Variables ¶
var Rules = []*Rule{ { Name: "url", Suffixes: []string{"_URL", "_URI"}, Validate: validateURL, }, { Name: "port", Suffixes: []string{"_PORT"}, Validate: validatePort, }, { Name: "secret", Suffixes: []string{"_KEY", "_SECRET", "_TOKEN", "_PASSWORD"}, Validate: validateNonEmpty, Mask: true, }, { Name: "email", Suffixes: []string{"_EMAIL", "_ADDRESS"}, Validate: validateEmail, }, { Name: "bool", Suffixes: []string{"_ENABLED", "_DEBUG", "_FLAG"}, Validate: validateBool, }, }
Rules is the ordered list of known validation rules. The order determines matching priority when a key could in principle match multiple rules; more specific suffixes should appear earlier.
Functions ¶
func CountErrors ¶
CountErrors returns the number of results with a non-nil Err.
func ShouldMask ¶
ShouldMask reports whether values for the given key should be masked when displayed. It is safe to call with any key; unmatched keys return false.
Types ¶
type Input ¶
Input is a single key/value to validate. It is decoupled from parser.Entry so that this package stays independent of the parser.
type Result ¶
type Result struct {
Key string
Value string
Rule *Rule // nil when no rule matched
Err error // nil when the value passed, or when no rule matched
}
Result is the outcome for one key.
type Rule ¶
type Rule struct {
Name string // short identifier, e.g. "url"
Suffixes []string // uppercase suffixes, e.g. ["_URL", "_URI"]
Validate func(string) error // required; run against each matched value
Mask bool // true when the value is sensitive
}
Rule classifies a key by one or more case-insensitive suffixes, provides a validation function, and records whether values for matched keys should be masked when displayed.