configpolicy

package
v1.19.0 Latest Latest
Warning

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

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

Documentation

Overview

Package configpolicy validates configuration with an embedded Rego policy.

A policy produces a document with these (optional) entrypoints:

processed - the input config with defaults injected (required)
errors    - a set/array of fatal error strings (joined into one error)
warnings  - a set/array of non-fatal warning strings

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EvalConfigInto

func EvalConfigInto[T any](ctx context.Context, p *Policy, raw []byte, out *T) ([]string, error)

EvalConfigInto decodes raw config bytes (absent/empty/null → empty object), evaluates the policy with input {"config": <raw>} to inject defaults, and decodes the processed config into out, returning any warnings. The typed unmarshal into out is what enforces field types, so a mistyped option surfaces here rather than in the policy.

func StringSet

func StringSet(v any) []string

StringSet converts a Rego set/array result to a []string, ignoring non-string members and returning nil when empty.

Types

type Policy

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

Policy is an embedded validation policy, compiled once on first use and evaluated repeatedly. Safe for concurrent use.

func New

func New(name, source, query string) *Policy

New returns a Policy for the given module: name is the module filename (and a prefix on infrastructure errors), source is its Rego, and query binds the result document to x (e.g. "data.opa.config = x").

func (*Policy) Compiler

func (p *Policy) Compiler() (*ast.Compiler, error)

Compiler compiles the policy once and returns the reusable result. Exported so callers can run ad-hoc queries against the policy (e.g. drift-guard tests).

func (*Policy) Eval

func (p *Policy) Eval(ctx context.Context, input any) (map[string]any, []string, error)

Eval evaluates the policy against input (any value ast.InterfaceToValue accepts), returning the processed config and warnings; a non-empty set of policy errors is returned as a single error.

Jump to

Keyboard shortcuts

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