Help us shape the future of Go! Take the 2026 Go Developer Survey

eval

package
v0.22.0-test2 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: Apache-2.0, Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package eval is SPEC §8 as a pure function: order-independent evaluation of a compiled policy against one (user, host, account) request. It knows nothing about HTTP, OIDC, or inventories — the caller resolves the request tuple and passes resolvers for flags (`when`) and facts (`require`).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GlobMatch

func GlobMatch(pattern, s string) bool

GlobMatch matches writ globs: `*` and `?` only — no character classes, no `**`. `*` matches any run of bytes including dots (host names are writ registrations, not DNS labels, so there is no hierarchy for a glob to respect). Comparison is byte-exact, so `?` matches one byte. Exported for inventory implementations that match host names against configured patterns with the language's glob semantics.

Types

type Decision

type Decision struct {
	Outcome   Outcome
	Reason    string
	TTL       time.Duration
	DenyRule  *il.DenyRule
	Allowed   []*il.AllowRule
	PendingOn []string
}

Decision is the evaluation result. TTL is the minimum across satisfied allows that set one; zero means the deployment default. DenyRule is set when a deny rule fired; Allowed carries the satisfied allows (for notify and audit); PendingOn names the requirements a Pending outcome waits on.

func Decide

func Decide(p *il.Policy, req Request, now time.Time, flags FlagFunc, facts FactFunc) (Decision, error)

Decide evaluates policy p for req at instant now. It implements SPEC §8 steps 1–7; file order never matters. Any resolver error is returned as-is — the caller must fail closed (500), never treat it as a non-match.

type FactFunc

type FactFunc func(name string) (FactState, error)

FactFunc resolves a `require` fact through the three-state resolver. An error fails the evaluation closed. Request-scoped caching and fast-before-side-effecting ordering are the resolver's business.

type FactState

type FactState int

FactState is the three-state result of a `require` fact resolver.

const (
	FactUnknown FactState = iota // unstarted — pends
	FactSatisfied
	FactUnsatisfied
	FactPending
)

type FlagFunc

type FlagFunc func(name string) (bool, error)

FlagFunc resolves a `when` flag: synchronous, two-state, never pending. An error fails the evaluation closed.

type Host

type Host struct {
	Name     string
	Labels   map[string]string
	Accounts []string
}

Host is a resolved host. Name must already have passed il.HostName. Accounts is the grounding list: nil means no account inventory was reported and account expressions match the requested name directly (ungrounded); non-nil means grounded matching — the requested account must be in the list, and an empty list grounds nothing.

type Outcome

type Outcome int

Outcome is the decision category.

const (
	Deny Outcome = iota
	Issue
	Pending
)

type Request

type Request struct {
	User    *User
	Host    *Host
	Account string // requested account name, verbatim — never case-folded
}

Request is one evaluation request. A nil User or Host is a structural non-match (the SPEC §8 step 1 gates), not an error.

type User

type User struct {
	ID     string
	Active bool
	Groups []string
	Type   string
	Dept   string
	Org    string
}

User is the SCIM-shaped view of a resolved user. ID carries the value of the bound identity attribute.

Jump to

Keyboard shortcuts

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