Documentation
¶
Overview ¶
Package util holds small helpers shared across packages so a single implementation is imported everywhere rather than duplicated.
Index ¶
- Variables
- func DefaultStatePath() (string, error)
- func Fingerprint(cluster, scanner, rule string) string
- func Float64(v any) (float64, bool)
- func Median(vals []float64) float64
- func Plural(n int) string
- func SanitizeName(name string) string
- func SeverityAtLeast(got, want string) bool
- func SeverityRank(s string) int
- func Truncate(s string, n int) string
Constants ¶
This section is empty.
Variables ¶
var ErrStatePath = errors.New("no default state directory")
ErrStatePath indicates no default state directory can be derived for this user.
Functions ¶
func DefaultStatePath ¶ added in v0.16.0
DefaultStatePath returns the file fleetsweeper keeps its scan store in when none is named: $XDG_STATE_HOME/fleetsweeper/fleet.db when XDG_STATE_HOME is absolute, else ~/.local/state/fleetsweeper/fleet.db, and the user config directory on Windows.
func Fingerprint ¶
Fingerprint returns a stable hex identifier for a finding, derived from the cluster, scanner, and rule separated by null bytes. The rule names the check rather than its wording, so a finding keeps its fingerprint when a count in its title changes. Acknowledgements key on the same value, so a finding can be matched to its ack and tracked across scans by fingerprint.
func Float64 ¶ added in v0.13.0
Float64 converts a numeric value to float64. It accepts the float64 that JSON decoding produces and the float32 and int variants hand-built maps carry, and reports false for anything else.
func Median ¶ added in v0.13.0
Median returns the median of vals without reordering it, averaging the middle pair for an even count. It returns 0 for empty input.
func SanitizeName ¶ added in v0.10.0
SanitizeName returns a DNS-1123-safe rendering of name suitable for use as a Kubernetes metadata.name value. It lowercases, replaces runs of invalid characters with a dash, collapses adjacent dashes, caps the result at 253 characters, and trims dashes and dots from both ends so the name starts and ends alphanumeric. Pass any fixed prefix as part of name so the cap covers it.
func SeverityAtLeast ¶ added in v0.10.0
SeverityAtLeast reports whether got meets the want threshold. An empty want always passes.
func SeverityRank ¶ added in v0.10.0
SeverityRank assigns a numeric weight to a severity string for comparison. Unknown values rank 0.
Types ¶
This section is empty.