glide

package module
v0.0.0-...-e133e7a Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

README

glide

Read these first:

Getting started

We recommend installing GraphViz:

brew install graphviz

Run an example (piping the output to GraphViz for visualisation):

go run cmd/main.go run -f examples/basic/workflow.yml -s examples/basic/schema.json -i examples/basic/input.json | dot -Tpng > example.png

Documentation

Index

Constants

View Source
const DefaultMaxDepth = 10

DefaultMaxDepth is the default maximum depth that statements can be nested in Glide workflows. It can be customised by setting 'MaxDepth' on the Compiler.

Variables

This section is empty.

Functions

func Use

Use a specified Glide dialect.

Types

type Compiler

type Compiler struct {
	Program     *Program
	InputSchema *jsoncel.Schema
	// MaxDepth is set to 10 by default if not provided.
	MaxDepth int
}

func (*Compiler) Compile

func (c *Compiler) Compile() (*Graph, error)

Compile statements into an execution graph.

type Completer

type Completer interface {
	Complete(input any) (bool, error)
}

type Graph

type Graph struct {
	// G is the underlying graph data structure.
	G graph.Graph[string, step.Step]
	// contains filtered or unexported fields
}

func NewGraph

func NewGraph() *Graph

func (*Graph) Execute

func (g *Graph) Execute(start string, input map[string]any) (*Result, error)

Execute a policy graph. The 'start' argument is the ID of a node to start execution from.

type InputMap

type InputMap struct {
	// The flattened mapping - e.g. 'group.id' -> 'test'
	Data map[string]any
}

InputMap is a map of flattened input keys to their corresponding values, e.g.

'group.id' -> 'test'

Used as the input for CEL evaluation, because CEL requires keys to be dot separated.

func NewInputMap

func NewInputMap(key string, data map[string]any) *InputMap

NewInputMap creates a new input map. The 'key' field is the root name of the input - such as 'input'.

type Path

type Path struct {
	Steps []step.Step
	// contains filtered or unexported fields
}

Path is a group of statements. Each pass in a Glide program builds the workflow graph from Start nodes to End nodes.

func (*Path) UnmarshalYAML

func (p *Path) UnmarshalYAML(ctx context.Context, b []byte) error

type Program

type Program struct {
	Workflow map[string]Path
}

Program is a Glide workflow definition.

func NewProgram

func NewProgram() *Program

func SimpleProgram

func SimpleProgram(statements ...step.Step) *Program

SimpleProgram creates a program with one 'default' pass only.

func Unmarshal

func Unmarshal(data []byte, dialect dialect.Dialect) (*Program, error)

Unmarshal a glide workflow YAML file into a program which can be compiled.

func (*Program) Pass

func (p *Program) Pass(name string, statements ...step.Step) *Program

Pass adds a pass to the workflow. Used to build test Programs.

func (*Program) UnmarshalYAML

func (p *Program) UnmarshalYAML(ctx context.Context, b []byte) error

type Result

type Result struct {
	// CG is the Completion Graph.
	// The Completion Graph contains the same vertices as the policy graph,
	// but only contains edges between nodes that are complete.
	CG graph.Graph[string, step.Step]

	// A map of vertex hashes to their corresponding state.
	State map[string]State

	// Outcome is the end state of the workflow.
	// If empty, the workflow is considered in an indeterminate, ongoing state.
	Outcome string
}

Result of a workflow execution

type State

type State int
const (
	Inactive State = iota
	Complete
	Active
)

func (State) String

func (s State) String() string

type VisitOpts

type VisitOpts struct {
	Statement *step.Step
	G         *Graph
	Index     int
	// Depth starts at 0 and increases as
	// visitStatement() is recursively called
	// to visit child nodes.
	//
	// e.g.
	//	- and:	<- depth = 0
	//	  - A	<- depth = 1
	//	  - or:	<- depth = 1
	//		- B	<- depth = 2
	//		- C	<- depth = 2
	Depth int
	// MaxDepth is the depth which cannot be exceeded by the compiler.
	// Prevents users creating large nested resources to exhaust server resources.
	MaxDepth int
	Env      *cel.Env // the CEL env

	// NumStatements is the number of statements in the workflow.
	// When visiting this is used to assert that an End node MUST be at
	// the end of a workflow only.
	NumStatements int

	Parent   *step.Step
	Previous *step.Step
}

Directories

Path Synopsis
cmd
pkg
dialect
Package dialect contain definitions for Glide dialects.
Package dialect contain definitions for Glide dialects.
dialect/cf
Package cf contains the Common Fate dialect of Glide.
Package cf contains the Common Fate dialect of Glide.
jsoncel
Package jsoncel implements a CEL Type Provider for JSON schema documents.
Package jsoncel implements a CEL Type Provider for JSON schema documents.
noderr
Package noderr contains an error definition for compile and lint errors.
Package noderr contains an error definition for compile and lint errors.
step/s
package 's' contains helper methods for building steps.
package 's' contains helper methods for building steps.

Jump to

Keyboard shortcuts

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