exprruntime

package
v1.8.1 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2026 License: MIT Imports: 39 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultHTTPClient

func DefaultHTTPClient() *http.Client

DefaultHTTPClient returns an HTTP client with reasonable timeouts.

func NeedsCELCompat

func NeedsCELCompat(s string) bool

func ParseValidationEnvAllowlist

func ParseValidationEnvAllowlist(parts []string) map[string]struct{}

ParseValidationEnvAllowlist converts CLI flag fragments into a set of names.

func RewriteCELCompat

func RewriteCELCompat(input string) (string, error)

RewriteCELCompat rewrites the CEL-shaped expression syntax used by existing configs into Expr syntax. It is intentionally narrow; unsupported CEL syntax should fail at Expr compile with both original and rewritten expressions.

Types

type EvalOptions

type EvalOptions struct {
	Debug bool
}

type EvalResult

type EvalResult struct {
	Value           any
	Debug           map[string]any
	RequestLimitHit *ValidationRequestLimitHit
}

type Program

type Program = *compiledProgram

Program is the compiled expression representation used by validation, filters, and prefilters.

type Runtime

type Runtime struct {

	// These endpoints are used for tests, not for real scans.
	STSEndpoint             string
	GCPTokenEndpoint        string
	AzureTokenEndpoint      string
	AzureStorageEndpoint    string
	AzureAppConfigEndpoint  string
	AzureServiceBusEndpoint string
	AllowedEnv              map[string]struct{}
	// contains filtered or unexported fields
}

Runtime holds compiled Expr programs and validation services (if needed).

func New

func New(httpClient *http.Client) (*Runtime, error)

func (*Runtime) CompileFilter

func (e *Runtime) CompileFilter(expression string, tokenizer *tiktoken.Tiktoken) (Program, error)

func (*Runtime) CompilePrefilter

func (e *Runtime) CompilePrefilter(expression string) (Program, error)

func (*Runtime) CompileValidation

func (e *Runtime) CompileValidation(expression string) (Program, error)

func (*Runtime) Eval

func (e *Runtime) Eval(prg Program, finding, captures map[string]string) (any, error)

func (*Runtime) EvalFilter

func (e *Runtime) EvalFilter(prg Program, finding map[string]any, attributes map[string]string) (bool, error)

Compile and runtime bindings expose the same names. Dynamic values are layered onto a shallow copy so compiled programs can share static function bindings.

func (*Runtime) EvalPrefilter

func (e *Runtime) EvalPrefilter(prg Program, attributes map[string]string) (bool, error)

func (*Runtime) EvalValidation

func (e *Runtime) EvalValidation(ctx context.Context, prg Program, finding, captures, attributes map[string]string, opts EvalOptions) (EvalResult, error)

func (*Runtime) EvalValidationWithComponents added in v1.7.4

func (e *Runtime) EvalValidationWithComponents(ctx context.Context, prg Program, finding, captures map[string]string, components map[string]any, attributes map[string]string, opts EvalOptions) (EvalResult, error)

EvalValidationWithComponents evaluates a validation program with structured component findings isolated from the primary rule's named capture groups.

func (*Runtime) EvalWithAttributes

func (e *Runtime) EvalWithAttributes(prg Program, finding, captures, attributes map[string]string) (any, error)

func (*Runtime) EvalWithComponents added in v1.7.4

func (e *Runtime) EvalWithComponents(prg Program, finding, captures map[string]string, components map[string]any) (any, error)

EvalWithComponents evaluates a validation program with primary named regex captures and structured component findings.

func (*Runtime) EvalWithContext

func (e *Runtime) EvalWithContext(ctx context.Context, prg Program, finding, captures, attributes map[string]string) (any, error)

func (*Runtime) SetHTTPClient

func (e *Runtime) SetHTTPClient(c *http.Client)

func (*Runtime) SetTokenizerProvider

func (e *Runtime) SetTokenizerProvider(provider func() *tiktoken.Tiktoken)

func (*Runtime) SetValidationRequestLimits added in v1.7.1

func (e *Runtime) SetValidationRequestLimits(cfg ValidationRequestLimits) error

SetValidationRequestLimits applies request-level validation limits to the Runtime's shared HTTP client.

type ValidationRequestLimitError added in v1.7.1

type ValidationRequestLimitError struct {
	Hit ValidationRequestLimitHit
}

ValidationRequestLimitError is returned by the validation HTTP transport when a target has exhausted its request budget.

func (*ValidationRequestLimitError) Error added in v1.7.1

type ValidationRequestLimitHit added in v1.7.1

type ValidationRequestLimitHit struct {
	RuleID       string
	Target       string
	MaxRequests  int
	RequestsSent int
}

ValidationRequestLimitHit describes a validation request rejected before it reached the provider.

type ValidationRequestLimits added in v1.7.1

type ValidationRequestLimits struct {
	// MaxRequestsPerTarget is the maximum number of requests admitted to each
	// target origin over the lifetime of the Runtime.
	MaxRequestsPerTarget int

	// RequestsPerSecond is the aggregate request rate across all validation
	// targets and rules.
	RequestsPerSecond float64

	// RequestsPerSecondByRule contains exact rule-ID request rates. A rule rate
	// composes with, rather than replaces, RequestsPerSecond.
	RequestsPerSecondByRule map[string]float64
}

ValidationRequestLimits controls outbound validation requests. Zero values disable the corresponding limit.

Jump to

Keyboard shortcuts

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