evaluator

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: MPL-2.0 Imports: 14 Imported by: ? 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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContainsExpression

func ContainsExpression(value any) bool

ContainsExpression determines whether the provided value is a string that contains an unresolved expression. An expression is identified by the pattern "${...}" anywhere in the string. This function returns true if the value is a string containing at least one properly closed "${...}" expression pattern, and false otherwise. Used to identify values containing unresolved expressions that should be skipped when evaluateDeferred is false.

func DeferredExpression

func DeferredExpression(value any) (string, bool)

DeferredExpression returns the preserved raw expression string when value is DeferredValue.

func ExpressionBody

func ExpressionBody(value string) (string, bool)

ExpressionBody returns the inner expression for ${ ... } inputs. Double-brace ${{ ... }} inputs are not matched; callers should normalize those first. When value is not wrapped as a full expression, returns the original trimmed string and false.

func IsDeferredValue

func IsDeferredValue(value any) bool

IsDeferredValue reports whether value is a DeferredValue (value or pointer form).

Types

type DefaultExpressionEvaluator added in v0.10.0

type DefaultExpressionEvaluator struct {
	Shims *Shims
	// contains filtered or unexported fields
}

DefaultExpressionEvaluator is the concrete implementation of ExpressionEvaluator.

func (*DefaultExpressionEvaluator) Evaluate added in v0.10.0

func (e *DefaultExpressionEvaluator) Evaluate(s string, facetPath string, scope map[string]any, evaluateDeferred bool) (any, error)

Evaluate resolves the Windsor expressions in s, both whole and interpolated ${...} expressions. It loads files as necessary. It defers unresolved expressions when evaluateDeferred is false. facetPath is the base for relative paths. When scope is nil, the environment is the enriched config. Otherwise it is scope plus the runtime keys. It returns the evaluated value, or an error when evaluation fails or the input is malformed.

func (*DefaultExpressionEvaluator) EvaluateMap added in v0.10.0

func (e *DefaultExpressionEvaluator) EvaluateMap(values map[string]any, facetPath string, scope map[string]any, evaluateDeferred bool) (map[string]any, error)

EvaluateMap evaluates a map of values using this expression evaluator. Each string value is evaluated as an expression; maps and arrays are recursively evaluated. When evaluateDeferred is false and evaluation fails with a DeferredError, the original value is preserved in the result. Environment is determined by scope the same way as Evaluate (nil = enriched config, non-nil = that scope with runtime keys). Returns a new map containing evaluated values, or an error if evaluation fails with a non-deferred error.

func (*DefaultExpressionEvaluator) Register added in v0.10.0

func (e *DefaultExpressionEvaluator) Register(name string, helper func(params []any, deferred bool) (any, error), signatures ...any)

Register adds a custom helper function to the evaluator for expression evaluation. The provided helper function receives the deferred flag as a closure variable. The name parameter specifies the function name used in expressions, helper is the custom function, and signatures define the helper's input/output signatures. Pass one signature per accepted argument count. This allows providers and consumers to extend evaluator capabilities with domain-specific helpers.

func (*DefaultExpressionEvaluator) SetConfigScope added in v0.10.0

func (e *DefaultExpressionEvaluator) SetConfigScope(scope map[string]any)

SetConfigScope publishes the composed scope (facet config blocks merged over context config) that a nil-scope evaluation should use as its base. The composer calls this after composition so apply-time consumers — secret resolution in particular — dereference computed config values the same way substitutions do. Passing nil clears it, reverting nil-scope evaluations to context config alone.

func (*DefaultExpressionEvaluator) SetEnvLookup added in v0.10.0

func (e *DefaultExpressionEvaluator) SetEnvLookup(lookup func(name string) (string, bool))

SetEnvLookup replaces the source that env() expressions resolve against. The test runner uses this to supply a hermetic environment so composition never reads the host env.

func (*DefaultExpressionEvaluator) SetTemplateData added in v0.10.0

func (e *DefaultExpressionEvaluator) SetTemplateData(templateData map[string][]byte)

SetTemplateData sets the template data map for in-memory file resolution. This is used when loading blueprints from OCI artifacts where template files are stored in memory rather than on disk. The map keys should use paths relative to the template root, typically prefixed with "_template/".

type DeferredError

type DeferredError = secretsRuntime.DeferredError

DeferredError signals that an expression is deferred and should be preserved for later evaluation. This is not an error condition but a signal that the expression cannot be evaluated at this time.

type DeferredValue

type DeferredValue struct {
	Expression string
}

DeferredValue represents a value that could not be fully resolved because one or more deferred helpers (for example terraform_output) were unavailable at evaluation time. Expression stores the raw expression text preserved for later resolution.

type ExpressionEvaluator

type ExpressionEvaluator interface {
	HelperRegistrar
	SetTemplateData(templateData map[string][]byte)
	SetEnvLookup(lookup func(name string) (string, bool))
	SetConfigScope(scope map[string]any)
	Evaluate(expression string, facetPath string, scope map[string]any, evaluateDeferred bool) (any, error)
	EvaluateMap(values map[string]any, facetPath string, scope map[string]any, evaluateDeferred bool) (map[string]any, error)
}

ExpressionEvaluator provides unified expression evaluation for the Runtime system. It uses the config handler for accessing configuration values and supports dynamic value resolution through the provider system. The evaluator handles expression compilation, evaluation, and string interpolation with support for file loading functions.

func NewExpressionEvaluator

func NewExpressionEvaluator(configHandler config.ConfigHandler, projectRoot, templateRoot string) ExpressionEvaluator

NewExpressionEvaluator creates a new expression evaluator with the provided dependencies. The configHandler is used for accessing configuration values and provider resolution. The projectRoot and templateRoot paths are used for resolving relative file paths in expressions. Returns a fully initialized evaluator ready for use.

type HelperRegistrar

type HelperRegistrar interface {
	Register(name string, helper func(params []any, deferred bool) (any, error), signatures ...any)
}

HelperRegistrar defines the interface for registering custom helpers with the evaluator. This allows providers to extend expression evaluation capabilities without the evaluator needing to know about provider-specific functionality.

type MockExpressionEvaluator

type MockExpressionEvaluator struct {
	SetTemplateDataFunc func(templateData map[string][]byte)
	SetEnvLookupFunc    func(lookup func(name string) (string, bool))
	SetConfigScopeFunc  func(scope map[string]any)
	RegisterFunc        func(name string, helper func(params []any, deferred bool) (any, error), signatures ...any)
	EvaluateFunc        func(expression string, facetPath string, scope map[string]any, evaluateDeferred bool) (any, error)
	EvaluateMapFunc     func(values map[string]any, facetPath string, scope map[string]any, evaluateDeferred bool) (map[string]any, error)
}

MockExpressionEvaluator is a mock implementation of the ExpressionEvaluator interface for testing purposes. It provides a way to simulate expression evaluation without executing actual evaluation logic. It allows for controlled testing of evaluator-dependent functionality by providing mock implementations of all ExpressionEvaluator interface methods.

func NewMockExpressionEvaluator

func NewMockExpressionEvaluator() *MockExpressionEvaluator

NewMockExpressionEvaluator creates a new instance of MockExpressionEvaluator.

func (*MockExpressionEvaluator) Evaluate

func (m *MockExpressionEvaluator) Evaluate(expression string, facetPath string, scope map[string]any, evaluateDeferred bool) (any, error)

Evaluate calls the mock EvaluateFunc if set, otherwise returns nil, nil.

func (*MockExpressionEvaluator) EvaluateMap

func (m *MockExpressionEvaluator) EvaluateMap(values map[string]any, facetPath string, scope map[string]any, evaluateDeferred bool) (map[string]any, error)

EvaluateMap calls the mock EvaluateMapFunc if set, otherwise returns an empty map and nil error.

func (*MockExpressionEvaluator) Register

func (m *MockExpressionEvaluator) Register(name string, helper func(params []any, deferred bool) (any, error), signatures ...any)

Register calls the mock RegisterFunc if set, otherwise does nothing.

func (*MockExpressionEvaluator) SetConfigScope

func (m *MockExpressionEvaluator) SetConfigScope(scope map[string]any)

SetConfigScope calls the mock SetConfigScopeFunc if set, otherwise does nothing.

func (*MockExpressionEvaluator) SetEnvLookup

func (m *MockExpressionEvaluator) SetEnvLookup(lookup func(name string) (string, bool))

SetEnvLookup calls the mock SetEnvLookupFunc if set, otherwise does nothing.

func (*MockExpressionEvaluator) SetTemplateData

func (m *MockExpressionEvaluator) SetTemplateData(templateData map[string][]byte)

SetTemplateData calls the mock SetTemplateDataFunc if set, otherwise does nothing.

type Shims

type Shims struct {
	shims.Shims
}

Shims holds the shared system call primitives.

func NewShims

func NewShims() *Shims

NewShims returns a Shims with every field set to its real implementation.

Jump to

Keyboard shortcuts

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