pipeline

package
v1.0.64 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2025 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OutputFormatYaml       = OutputFormat("yaml")
	OutputFormatJson       = OutputFormat("json")
	OutputFormatProperties = OutputFormat("properties")
	OutputFormatText       = OutputFormat("text")
)
View Source
const (
	AttributeNode = "Attrs"
	ValueNode     = "Value"

	// Html2DomLayoutDefault will produce "Value" leaf for every text node.
	// Child elements are collected into the list, if their name appears multiple times within the parent,
	// otherwise they are regular child node.
	// Attributes of element are put into container node "Attrs".
	// Namespaces are ignored.
	Html2DomLayoutDefault = Html2DomLayout("default")
)
View Source
const (
	SetStrategyReplace = SetStrategy("replace")
	SetStrategyMerge   = SetStrategy("merge")
)

Variables

View Source
var (
	ErrNoDataToSet   = errors.New("no data to set")
	ErrTemplateEmpty = errors.New("template cannot be empty")
	ErrPathEmpty     = errors.New("path cannot be empty")
	ErrFileEmpty     = errors.New("file cannot be empty")
	ErrOutputEmpty   = errors.New("output cannot be empty")
	ErrNotContainer  = errors.New("data element must be container when no path is provided")
)

Functions

This section is empty.

Types

type AbortOp added in v1.0.43

type AbortOp struct {
	Message string `yaml:"message" clone:"template"`
}

func (*AbortOp) CloneWith added in v1.0.43

func (ao *AbortOp) CloneWith(ctx ActionContext) Action

func (*AbortOp) Do added in v1.0.43

func (ao *AbortOp) Do(ctx ActionContext) error

func (*AbortOp) String added in v1.0.43

func (ao *AbortOp) String() string

type Action

type Action interface {
	fmt.Stringer
	// Do will perform this action.
	// This function is invoked by Executor implementation and as such it's not meant to be called by end user directly.
	Do(ctx ActionContext) error
	Cloneable
}

Action is implemented by actions within ActionSpec

type ActionContext

type ActionContext interface {
	// Data exposes data document
	Data() dom.ContainerBuilder
	// Snapshot is read-only view of Data() in point in time
	Snapshot() map[string]interface{}
	// Factory give access to factory to create new documents
	Factory() dom.ContainerFactory
	// Executor returns reference to executor
	Executor() Executor
	// TemplateEngine return reference to TemplateEngine
	TemplateEngine() TemplateEngine
	// Action return reference to actual Action
	Action() Action
	// Logger gets reference to Logger interface
	Logger() Logger
	// Ext allows access to extensions interface
	Ext() ExtInterface
}

ActionContext is created by Executor implementation for sole purpose of invoking Action's Do function.

type ActionFactory added in v1.0.64

type ActionFactory interface {
	// NewForArgs creates new instance of Action for given set of arguments.
	NewForArgs(args map[string]interface{}) Action
}

ActionFactory can be used to create instances of Action

type ActionMeta

type ActionMeta struct {
	// Name of this step, should be unique within current scope
	Name string `yaml:"name,omitempty"`

	// Optional ordinal number that controls order of execution within parent step
	Order int `yaml:"order,omitempty"`

	// Optional expression to make execution of this action conditional.
	// Execution of this step is skipped when this expression is evaluated to false.
	// If value of this field is omitted, then this action is executed.
	When *string `yaml:"when,omitempty"`
}

ActionMeta holds action's metadata used by Executor

func (ActionMeta) String

func (am ActionMeta) String() string

type ActionSpec

type ActionSpec struct {
	ActionMeta `yaml:",inline"`
	// Operations to perform
	Operations OpSpec `yaml:",inline"`
	// Children element is an optional map of child actions that will be executed
	// as a part of this action (after any of OpSpec in Operations are performed).
	// Exact order of execution is given by Order field value (lower the value, sooner the execution will take place).
	Children ChildActions `yaml:"steps,omitempty"`
}

func (ActionSpec) CloneWith

func (s ActionSpec) CloneWith(ctx ActionContext) Action

func (ActionSpec) Do

func (s ActionSpec) Do(ctx ActionContext) error

func (ActionSpec) String

func (s ActionSpec) String() string

type AnyVal added in v1.0.64

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

AnyVal can represent any DOM value (leaf, list, container)

func (*AnyVal) UnmarshalYAML added in v1.0.64

func (pv *AnyVal) UnmarshalYAML(node *yaml.Node) error

func (*AnyVal) Value added in v1.0.64

func (pv *AnyVal) Value() dom.Node

Value get actual value

type ArgsSetter added in v1.0.64

type ArgsSetter interface {
	// SetArgs sets arguments from map
	SetArgs(args map[string]interface{})
}

ArgsSetter is implemented by ext Action if it wishes to receive arguments.

type CallOp added in v1.0.64

type CallOp struct {
	// Name is name of callable previously registered using DefineOp.
	// Attempt to use name that was not registered will result in error
	Name string
	// ArgsPath is optional path within the global data where arguments are stored prior to execution.
	// When omitted, then default value of "args" is assumed. Note that passing arguments to nested callable
	// is only possible if path is different, otherwise inner's arguments will overwrite outer's one.
	// Template is accepted as possible value.
	ArgsPath *string `yaml:"argsPath,omitempty"`
	// Arguments to be passed to callable.
	// Leaf values are recursively templated just before call is executed.
	Args map[string]interface{}
}

func (*CallOp) CloneWith added in v1.0.64

func (c *CallOp) CloneWith(_ ActionContext) Action

func (*CallOp) Do added in v1.0.64

func (c *CallOp) Do(ctx ActionContext) error

func (*CallOp) String added in v1.0.64

func (c *CallOp) String() string

type ChildActions

type ChildActions map[string]ActionSpec

ChildActions is map of named actions that are executed as a part of parent action

func (ChildActions) CloneWith

func (na ChildActions) CloneWith(ctx ActionContext) Action

func (ChildActions) Do

func (na ChildActions) Do(ctx ActionContext) error

func (ChildActions) String

func (na ChildActions) String() string

type Cloneable added in v1.0.64

type Cloneable interface {
	// CloneWith creates fresh clone of this Action with values of its fields templated.
	// Data for template can be obtained by calling Snapshot() on provided context.
	CloneWith(ctx ActionContext) Action
}

Cloneable interface allows to customize default clone behavior by providing implementation of CloneWith function.

type DefineOp added in v1.0.64

type DefineOp struct {
	Name   string
	Action ActionSpec
}

DefineOp can be used to define the ActionSpec and later recall it by name via CallOp. Attempt to define name that was defined before will result in an error.

func (*DefineOp) CloneWith added in v1.0.64

func (d *DefineOp) CloneWith(ctx ActionContext) Action

func (*DefineOp) Do added in v1.0.64

func (d *DefineOp) Do(ctx ActionContext) error

func (*DefineOp) String added in v1.0.64

func (d *DefineOp) String() string

type EnvOp added in v1.0.40

type EnvOp struct {
	// Optional regexp which defines what to include. Only item names matching this regexp are added into data document.
	Include *regexp.Regexp `yaml:"include,omitempty"`

	// Optional regexp which defines what to exclude. Only item names NOT matching this regexp are added into data document.
	// Exclusion is considered after inclusion regexp is processed.
	Exclude *regexp.Regexp `yaml:"exclude,omitempty"`

	// Optional path within data tree under which "Env" container will be put.
	// When omitted, then "Env" goes to root of data.
	Path string `yaml:"path,omitempty" clone:"template"`
}

EnvOp is used to import OS environment variables into data

func (*EnvOp) CloneWith added in v1.0.40

func (eo *EnvOp) CloneWith(ctx ActionContext) Action

func (*EnvOp) Do added in v1.0.40

func (eo *EnvOp) Do(ctx ActionContext) error

func (*EnvOp) String added in v1.0.40

func (eo *EnvOp) String() string

type ExecOp added in v1.0.44

type ExecOp struct {
	// Program to execute
	Program string `yaml:"program,omitempty" clone:"template"`
	// Optional arguments for program
	Args *[]string `yaml:"args,omitempty"`
	// Program's working directory
	Dir string `yaml:"dir" clone:"template"`
	// List of exit codes that are assumed to be valid
	ValidExitCodes *[]int `yaml:"validExitCodes,omitempty"`
	// Path to file where program's stdout will be written upon completion.
	// Any error occurred during write will result in panic.
	Stdout *string
	// Path to file where program's stderr will be written upon completion
	// Any error occurred during write will result in panic.
	Stderr *string
	// Path within the global data where to set exit code.
	SaveExitCodeTo *string `yaml:"saveExitCodeTo,omitempty"`
}

func (*ExecOp) CloneWith added in v1.0.44

func (e *ExecOp) CloneWith(ctx ActionContext) Action

func (*ExecOp) Do added in v1.0.44

func (e *ExecOp) Do(ctx ActionContext) error

func (*ExecOp) String added in v1.0.44

func (e *ExecOp) String() string

type Executor

type Executor interface {
	Execute(act Action) error
}

Executor interface is used by external callers to execute Action items

func New

func New(opts ...Opt) Executor

type ExportOp added in v1.0.40

type ExportOp struct {
	// File to export data onto
	File string `clone:"template"`
	// Path within data tree pointing to dom.Node to export. Empty path denotes whole document.
	// If path does not resolve, then empty document will be exported.
	// If output format is "text" then path must point to leaf.
	// Any other output format must point to dom.Container.
	// If neither of these conditions are met, then it is considered as if path does not resolve at all.
	Path string `clone:"template"`
	// Format of output file.
	Format OutputFormat `clone:"template"`
}

ExportOp allows to export data into file

func (*ExportOp) CloneWith added in v1.0.40

func (e *ExportOp) CloneWith(ctx ActionContext) Action

func (*ExportOp) Do added in v1.0.40

func (e *ExportOp) Do(ctx ActionContext) (err error)

func (*ExportOp) String added in v1.0.40

func (e *ExportOp) String() string

type ExtInterface added in v1.0.64

type ExtInterface interface {
	Define(string, ActionSpec)
	Get(string) (ActionSpec, bool)
	AddAction(string, ActionFactory)
	GetAction(string) (ActionFactory, bool)
	RegisterService(string, interface{})
	GetService(string) (interface{}, bool)
}

type ExtOp added in v1.0.62

type ExtOp struct {
	// Function is name of function that was registered with Executor
	Function string `yaml:"func"`
	// Args holds arguments to be passed to function, if it implements ArgsSetter.
	Args map[string]interface{} `yaml:"args"`
}

func (*ExtOp) CloneWith added in v1.0.62

func (e *ExtOp) CloneWith(_ ActionContext) Action

func (*ExtOp) Do added in v1.0.62

func (e *ExtOp) Do(ctx ActionContext) error

func (*ExtOp) String added in v1.0.62

func (e *ExtOp) String() string

type ForEachOp

type ForEachOp struct {
	// Glob is pattern that will be used to match files on file system.
	// Matched files will be used as iteration items.
	Glob *string `yaml:"glob,omitempty"`
	// Query is path within the data tree that will be attempted
	Query *string `yaml:"query,omitempty"`
	// Item is list of specified strings to iterate over
	Item *[]string `yaml:"item,omitempty"`
	// Action to perform for every item
	Action ActionSpec `yaml:"action"`
	// Variable is name of variable to hold current iteration item.
	// When omitted, default value of "forEach" will be used
	Variable *string `yaml:"var,omitempty"`
}

ForEachOp can be used to repeat actions over list of items. Those items could be

  1. files specified by globbing pattern
  2. result of query from data tree (list values)
  3. specified strings

func (*ForEachOp) CloneWith

func (fea *ForEachOp) CloneWith(ctx ActionContext) Action

func (*ForEachOp) Do

func (fea *ForEachOp) Do(ctx ActionContext) error

func (*ForEachOp) String

func (fea *ForEachOp) String() string

type Html2DomLayout added in v1.0.64

type Html2DomLayout string

type Html2DomOp added in v1.0.64

type Html2DomOp struct {
	// From is path within the global data to the leaf node where XML source is stored as string.
	From string `yaml:"from" clone:"template"`
	// Query is optional xpath expression to use to extract subset from source XML document.
	// When omitted, then whole document is used.
	Query *string `yaml:"query"`
	// To is destination where to put converted document as dom.Container.
	To string `yaml:"to" clone:"template"`
	// Layout defines how HTML data are put into DOM
	Layout *Html2DomLayout `yaml:"layout"`
}

func (*Html2DomOp) CloneWith added in v1.0.64

func (x *Html2DomOp) CloneWith(ctx ActionContext) Action

func (*Html2DomOp) Do added in v1.0.64

func (x *Html2DomOp) Do(ctx ActionContext) error

func (*Html2DomOp) String added in v1.0.64

func (x *Html2DomOp) String() string

type ImportOp

type ImportOp struct {
	// File to read
	File string `yaml:"file" clone:"template"`

	// Path at which to import data.
	// If omitted, then data are merged into root of document
	Path string `yaml:"path" clone:"template"`

	// How to parse file
	Mode ParseFileMode `yaml:"mode,omitempty"`
}

ImportOp reads content of file into data tree at given path

func (*ImportOp) CloneWith

func (ia *ImportOp) CloneWith(ctx ActionContext) Action

func (*ImportOp) Do

func (ia *ImportOp) Do(ctx ActionContext) error

func (*ImportOp) String

func (ia *ImportOp) String() string

type LayoutFn added in v1.0.64

type LayoutFn func(dom.ContainerBuilder, *html.Node)

type Listener

type Listener interface {
	// OnBefore is called just before action is executed
	OnBefore(ctx ActionContext)
	// OnAfter is called sometime after action is executed, regardless of result.
	// Any error returned by invoking Do() method is returned as last parameter.
	OnAfter(ctx ActionContext, err error)
	// OnLog is called whenever action invokes Log method on Logger instance
	OnLog(ctx ActionContext, v ...interface{})
}

Listener interface allows hook into execution of Action.

type LogOp added in v1.0.52

type LogOp struct {
	Message string `yaml:"message" clone:"template"`
}

LogOp just logs message to logger

func (*LogOp) CloneWith added in v1.0.52

func (lo *LogOp) CloneWith(ctx ActionContext) Action

func (*LogOp) Do added in v1.0.52

func (lo *LogOp) Do(ctx ActionContext) error

func (*LogOp) String added in v1.0.52

func (lo *LogOp) String() string

type Logger added in v1.0.49

type Logger interface {
	// Log logs given values.
	// Format of values passed to this method is undefined.
	Log(v ...interface{})
}

Logger interface allows arbitrary messages to be logged by actions.

type LoopOp added in v1.0.62

type LoopOp struct {
	// Init is called just before any loop execution takes place
	Init *ActionSpec `yaml:"init,omitempty"`

	// Test is condition that is tested before each iteration.
	// When evaluated to true, execution will proceed with next iteration,
	// false terminates loop immediately
	Test string `yaml:"test,omitempty"`

	// Action is action that is executed every loop iteration
	Action ActionSpec `yaml:"action,omitempty"`

	// PostAction is action that is executed after every loop iteration.
	// This is right place to modify loop variables, such as incrementing counter
	PostAction *ActionSpec `yaml:"postAction,omitempty"`
}

LoopOp is similar to loop statement.

func (*LoopOp) CloneWith added in v1.0.62

func (l *LoopOp) CloneWith(ctx ActionContext) Action

func (*LoopOp) Do added in v1.0.62

func (l *LoopOp) Do(ctx ActionContext) (err error)

func (*LoopOp) String added in v1.0.62

func (l *LoopOp) String() string

type OpSpec

type OpSpec struct {
	// Set sets data in data document.
	Set *SetOp `yaml:"set,omitempty"`

	// Patch performs RFC6902-style patch on data document.
	Patch *PatchOp `yaml:"patch,omitempty"`

	// Import loads content of file into data document.
	Import *ImportOp `yaml:"import,omitempty"`

	// Template allows to render value at runtime
	Template *TemplateOp `yaml:"template,omitempty"`

	// TemplateFile can be used to render template file
	TemplateFile *TemplateFileOp `yaml:"templateFile,omitempty"`

	// Call calls previously defined callable
	Call *CallOp `yaml:"call,omitempty"`

	// Define defines callable ActionSpec
	Define *DefineOp `yaml:"define,omitempty"`

	// Env adds OS environment variables into data document
	Env *EnvOp `yaml:"env,omitempty"`

	// Exec executes program
	Exec *ExecOp `yaml:"exec,omitempty"`

	// Export exports data document into file
	Export *ExportOp `yaml:"export,omitempty"`

	// Ext allows runtime-registered extension action to be executed
	Ext *ExtOp `yaml:"ext,omitempty"`

	// ForEach execute same operation in a loop for every configured item
	ForEach *ForEachOp `yaml:"forEach,omitempty"`

	// Log logs arbitrary message to logger
	Log *LogOp `yaml:"log,omitempty"`

	// Loop allows for execution to be done in a loop
	Loop *LoopOp `yaml:"loop,omitempty"`

	// Abort is able to signal error, so that pipeline can abort execution
	Abort *AbortOp `yaml:"abort,omitempty"`

	// Html2Dom can be used to process HTML source into DOM
	Html2Dom *Html2DomOp `yaml:"html2DomOp,omitempty"`
}

OpSpec is specification of operation.

func (OpSpec) CloneWith

func (as OpSpec) CloneWith(ctx ActionContext) Action

func (OpSpec) Do

func (as OpSpec) Do(ctx ActionContext) error

func (OpSpec) String

func (as OpSpec) String() string

type Opt

type Opt func(*exec)

func WithData

func WithData(gd dom.ContainerBuilder) Opt

func WithExtActions added in v1.0.62

func WithExtActions(m map[string]ActionFactory) Opt

func WithListener

func WithListener(l Listener) Opt

func WithTemplateEngine

func WithTemplateEngine(t TemplateEngine) Opt

type OutputFormat added in v1.0.40

type OutputFormat string

type ParseFileMode

type ParseFileMode string

ParseFileMode defines how the file is parsed before is put into data tree

const (
	// ParseFileModeBinary File is read and encoded using base64 string into data tree
	ParseFileModeBinary ParseFileMode = "binary"

	// ParseFileModeText File is read as-is and is assumed it represents utf-8 encoded byte stream
	ParseFileModeText ParseFileMode = "text"

	// ParseFileModeYaml File is parsed as YAML document and put as child node into data tree
	ParseFileModeYaml ParseFileMode = "yaml"

	// ParseFileModeJson File is parsed as JSON document and put as child node into data tree
	ParseFileModeJson ParseFileMode = "json"

	// ParseFileModeProperties File is parsed as Java properties into map[string]interface{} and put as child node into data tree
	ParseFileModeProperties ParseFileMode = "properties"
)

type PatchOp

type PatchOp struct {
	Op   patch.Op `yaml:"op"`
	From string   `yaml:"from,omitempty" clone:"template"`
	Path string   `yaml:"path" clone:"template"`
	// Value is value to be used for op. This takes precedence over ValueFrom.
	Value *AnyVal `yaml:"value,omitempty"`
	// ValueFrom allow value to be read from data tree at given path.
	// Only considered when Value is nil.
	ValueFrom *string `yaml:"valueFrom,omitempty" clone:"template"`
}

PatchOp performs RFC6902-style patch on global data document. Check patch package for more details

func (*PatchOp) CloneWith

func (ps *PatchOp) CloneWith(ctx ActionContext) Action

func (*PatchOp) Do

func (ps *PatchOp) Do(ctx ActionContext) error

func (*PatchOp) String

func (ps *PatchOp) String() string

type SetOp

type SetOp struct {
	// Arbitrary data to put into data tree
	Data map[string]interface{} `yaml:"data"`

	// Path at which to put data.
	// If omitted, then data are merged into root of document
	Path string `yaml:"path,omitempty" clone:"template"`

	// Strategy defines how that are handled when conflict during set/add of data occur.
	Strategy *SetStrategy `yaml:"strategy,omitempty"`
}

SetOp sets data in global data document at given path.

func (*SetOp) CloneWith

func (sa *SetOp) CloneWith(ctx ActionContext) Action

func (*SetOp) Do

func (sa *SetOp) Do(ctx ActionContext) error

func (*SetOp) String

func (sa *SetOp) String() string

type SetStrategy added in v1.0.41

type SetStrategy string

type TemplateEngine

type TemplateEngine interface {
	Render(template string, data map[string]interface{}) (string, error)
	// RenderLenient attempts to render given template using provided data, while swallowing any error.
	// Value of template is first checked by simple means if it is actually template to avoid unnecessary errors.
	// Use with caution.
	RenderLenient(template string, data map[string]interface{}) string
	// RenderMapLenient attempts to render every leaf value in provided map
	RenderMapLenient(input map[string]interface{}, data map[string]interface{}) map[string]interface{}
	EvalBool(template string, data map[string]interface{}) (bool, error)
}

type TemplateFileOp added in v1.0.64

type TemplateFileOp struct {
	// File is path to file with template
	File string `yaml:"file" clone:"template"`
	// Output is path to output file
	Output string `yaml:"output" clone:"template"`
	// Path is path within the global data where data are read from (must be container).
	// When omitted, then root of global data is assumed.
	Path *string `yaml:"path,omitempty" clone:"template"`
}

TemplateFileOp can be used to render template from file and write result to output.

func (*TemplateFileOp) CloneWith added in v1.0.64

func (tfo *TemplateFileOp) CloneWith(ctx ActionContext) Action

func (*TemplateFileOp) Do added in v1.0.64

func (tfo *TemplateFileOp) Do(ctx ActionContext) error

func (*TemplateFileOp) String added in v1.0.64

func (tfo *TemplateFileOp) String() string

type TemplateOp

type TemplateOp struct {
	// template to render
	Template string `yaml:"template"`
	// path within global data tree where to set result at
	Path string `yaml:"path" clone:"template"`
	// Trim when true, whitespace is trimmed off the value
	Trim *bool `yaml:"trim,omitempty"`
}

TemplateOp can be used to render value from data at runtime.

func (*TemplateOp) CloneWith

func (ts *TemplateOp) CloneWith(ctx ActionContext) Action

func (*TemplateOp) Do

func (ts *TemplateOp) Do(ctx ActionContext) error

func (*TemplateOp) String

func (ts *TemplateOp) String() string

Jump to

Keyboard shortcuts

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