runner

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildVariables

func BuildVariables(optsFn ...VarBuilderOption) (map[string]any, error)

BuildVariables provides a mechanism to populate the variables map that can be exposed in the CEl environment. The function takes functional options to define the SBOMs that are made available to the evaluator passing protobom Documents or paths to native SBOMs:

vars, err := BuildVariables(
   WithPaths([]string{"sbom1.spdx.json", "sbom2.cdx.json"}),
   WithDocuments(sbom.NewDocument())
)

func CreateEnvironment

func CreateEnvironment(opts *Options) (*cel.Env, error)

CreateEnvironment creates a CEL environment with the protobom library loaded.

Types

type Implementation

type Implementation interface {
	ReadStream(io.Reader) (string, error)
	Compile(*cel.Env, string) (*cel.Ast, error)
	Evaluate(*cel.Env, *cel.Ast, map[string]any) (ref.Val, error)
}

type Options

type Options struct {
	EnvOptions []cel.EnvOption
}

type Runner

type Runner struct {
	Environment *cel.Env
	// contains filtered or unexported fields
}

func NewRunner

func NewRunner() (*Runner, error)

func NewRunnerWithOptions

func NewRunnerWithOptions(opts *Options) (*Runner, error)

func (*Runner) Evaluate

func (r *Runner) Evaluate(code string, variables map[string]any) (ref.Val, error)

Evaluate evaluates the CEL `code“ passed as a string predefining the variaables passed in `variables`. The function returns the raw ref.Val meaning that any cel expression returning an error will not return err but will set the err in the return value.

type VarBuilderOption

type VarBuilderOption func(*varBuilderOptions)

func WithDocuments

func WithDocuments(docs []*sbom.Document) VarBuilderOption

func WithPaths

func WithPaths(paths []string) VarBuilderOption