MCPcopy Create free account
hub / github.com/chainloop-dev/chainloop / NewEngine

Function NewEngine

pkg/policies/engine/wasm/engine.go:54–91  ·  view source on GitHub ↗

NewEngine creates a new WASM policy engine with the given options

(opts ...engine.Option)

Source from the content-addressed store, hash-verified

52
53// NewEngine creates a new WASM policy engine with the given options
54func NewEngine(opts ...engine.Option) *Engine {
55 options := engine.ApplyOptions(opts...)
56
57 // Extract WASM-specific options with defaults
58 executionTimeout := options.ExecutionTimeout
59 if executionTimeout == 0 {
60 executionTimeout = 5 * time.Second
61 }
62
63 logger := options.Logger
64 if logger == nil {
65 noopLogger := zerolog.Nop()
66 logger = &noopLogger
67 }
68
69 // Set WASM plugin log level exactly once across all engine instances.
70 // extism.SetLogLevel modifies global state and is not safe for concurrent calls.
71 setLogLevelOnce.Do(func() {
72 switch {
73 case logger.GetLevel() <= zerolog.TraceLevel:
74 extism.SetLogLevel(extism.LogLevelTrace)
75 case logger.GetLevel() <= zerolog.DebugLevel:
76 extism.SetLogLevel(extism.LogLevelDebug)
77 case logger.GetLevel() <= zerolog.InfoLevel:
78 extism.SetLogLevel(extism.LogLevelInfo)
79 case logger.GetLevel() <= zerolog.WarnLevel:
80 extism.SetLogLevel(extism.LogLevelWarn)
81 default:
82 extism.SetLogLevel(extism.LogLevelError)
83 }
84 })
85
86 return &Engine{
87 executionTimeout: executionTimeout,
88 logger: logger,
89 CommonEngineOptions: options.CommonEngineOptions,
90 }
91}
92
93// Verify executes a WASM policy against the provided input
94func (e *Engine) Verify(ctx context.Context, policy *engine.Policy, input []byte, args map[string]any) (*engine.EvaluationResult, error) {

Callers 7

executeScriptMethod · 0.92
TestNewEngineFunction · 0.70
TestMatchesParametersFunction · 0.70
TestMatchesEvaluationFunction · 0.70
TestSimpleWASMExecutionFunction · 0.70
TestFilesystemIsolationFunction · 0.70

Calls 2

ApplyOptionsFunction · 0.92
DoMethod · 0.80

Tested by 6

TestNewEngineFunction · 0.56
TestMatchesParametersFunction · 0.56
TestMatchesEvaluationFunction · 0.56
TestSimpleWASMExecutionFunction · 0.56
TestFilesystemIsolationFunction · 0.56