generator

package
v0.15.7 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2021 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package generator converts Pomerium Policy Language into Rego.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Criterion

type Criterion interface {
	DataType() CriterionDataType
	Name() string
	GenerateRule(subPath string, data parser.Value) (rule *ast.Rule, additionalRules []*ast.Rule, err error)
}

A Criterion generates rego rules based on data.

func NewCriterionFunc

func NewCriterionFunc(
	dataType CriterionDataType,
	name string,
	f func(subPath string, data parser.Value) (rule *ast.Rule, additionalRules []*ast.Rule, err error),
) Criterion

NewCriterionFunc creates a new Criterion from a function.

type CriterionConstructor

type CriterionConstructor func(*Generator) Criterion

A CriterionConstructor is a function which returns a Criterion for a Generator.

type CriterionDataType

type CriterionDataType string

A CriterionDataType describes the expected format of the data to be sent to the criterion.

const (
	// CriterionDataTypeUnknown indicates that the type of data is unknown.
	CriterionDataTypeUnknown CriterionDataType = ""

	// CriterionDataTypeUnused indicates that the data is unused.
	CriterionDataTypeUnused CriterionDataType = "unused"
)

type Generator

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

A Generator generates a rego script from a policy.

func New

func New(options ...Option) *Generator

New creates a new Generator.

func (*Generator) Generate

func (g *Generator) Generate(policy *parser.Policy) (*ast.Module, error)

Generate generates the rego module from a policy.

func (*Generator) GetCriterion

func (g *Generator) GetCriterion(name string) (Criterion, bool)

GetCriterion gets a Criterion for the given name.

func (*Generator) NewRule

func (g *Generator) NewRule(name string) *ast.Rule

NewRule creates a new rule with a dynamically generated name.

type Option

type Option func(*Generator)

An Option configures the Generator.

func WithCriterion

func WithCriterion(criterionConstructor CriterionConstructor) Option

WithCriterion adds a Criterion to the generator's known criteria.

Jump to

Keyboard shortcuts

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