evaluator

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2026 License: MPL-2.0 Imports: 16 Imported by: 0

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 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 Jsonnet files and 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), signature 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 JsonnetVM

type JsonnetVM interface {
	ExtCode(key, val string)
	Importer(importer jsonnet.Importer)
	EvaluateAnonymousSnippet(filename, snippet string) (string, error)
}

JsonnetVM provides an interface for Jsonnet virtual machine operations. It abstracts the underlying Jsonnet VM implementation to enable testing and dependency injection. The interface supports setting external code, configuring importers, and evaluating Jsonnet snippets.

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), signature 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), signature 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 {
	ReadFile      func(string) ([]byte, error)
	JsonMarshal   func(any) ([]byte, error)
	JsonUnmarshal func([]byte, any) error
	YamlMarshal   func(any) ([]byte, error)
	YamlUnmarshal func([]byte, any) error
	FilepathBase  func(string) string
	LookupEnv     func(string) (string, bool)
	NewJsonnetVM  func() JsonnetVM
}

Shims provides mockable wrappers around system and runtime functions

func NewShims

func NewShims() *Shims

NewShims creates a new Shims instance with default implementations

Jump to

Keyboard shortcuts

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