engine

package
v0.12.1 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2022 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var FailedToCompile = errors.New("Failed to compile rules")

FailedToCompile indicates that more than the maximum number of errors occurred during the compilation stage.

View Source
var FailedToLoadRegoAPI = errors.New("Failed to load the snyk Rego API")

FailedToLoadRegoAPI indicates that an error occurred while initializing the snyk Rego API.

View Source
var FailedToLoadRules = errors.New("Failed to load rules")

FailedToLoadRules indicates that an error occurred while consuming the rego and data producers provided to the engine.

Functions

This section is empty.

Types

type Engine

type Engine struct {
	// contains filtered or unexported fields
}

Engine is responsible for evaluating some States with a given set of rules.

func NewEngine

func NewEngine(ctx context.Context, options *EngineOptions) (*Engine, error)

NewEngine constructs a new Engine instance.

func (*Engine) Eval

func (e *Engine) Eval(ctx context.Context, options *EvalOptions) *models.Results

Eval evaluates the given states using the rules that the engine was initialized with.

func (*Engine) Metadata

func (e *Engine) Metadata(ctx context.Context) []MetadataResult

Metadata returns the metadata of all Policies that have been loaded into this Engine instance.

type EngineOptions

type EngineOptions struct {
	// Providers contains functions that produce parsed OPA modules or data documents.
	Providers []data.Provider
	// RuleIDs determines which rules are executed. When this option is empty or
	// unspecified, all rules will be run.
	RuleIDs map[string]bool
	// Logger is an optional instance of the logger.Logger interface
	Logger logging.Logger
	// Metrics is an optional instance of the metrics.Metrics interface
	Metrics metrics.Metrics
}

EngineOptions contains options for initializing an Engine instance

type EvalOptions

type EvalOptions struct {
	// Inputs are the State instances that the engine should evaluate.
	Inputs  []models.State
	Workers int
	// ResourceResolver is a function that returns a resource state for the given
	// ResourceRequest.
	// Multiple ResourcesResolvers can be composed with And() and Or().
	ResourcesResolver policy.ResourcesResolver
}

EvalOptions contains options for Engine.Eval

type MetadataResult

type MetadataResult struct {
	Package  string          `json:"package"`
	Metadata policy.Metadata `json:"metadata"`
	Error    string          `json:"error,omitempty"`
}

type PolicyConsumer

type PolicyConsumer struct {
	Modules      map[string]*ast.Module
	Document     map[string]interface{}
	NumDocuments int
}

PolicyConsumer is an implementation of the data.Consumer interface that stores parsed modules, policies, and documents in-memory.

func NewPolicyConsumer

func NewPolicyConsumer() *PolicyConsumer

func (*PolicyConsumer) DataDocument

func (c *PolicyConsumer) DataDocument(
	_ context.Context,
	path string,
	document map[string]interface{},
) error

func (*PolicyConsumer) Module

func (c *PolicyConsumer) Module(
	ctx context.Context,
	path string,
	module *ast.Module,
) error

Jump to

Keyboard shortcuts

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