evaluator

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const OPAEvaluatorID = "opa"
View Source
const OPAMappingFile = "complytime-mapping.json"

OPAMappingFile is the filename the OPA provider requires in the content directory to map Rego package namespaces to assessment plan requirement IDs.

Variables

View Source
var ErrNotFound = errors.New("evaluator not found")

ErrNotFound is returned when a requested evaluator is not in the registry.

Functions

This section is empty.

Types

type ContractViolation

type ContractViolation struct {
	Path     string // The input.* path that was referenced (e.g., "input.metadata.name")
	Location string // Location in the policy file (e.g., "policy.rego:12:5")
}

ContractViolation represents a policy reference that doesn't exist in the schema.

func (ContractViolation) Error

func (v ContractViolation) Error() string

Error implements the error interface.

type Evaluator

type Evaluator interface {
	// ID returns the unique identifier for this evaluator (e.g., "opa").
	ID() string

	// Validate checks policy syntax and compilation without executing.
	// Returns a list of validation errors (empty if valid).
	Validate(filename string, src string) []error

	// CheckContract validates that all input.* references in the policy
	// exist in the provided CUE schema.
	CheckContract(filename string, src string, schema cue.Value) ([]ContractViolation, error)

	// Test executes policy unit tests.
	// files is a map of filename -> source code.
	Test(ctx context.Context, files map[string]string) (*TestResults, error)

	// Lint performs static analysis and returns style/quality warnings.
	// Returns nil/nil if linting is not available or not applicable.
	Lint(filename string, src string) ([]LintWarning, error)

	// FileExtension returns the expected file extension for this evaluator's policies.
	FileExtension() string

	// RequiredFiles returns filenames that must exist in the content
	// directory alongside policy files for this evaluator to function
	// at scan time (e.g., "complytime-mapping.json" for OPA).
	// Returns nil if no additional files are required.
	RequiredFiles() []string
}

Evaluator defines the interface for policy-language evaluators.

type LintWarning

type LintWarning struct {
	Rule     string // Name of the lint rule that triggered
	Message  string // Human-readable warning message
	Location string // Location in the policy file (e.g., "policy.rego:12:5")
}

LintWarning represents a non-fatal linting issue.

type OPA

type OPA struct{}

OPA implements the Evaluator interface for Open Policy Agent policies.

func (*OPA) CheckContract

func (o *OPA) CheckContract(filename string, src string, schema cue.Value) ([]ContractViolation, error)

func (*OPA) FileExtension

func (o *OPA) FileExtension() string

func (*OPA) ID

func (o *OPA) ID() string

func (*OPA) Lint

func (o *OPA) Lint(filename string, src string) ([]LintWarning, error)

func (*OPA) RequiredFiles added in v0.0.8

func (o *OPA) RequiredFiles() []string

func (*OPA) Test

func (o *OPA) Test(ctx context.Context, files map[string]string) (*TestResults, error)

func (*OPA) Validate

func (o *OPA) Validate(filename string, src string) []error

type Registry

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

Registry maps evaluator IDs to Evaluator implementations. Thread-safe for concurrent access.

func DefaultRegistry

func DefaultRegistry() *Registry

DefaultRegistry creates a registry pre-populated with the OPA evaluator.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates an empty evaluator registry.

func (*Registry) Get

func (r *Registry) Get(id string) (Evaluator, error)

Get retrieves an evaluator by ID. Returns an error if the evaluator is not registered.

func (*Registry) IDs

func (r *Registry) IDs() []string

IDs returns a sorted list of all registered evaluator IDs.

func (*Registry) Register

func (r *Registry) Register(e Evaluator)

Register adds an evaluator to the registry. If an evaluator with the same ID already exists, it is replaced.

type TestResults

type TestResults struct {
	Total  int      // Total number of tests
	Passed int      // Number of passing tests
	Failed int      // Number of failing tests
	Errors []string // Error messages from failing tests
}

TestResults contains policy test execution results.

Jump to

Keyboard shortcuts

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