conds

package
v0.0.0-...-add0f8d Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package conds contains supporting code for conditional bindings.

Used internally by authdb.Snapshot.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

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

Builder is a caching factory of Conditions.

func NewBuilder

func NewBuilder(vocab []*protocol.Condition) *Builder

NewBuilder returns a new builder that uses the given "vocabulary" of elementary conditions when building composite (ANDed) conditions.

This is usually `conditions` field from the Realms proto message. These elementary conditions are referenced by their index in Condition(...) method.

func (*Builder) Condition

func (b *Builder) Condition(indexes []uint32) (*Condition, error)

Condition either constructs a new condition or returns an existing one.

`indexes` are indexes of elementary conditions in the array passed to NewBuilder. The returned condition is an AND of all these elementary conditions. `indexes` are assumed to be ordered already.

Returns nil if the condition would always evaluate to true (in particular if `indexes` is empty).

Returns an error if some index is out of bounds. This should not happen in a valid AuthDB.

type Condition

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

Condition is a predicate on attributes map.

func (*Condition) Eval

func (c *Condition) Eval(ctx context.Context, attrs realms.Attrs) bool

Eval evaluates the condition over given attributes.

func (*Condition) Index

func (c *Condition) Index() int

Index can be used to sort conditions based on the order of their creation.

Indexes are comparable only if conditions came from the same Builder.

Jump to

Keyboard shortcuts

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