validate

package
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BetterStatus

BetterStatus returns whichever of a or b has higher priority. Priority order: valid > needs_validation > revoked > unknown > invalid > error > "". This is used for rolling up per-component validation results into an overall finding-level status for composite rules.

func CacheKey

func CacheKey(ruleID, secret string, auxiliary map[string]string) string

TODO maybe rename this to "components" and collapse secret into it too

Types

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

Cache prevents duplicate HTTP requests for the same rule+secret combination. It uses singleflight to coalesce concurrent requests for the same key so that only one goroutine performs the actual evaluation.

func NewCache

func NewCache() *Cache

func (*Cache) GetOrDo

func (c *Cache) GetOrDo(key string, fn func() (*Result, error)) (*Result, error)

GetOrDo looks up key in the cache. On a hit it returns the cached result. On a miss it calls fn exactly once (even if many goroutines race on the same key) and caches non-error results before returning.

func (*Cache) Hits

func (c *Cache) Hits() uint64

Hits returns the total number of cache hits.

func (*Cache) Misses

func (c *Cache) Misses() uint64

Misses returns the total number of cache misses.

type Pool

type Pool struct {
	Debug bool

	// Emit receives fully-resolved, enriched findings.
	// Pool never synchronizes or retries around this callback; callers must make
	// it safe for concurrent worker use.
	Emit func(report.Finding)
	// contains filtered or unexported fields
}

Pool manages a set of workers that validate findings asynchronously.

func NewPool

func NewPool(workers int, runtime *exprruntime.Runtime) *Pool

NewPool creates a validation pool with the given number of workers.

func (*Pool) Close

func (p *Pool) Close()

Close signals that no more jobs will be submitted and waits for all workers to finish.

func (*Pool) Stats

func (p *Pool) Stats() (hits, misses uint64)

Stats returns cache hit/miss counts. Must be called after Close().

func (*Pool) Submit

func (p *Pool) Submit(finding report.Finding, program exprruntime.Program)

Submit queues a job for validation. RequiredSets (if any) are already on the finding.

func (*Pool) SubmitContext

func (p *Pool) SubmitContext(ctx context.Context, finding report.Finding, program exprruntime.Program) error

SubmitContext queues a job for validation unless the provided context has already been canceled.

type Result

type Result struct {
	Status   report.ValidationStatus // valid, invalid, revoked, unknown, error
	Reason   string                  // human-readable explanation
	Metadata map[string]any          // extra fields from the validation result map
}

Result holds the outcome of a validation expression evaluation.

func ParseResult

func ParseResult(val any) *Result

ParseResult interprets the expression output value into a Result.

Jump to

Keyboard shortcuts

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