configpolicy

package
v1.23.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Every policy is compiled together with util.rego, so a policy can import data.opa.config.util for the helpers shared across the validation policies.

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. Field types the policy does not check are enforced by the typed unmarshal into out, 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