force

package module
v0.0.0-...-8fc2537 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2020 License: Apache-2.0 Imports: 20 Imported by: 0

README

Force

Force is an event processing and infrastructure automation framework.

Makefiles create an easy way to build targets and projects.

.force scripts create event-driven workflows with multiple services combined together: Github to Docker builds, Slack to Kubernetes Deployments.

Status

Current version is not even alpha, use at your own risk (0.0.18).

Documentation

Read the docs at https://force.gravitational.co

Goals

It should be easy and fun to define declarative event-driven workflows for infrastructure projects.

  • The tooling will be tailored to detect loops, inefficiencies in event-driven workflows.
  • Should make it easy and manageable to have an even driven distributed system running on Kubernetes or on developer's laptop.
  • Should be a single binary with no external dependencies.
  • Should not invent a new syntax and use Go syntax for everything.
  • It should be trivial to build a simple CI/CD system for a small project.

Non goals

It is not a general purpose event workflow tool, it's designed for cloud native infrastructure projects.

Batteries included

Force already includes out of the box plugins for:

  • Local and Kubernetes-native linux Docker builds.
  • Github and git integration
  • AWS S3
  • SSH
  • Slack

Soon force will include out of the box plugins for:

  • Better integration with Kubernetes.
  • Other popular source control and code sharing systems - Bitbucket, Gitlab.
  • Event queues - Redis, Kafka, AWS SQS.

Design concepts for language geeks

Rationale

There should be a high level abstraction, a glue language to describe modern cloud-native workloads.

Current state of the system using YAML is not good enough, as it produces very complex systems that are very hard to troubleshoot, debug and install.

Originals

Force is an interpreted mix of Go and [Scheme](https://en.wikipedia.org/wiki/Scheme_(programming_language).

Go makes it fun to work with concurrently running processes because it derives it's design from the CSP.

[Scheme](https://en.wikipedia.org/wiki/Scheme_(programming_language) is a higher-level functional language, and Force uses it's functional declarative style that will work well for cloud-native workloads where state is propagated across distributed infrastructure. Scheme's immutable and functional approach should work well

Status

This is work in progress and draft.

Please send your feedback to sasha@gravitational.com who is working on this project as a research activity.

Documentation

Index

Constants

View Source
const (
	// KeyCurrentDir is a current directory
	KeyCurrentDir = ContextKey("current.dir")
	// KeyError is an error value
	KeyError = ContextKey("error")
	// KeyLog is a logger associated with this execution
	KeyLog = ContextKey("log")
	// KeyProc is a process name
	KeyProc = "proc"
	// KeyID is a unique identifier of the run
	KeyID = "id"
	// KeyForce is a name of the force CI
	KeyForce = "force"
	// KeyEvent is an event produced by watchers
	KeyEvent = "event"
	// Underscore is underscore symbol
	Underscore = "_"
	StringType = "string"
	IntType    = "int"
	BoolType   = "bool"
)
View Source
const (
	// HumanDateFormat is a user friendly date format
	HumanDateFormat = "Jan _2 15:04 UTC"
)

Variables

This section is empty.

Functions

func Capitalize

func Capitalize(s string) string

Capitalize returns a copy of the string with first rune converted to capital letter

func ConvertTypeToAST

func ConvertTypeToAST(in reflect.Type) (reflect.Type, error)

ConvertTypeToAST converts incoming type to the type understood by force interpreter

func ConvertValueToAST

func ConvertValueToAST(in interface{}) (interface{}, error)

ConvertValueToAST converts value to the value of the force-compatible type

func Debugf

func Debugf(format string, args ...interface{})

func Define

func Define(group Group) func(name String, value interface{}) (Action, error)

Define defines a variable type and returns an action that sets the variable on the execution

func Error

func Error(ctx ExecutionContext) error

Error is a helper function that finds and returns an error

func Errorf

func Errorf(format string, args ...interface{})

func EscapeControl

func EscapeControl(s string) string

EscapeControl escapes all ANSI escape sequences from string and returns a string that is safe to print on the CLI. This is to ensure that malicious servers can not hide output. For more details, see:

func Eval

func Eval(ctx ExecutionContext, variable interface{}) (interface{}, error)

Eval evaluates variable based on the execution context

func EvalBool

func EvalBool(ctx ExecutionContext, in Expression) (bool, error)

EvalBool evaluates bool from var

func EvalFromAST

func EvalFromAST(ctx ExecutionContext, in interface{}) (interface{}, error)

EvalFromAST returns a new instance of the original struct marshaled from converted object, returns error if the object was not converted into AST

func EvalInt

func EvalInt(ctx ExecutionContext, in Expression) (int, error)

EvalInt evaluates int from var

func EvalInto

func EvalInto(ctx ExecutionContext, inRaw, out interface{}) error

EvalInto evaluates variable in within the execution context into variable out

func EvalString

func EvalString(ctx ExecutionContext, in Expression) (string, error)

EvalString evaluates string from var

func EvalStringVars

func EvalStringVars(ctx ExecutionContext, in []Expression) ([]string, error)

EvalStringVars evaluates string vars and returns a slice of strings

func ExpectBool

func ExpectBool(expr Expression) error

ExpectBool returns nil if expression is bool, error otherwise

func ExpectEnv

func ExpectEnv(key string) (string, error)

ExpectEnv returns environment var by key or error if variable not defined

func ExpectEqualTypes

func ExpectEqualTypes(aType, bType interface{}) error

ExpectEqualTypes compares expression types

func ExpectInt

func ExpectInt(expr Expression) error

ExpectInt returns nil if expression is int, error otherwise

func ExpectString

func ExpectString(expr Expression) error

ExpectString returns nil if expression is bool, error otherwise

func ExpressionType

func ExpressionType(in interface{}) interface{}

ExpressionType returns a type evaluated by expression

func FunctionName

func FunctionName(i interface{}) string

FunctionName returns function name

func GetField

func GetField(v interface{}, name String, fields ...String) (interface{}, error)

GetField returns field from struct v or error

func ImportStructsIntoAST

func ImportStructsIntoAST(l *LexScope, structs ...reflect.Type) error

ImportStructsIntoAST converts structs to AST compatible types and registers definitions in the

func Infof

func Infof(format string, args ...interface{})

func IsDir

func IsDir(dirPath string) bool

IsDir is a helper function to quickly check if a given path is a valid directory

func IsExit

func IsExit(event Event) bool

IsExit returns true if it's an exit event

func MarshalCode

func MarshalCode(ctx ExecutionContext, iface interface{}) ([]byte, error)

MarshalCode marshals parsed types into representation that could be interpreted by Force interpreter

func MultiCloser

func MultiCloser(closers ...io.Closer) *multiCloser

MultiCloser implements io.Close, it sequentially calls Close() on each object

func OriginalType

func OriginalType(t reflect.Type) reflect.Type

OriginalType is original struct type

func PInt32

func PInt32(in int32) *int32

func PInt64

func PInt64(in int64) *int64

func SetError

func SetError(ctx ExecutionContext, err error)

SetError is a helper function that adds an error to the context

func SetLog

func SetLog(ctx ExecutionContext, log Logger)

SetLog adds a logger to the exectuion context

func SetStruct

func SetStruct(ctx ExecutionContext, v interface{})

SetStruct sets struct from the value

func StartsWithLower

func StartsWithLower(v string) bool

StartsWithLower returns true if the string starts with lower case

func StructName

func StructName(t reflect.Type) string

StructName returns struct name

func StructPackageName

func StructPackageName(t reflect.Type) string

StructPackageName returns originating package name of this struct

func Var

func Var(group Group) func(name String, fields ...String) (interface{}, error)

Var returns a new function that references a variable based on the defined type

func Warningf

func Warningf(format string, args ...interface{})

func Writer

func Writer(logger Logger) io.WriteCloser

Writer returns a writer that ouptuts everything to logger

func Zero

func Zero(iface reflect.Value) reflect.Value

Zero returns a zero value for interface

func ZeroFromAST

func ZeroFromAST(in interface{}) (interface{}, error)

ZeroFromAST returns zero value original struct from AST

Types

type Action

type Action interface {
	Expression
}

Action is an expression with or without side effects

func Command

func Command(cmd Expression) (Action, error)

Command is a shortcut for shell action

func Defer

func Defer(action Action) Action

Defer defers the action executed in sequence

func Exit

func Exit() Action

Exit exits, if the exit code has been supplied it will extract for whatever exit event was sent in the context

func Parallel

func Parallel(actions ...Action) (Action, error)

Parallel runs actions in parallel

func Run

func Run(cmd Expression) (Action, error)

Run is a shortcut for deer Exit(), Command

func Shell

func Shell(s Script) (Action, error)

Shell runs shell script

type Bool

type Bool bool

Bool is a constant bool var

func (Bool) Convert

func (b Bool) Convert(i interface{}) (interface{}, error)

func (Bool) Eval

func (b Bool) Eval(ctx ExecutionContext) (interface{}, error)

Eval evaluates variable and returns bool

func (Bool) MarshalCode

func (b Bool) MarshalCode(ctx ExecutionContext) ([]byte, error)

MarshalCode marshals the variable to code representation

func (Bool) Type

func (b Bool) Type() interface{}

type BoolSlice

type BoolSlice []Expression

BoolSlice represents a slice of integers

func (BoolSlice) Eval

func (s BoolSlice) Eval(ctx ExecutionContext) (interface{}, error)

Eval evaluates a list of var references to types

func (BoolSlice) MarshalCode

func (s BoolSlice) MarshalCode(ctx ExecutionContext) ([]byte, error)

MarshalCode

func (BoolSlice) Type

func (s BoolSlice) Type() interface{}

Type of slice of expressions

func (BoolSlice) Vars

func (s BoolSlice) Vars() []Expression

Vars returns string vars

type BoolVar

type BoolVar struct {
	Expression
}

func (BoolVar) Convert

func (b BoolVar) Convert(i interface{}) (interface{}, error)

func (BoolVar) Eval

func (b BoolVar) Eval(ctx ExecutionContext) (interface{}, error)

func (BoolVar) Type

func (b BoolVar) Type() interface{}

type BoolVarFunc

type BoolVarFunc func(ctx ExecutionContext) (interface{}, error)

BoolVarFunc wraps function and returns an interface BoolVar

func (BoolVarFunc) Eval

func (f BoolVarFunc) Eval(ctx ExecutionContext) (interface{}, error)

Eval evaluates variable and returns bool

func (BoolVarFunc) Type

func (f BoolVarFunc) Type() interface{}

type Channel

type Channel interface {
	// CodeMarshaler allows to marshal action into code
	CodeMarshaler
	// Start starts the process
	Start(ctx context.Context) error
	Events() <-chan Event
	Done() <-chan struct{}
}

Channel produces events

func Duplicate

func Duplicate(c Channel, count int) Channel

Duplicate creates a channel that sends the same event count times, used for testing purposes

func FanIn

func FanIn(channels ...Channel) (Channel, error)

FanIn fans in events from multiple channels

func Files

func Files(files ...String) (Channel, error)

func Oneshot

func Oneshot() (Channel, error)

Oneshot returns a channel that fires once

func Ticker

func Ticker(period String) (Channel, error)

Ticker returns a channel that fires with period

type CloserFunc

type CloserFunc func() error

CloserFunc wraps function to create io.Closer compatible type

func (CloserFunc) Close

func (fn CloserFunc) Close() error

Close closes resources

type CodeError

type CodeError struct {
	Snippet Snippet
	Err     error
}

CodeError wraps error in the code

func (*CodeError) Error

func (e *CodeError) Error() string

Error returns user friendly error

type CodeMarshaler

type CodeMarshaler interface {
	// MarshalCode marshals object to text representation
	MarshalCode(ctx ExecutionContext) ([]byte, error)
}

CodeMarshaler marshals objects to code that could be interpreted later

type ContainsAction

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

func (*ContainsAction) Eval

func (c *ContainsAction) Eval(ctx ExecutionContext) (interface{}, error)

func (*ContainsAction) MarshalCode

func (c *ContainsAction) MarshalCode(ctx ExecutionContext) ([]byte, error)

MarshalCode marshals the variable to code representation

func (*ContainsAction) Type

func (c *ContainsAction) Type() interface{}

type Context

type Context struct {
	*sync.RWMutex
	*RuntimeScope
	// contains filtered or unexported fields
}

Context implements local execution context

func NewContext

func NewContext(cfg ContextConfig) *Context

NewContext returns a new context wraping context

func (*Context) Deadline

func (c *Context) Deadline() (deadline time.Time, ok bool)

Deadline returns the time when work done on behalf of this context should be canceled. Deadline returns ok==false when no deadline is set. Successive calls to Deadline return the same results.

func (*Context) Done

func (c *Context) Done() <-chan struct{}

Done returns channel that is closed when the context is closed

func (*Context) Err

func (c *Context) Err() error

Err returns an error associated with the context If Done is not yet closed, Err returns nil. If Done is closed, Err returns a non-nil error explaining why: Canceled if the context was canceled or DeadlineExceeded if the context's deadline passed. After Err returns a non-nil error, successive calls to Err return the same error.

func (*Context) Event

func (c *Context) Event() Event

Event is an event that generated the action

func (*Context) ID

func (c *Context) ID() string

ID is an execution unique identifier

func (*Context) Process

func (c *Context) Process() Process

Process returns a process associated with the context

type ContextConfig

type ContextConfig struct {
	// Parent is a context to wrap
	Parent ExecutionContext
	// Process is a process
	Process Process
	// Event is event
	Event Event
	// ID is an execution ID
	ID string
}

ContextConfig sets up local context

type ContextKey

type ContextKey string

ContextKey is a special type used to set force-related context value, is recommended by context package to use separate type for context values to prevent namespace clash

type ConvertedFunc

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

ConvertedFunc holds converted function

func (*ConvertedFunc) Eval

func (c *ConvertedFunc) Eval(ctx ExecutionContext) (interface{}, error)

Eval evaluates function and returns string

func (*ConvertedFunc) MarshalCode

func (c *ConvertedFunc) MarshalCode(ctx ExecutionContext) ([]byte, error)

MarshalCode marshals code

func (*ConvertedFunc) Type

func (c *ConvertedFunc) Type() interface{}

type Converter

type Converter interface {
	Convert(i interface{}) (interface{}, error)
}

Converter converts one value into another or returns error

type DeferAction

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

DeferAction runs actions in defer

func (*DeferAction) Eval

func (d *DeferAction) Eval(ctx ExecutionContext) (interface{}, error)

Run runs deferred action

func (*DeferAction) MarshalCode

func (d *DeferAction) MarshalCode(ctx ExecutionContext) ([]byte, error)

MarshalCode marshals action into code representation

func (*DeferAction) Type

func (d *DeferAction) Type() interface{}

type DefineAction

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

DefineAction defines a variable

func (*DefineAction) Eval

func (p *DefineAction) Eval(ctx ExecutionContext) (interface{}, error)

Eval defines a variable on the context and evaluates to the value

func (*DefineAction) MarshalCode

func (p *DefineAction) MarshalCode(ctx ExecutionContext) ([]byte, error)

MarshalCode marshals action into code representation

func (*DefineAction) Type

func (p *DefineAction) Type() interface{}

Type returns type evaluated by expression

type DuplicateChannel

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

func (*DuplicateChannel) Done

func (d *DuplicateChannel) Done() <-chan struct{}

func (*DuplicateChannel) Events

func (d *DuplicateChannel) Events() <-chan Event

func (*DuplicateChannel) MarshalCode

func (d *DuplicateChannel) MarshalCode(ctx ExecutionContext) ([]byte, error)

MarshalCode marshals channel to code

func (*DuplicateChannel) Start

func (d *DuplicateChannel) Start(pctx context.Context) error

func (*DuplicateChannel) String

func (d *DuplicateChannel) String() string

type Event

type Event interface {
	// AddMetadata adds metadada to the execution context
	AddMetadata(ctx ExecutionContext)
	// Created returns time when the event was originated in the system
	Created() time.Time
}

Event is generated by channel

func GetExitEventFromContext

func GetExitEventFromContext(ctx ExecutionContext) Event

type ExecutionContext

type ExecutionContext interface {
	context.Context
	// Event is an event that generated the action
	Event() Event
	// Process returns a process associated with context
	Process() Process
	// SetValue sets a key value pair of the context
	SetValue(key interface{}, value interface{}) error
	// ID is an execution unique identifier
	ID() string
}

ExecutionContext represents an execution context of a certain action execution chain,

func EmptyContext

func EmptyContext() ExecutionContext

EmptyContext returns empty execution context

type ExitEvent

type ExitEvent interface {
	ExitCode() int
}

ExitEvent is a special event tells the process group to exit with a specified code

type Expression

type Expression interface {
	// CodeMarshaler allows to marshal action into code
	CodeMarshaler
	// Eval evaluates variable and returns result of the expression
	Eval(ctx ExecutionContext) (interface{}, error)
	// Type returns the type of the expression,
	// for concrete types it is a zero instance -
	// empty string or function, for higher level types
	// like lambda function, returns the value
	Type() interface{}
}

Expression is any expression or variable that can be evaluated to contrete type

func Contains

func Contains(slice, item Expression) (Expression, error)

Contains returns true if a sequence contains value

func ID

func ID() Expression

ID returns a current Force execution ID

func Strings

func Strings(args ...Expression) (Expression, error)

Strings returns a list of strings evaluated from the arguments

type ExpressionSlice

type ExpressionSlice []Expression

ExpressionSlice is a wrapper around a slice of expressoins that adds interface method to evaluate to expression

func (ExpressionSlice) Eval

func (s ExpressionSlice) Eval(ctx ExecutionContext) (interface{}, error)

Eval evaluates a list of var references to types

func (ExpressionSlice) Type

func (s ExpressionSlice) Type() interface{}

Type of slice of expressions

func (ExpressionSlice) Vars

func (s ExpressionSlice) Vars() []Expression

Vars returns string vars

type FSNotify

type FSNotify struct {
	Files []string
	// contains filtered or unexported fields
}

func (*FSNotify) Done

func (f *FSNotify) Done() <-chan struct{}

func (*FSNotify) Events

func (f *FSNotify) Events() <-chan Event

func (*FSNotify) MarshalCode

func (f *FSNotify) MarshalCode(ctx ExecutionContext) ([]byte, error)

MarshalCode marshals channel to code

func (*FSNotify) Start

func (f *FSNotify) Start(pctx context.Context) error

func (*FSNotify) String

func (f *FSNotify) String() string

type FSNotifyEvent

type FSNotifyEvent struct {
	fsnotify.Event
	// contains filtered or unexported fields
}

func (*FSNotifyEvent) AddMetadata

func (f *FSNotifyEvent) AddMetadata(ctx ExecutionContext)

func (*FSNotifyEvent) Created

func (f *FSNotifyEvent) Created() time.Time

func (*FSNotifyEvent) String

func (f *FSNotifyEvent) String() string

type FanInChannel

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

FanInChannel

func (*FanInChannel) Done

func (d *FanInChannel) Done() <-chan struct{}

func (*FanInChannel) Events

func (d *FanInChannel) Events() <-chan Event

func (*FanInChannel) MarshalCode

func (d *FanInChannel) MarshalCode(ctx ExecutionContext) ([]byte, error)

MarshalCode marshals channel to code

func (*FanInChannel) Start

func (d *FanInChannel) Start(ctx context.Context) error

Start starts all sub channels and launches fan in and wait gorotouines

func (*FanInChannel) String

func (d *FanInChannel) String() string

type FnCall

type FnCall struct {
	// Package is a package name
	Package string
	// Fn is a function, the name will
	// be extracted from it
	Fn interface{}
	// FnName is a function name, will be
	// used instead of Fn if specified
	FnName string
	// Args is a list of arguments to the function
	Args []interface{}
}

FnCall is a struct used by marshaler

func NewFnCall

func NewFnCall(fn interface{}, args ...interface{}) *FnCall

NewFnCall returns new FnCall instance

func (*FnCall) MarshalCode

func (f *FnCall) MarshalCode(ctx ExecutionContext) ([]byte, error)

MarshalCode marshals object to code

func (*FnCall) SetExpressionArgs

func (f *FnCall) SetExpressionArgs(expressions []Expression)

SetExpressionArgs sets arguments from expressions

type Function

type Function interface {
	// NewInstance creates a new instance of the function
	// optionally creating a new lexical scope
	NewInstance(group Group) (Group, interface{})
}

Function creates new functions

func ConvertFunctionToAST

func ConvertFunctionToAST(fn interface{}) (Function, error)

ConvertFunctionToAST converts function fn into function with all arguments and return value converted to AST types

type GetEventFunc

type GetEventFunc func(ctx ExecutionContext) Event

type Group

type Group interface {
	// LexicalScope is a lexical scope
	// represented by this group
	LexicalScope
	// BroadcastEvents will broadcast events
	// to every process in a process group
	BroadcastEvents() chan<- Event

	// ExitEvent is set and returned when the group stop execution,
	// otherwise is nil, so callers should check for validity
	ExitEvent() ExitEvent

	// Context returns a process group context
	Context() context.Context

	// SetPlugin sets process group-local plugin
	// all setters and getters are thread safe
	SetPlugin(key interface{}, val interface{})

	// GetPlugin returns a process group plugin
	// all setters and getters are thread safe
	GetPlugin(key interface{}) (val interface{}, exists bool)

	// Logger returns a logger associated with this group
	Logger() Logger

	// IsDebug returns a global debug override
	IsDebug() bool
}

Group represents a group of processes

type IDAction

type IDAction struct {
}

IDAction returns force ID

func (*IDAction) Eval

func (i *IDAction) Eval(ctx ExecutionContext) (interface{}, error)

Eval evaluates id of the current execution context

func (*IDAction) MarshalCode

func (i *IDAction) MarshalCode(ctx ExecutionContext) ([]byte, error)

MarshalCode marshals ID action to code

func (*IDAction) Type

func (i *IDAction) Type() interface{}

type IfAction

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

IfAction runs actions in a sequence, if the action fails, next actions are not run

func (*IfAction) Eval

func (s *IfAction) Eval(ctx ExecutionContext) (interface{}, error)

Eval runs actions in sequence

func (*IfAction) EvalWithScope

func (s *IfAction) EvalWithScope(ctx ExecutionContext) (interface{}, error)

EvalWithScope runs actions in sequence using the passed scope

func (*IfAction) MarshalCode

func (p *IfAction) MarshalCode(ctx ExecutionContext) ([]byte, error)

MarshalCode marshals action into code representation

func (*IfAction) NewInstance

func (s *IfAction) NewInstance(group Group) (Group, interface{})

NewInstance is used when If expression evaluates to lambda function

func (*IfAction) Type

func (p *IfAction) Type() interface{}

type Int

type Int int

Int is a constant int var

func (Int) Convert

func (i Int) Convert(in interface{}) (interface{}, error)

func (Int) Eval

func (i Int) Eval(ctx ExecutionContext) (interface{}, error)

Value returns int value

func (Int) MarshalCode

func (i Int) MarshalCode(ctx ExecutionContext) ([]byte, error)

MarshalCode marshals the variable to code representation

func (*Int) String

func (i *Int) String() string

func (Int) Type

func (i Int) Type() interface{}

type IntSlice

type IntSlice []Expression

IntSlice represents a slice of integers

func (IntSlice) Eval

func (s IntSlice) Eval(ctx ExecutionContext) (interface{}, error)

Eval evaluates a list of var references to types

func (IntSlice) MarshalCode

func (s IntSlice) MarshalCode(ctx ExecutionContext) ([]byte, error)

MarshalCode

func (IntSlice) Type

func (s IntSlice) Type() interface{}

Type of slice of expressions

func (IntSlice) Vars

func (s IntSlice) Vars() []Expression

Vars returns string vars

type IntVar

type IntVar struct {
	Expression
}

func (IntVar) Convert

func (i IntVar) Convert(in interface{}) (interface{}, error)

func (IntVar) Eval

func (i IntVar) Eval(ctx ExecutionContext) (interface{}, error)

func (IntVar) Type

func (i IntVar) Type() interface{}

type IntVarFunc

type IntVarFunc func(ctx ExecutionContext) (interface{}, error)

IntVarFunc wraps function and returns an interface Var

func (IntVarFunc) Eval

func (f IntVarFunc) Eval(ctx ExecutionContext) (interface{}, error)

Eval evaluates value and returns error

func (IntVarFunc) Type

func (f IntVarFunc) Type() interface{}

type LambdaFunction

type LambdaFunction struct {
	Scope      Group
	Statements []Action
	Params     []LambdaParam
}

func ExpectLambdaFunction

func ExpectLambdaFunction(expr Expression) (*LambdaFunction, error)

ExpectLambdaFunction expects expression to evaluate to lambda function

func (*LambdaFunction) Call

func (f *LambdaFunction) Call(scope ExecutionContext) (interface{}, error)

Call attempts to call a function with no arguments

func (*LambdaFunction) Eval

func (f *LambdaFunction) Eval(ctx ExecutionContext) (interface{}, error)

Eval runs the action in the context of the worker, could modify the context to add metadata, fields or error

func (*LambdaFunction) EvalWithScope

func (f *LambdaFunction) EvalWithScope(scope ExecutionContext) (interface{}, error)

EvalWithScope runs actions in sequence using the passed scope

func (*LambdaFunction) ExpectEqualTypes

func (f *LambdaFunction) ExpectEqualTypes(i interface{}) error

ExpectEqualTypes returns nil if the lambda function signatures (input argument types and evaluated value) are equal

func (*LambdaFunction) MarshalCode

func (f *LambdaFunction) MarshalCode(ctx ExecutionContext) ([]byte, error)

MarshalCode marshals code

func (*LambdaFunction) NewCall

func (f *LambdaFunction) NewCall() (*LambdaFunctionCall, error)

NewCall creates a new call

func (*LambdaFunction) NewInstance

func (f *LambdaFunction) NewInstance(group Group) (Group, interface{})

func (*LambdaFunction) Type

func (f *LambdaFunction) Type() interface{}

type LambdaFunctionCall

type LambdaFunctionCall struct {
	Expression Expression
	// Args defines arguments the lambda function has been called with
	Arguments []interface{}
}

LambdaFunctionCall represents a call of a lambda function with arguments

func (*LambdaFunctionCall) CheckCall

func (f *LambdaFunctionCall) CheckCall() error

CheckCall checks call type variables and parameters

func (*LambdaFunctionCall) Eval

func (f *LambdaFunctionCall) Eval(ctx ExecutionContext) (interface{}, error)

Eval runs the action in the context of the worker, could modify the context to add metadata, fields or error

func (*LambdaFunctionCall) EvalStatements

func (f *LambdaFunctionCall) EvalStatements(ctx ExecutionContext) ([]Action, error)

EvalStatements returns all statements from evaluated lambda function

func (*LambdaFunctionCall) EvalWithScope

func (f *LambdaFunctionCall) EvalWithScope(scope ExecutionContext) (interface{}, error)

EvalWithScope runs actions in sequence using the passed scope and evalates to the value of the sequence (the last element of it)

func (*LambdaFunctionCall) LambdaType

func (f *LambdaFunctionCall) LambdaType() (*LambdaFunction, error)

LambdaType returns a lambda function type

func (*LambdaFunctionCall) MarshalCode

func (f *LambdaFunctionCall) MarshalCode(ctx ExecutionContext) ([]byte, error)

MarshalCode marshals code

func (*LambdaFunctionCall) Type

func (f *LambdaFunctionCall) Type() interface{}

LambdaFunctionCall evaluates to it's last statement

type LambdaParam

type LambdaParam struct {
	Name      string
	Prototype interface{}
}

type LexScope

type LexScope struct {
	*sync.RWMutex
	Group
	// contains filtered or unexported fields
}

LexScope wraps a group to create a new lexical scope

func WithLexicalScope

func WithLexicalScope(group Group) *LexScope

WithLexicalScope wraps a group to create a new lexical scope

func WithParent

func WithParent(group Group, parent interface{}) *LexScope

WithParent wraps a group to create a new lexical scope

func (*LexScope) AddDefinition

func (l *LexScope) AddDefinition(name string, v interface{}) error

AddDefinition defines variable to track its type the variable is set on the execution context

func (*LexScope) GetDefinition

func (l *LexScope) GetDefinition(name string) (interface{}, error)

GetDefinition gets a variable defined with DefineVarType not the actual variable value is returned, but a prototype value specifying the type

func (*LexScope) GetParent

func (l *LexScope) GetParent() (interface{}, error)

GetParent returns a parent definition of the lexical scope

func (*LexScope) SetParent

func (l *LexScope) SetParent(p interface{})

SetParent returns a parent definition of the lexical scope

func (*LexScope) Variables

func (l *LexScope) Variables() []string

Variables returns all variables defined in this scope (and parent scopes)

type LexicalScope

type LexicalScope interface {
	// AddDefinition adds variable definition in the current lexical scop
	AddDefinition(name string, v interface{}) error

	// GetDefinition gets a variable defined with DefineVarType
	// not the actual variable value is returned, but a prototype
	// value specifying the type
	GetDefinition(name string) (interface{}, error)

	// Variables returns a list of variable names
	// defined in this scope (and the parent scopes)
	Variables() []string

	// GetParent returns a parent scope definition,
	// NotFound error is returned if scope has no parent
	GetParent() (interface{}, error)

	// SetParent sets parent type of the scope
	SetParent(p interface{})
}

LexicalScope is a lexical scope with variables

type LocalExitEvent

type LocalExitEvent struct {
	Code int
	// contains filtered or unexported fields
}

func (LocalExitEvent) AddMetadata

func (e LocalExitEvent) AddMetadata(ctx ExecutionContext)

func (LocalExitEvent) Created

func (e LocalExitEvent) Created() time.Time

func (LocalExitEvent) ExitCode

func (e LocalExitEvent) ExitCode() int

func (LocalExitEvent) String

func (e LocalExitEvent) String() string

String returns a string description of the event

type Logger

type Logger interface {
	// WithError returns a logger bound to an error
	WithError(error) Logger
	Debugf(format string, args ...interface{})
	Infof(format string, args ...interface{})
	Warningf(format string, args ...interface{})
	Errorf(format string, args ...interface{})
	// URL returns a URL for viewing the logs
	// associated with this execution context
	URL(ExecutionContext) string
	// AddFields adds fields to the logger
	AddFields(fields map[string]interface{}) Logger
}

Logger is an interface to the logger

func Log

func Log(ctx context.Context) Logger

Log is a helper function that returns log

type Marshaler

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

Marshaler marshals expression to string

func Marshal

func Marshal(node interface{}) *Marshaler

Marshal marshals expression to its code representation without evaluating it (unless some parts of the expression) are unquoted using Unquote

func (*Marshaler) Eval

func (n *Marshaler) Eval(ctx ExecutionContext) (interface{}, error)

Eval returns code representation of the expression without evaluating it

func (*Marshaler) MarshalCode

func (n *Marshaler) MarshalCode(ctx ExecutionContext) ([]byte, error)

func (*Marshaler) Type

func (n *Marshaler) Type() interface{}

type NewDefine

type NewDefine struct {
}

NewDefine specifies a new define action

func (*NewDefine) NewInstance

func (n *NewDefine) NewInstance(group Group) (Group, interface{})

NewInstance returns a new instance of define

type NewIf

type NewIf struct {
}

NewIf creates a new conditional action with a new lexical scope

func (*NewIf) NewInstance

func (n *NewIf) NewInstance(group Group) (Group, interface{})

NewInstance returns a new instance of a function with a new lexical scope

type NewParallel

type NewParallel struct {
}

NewParallel creates a new series of actions executed in parallel

func (*NewParallel) NewInstance

func (n *NewParallel) NewInstance(group Group) (Group, interface{})

NewInstance returns a new instance

type NewSequence

type NewSequence struct {
}

NewSequence creates a new sequence with a new lexical scope

func (*NewSequence) NewInstance

func (n *NewSequence) NewInstance(group Group) (Group, interface{})

NewInstance returns a new instance of a function with a new lexical scope

type NewVarRef

type NewVarRef struct {
}

NewVarRef returns new variable references

func (*NewVarRef) NewInstance

func (n *NewVarRef) NewInstance(group Group) (Group, interface{})

NewInstance returns a new instance

type NopAction

type NopAction struct {
	FnName   string
	Args     []Expression
	EvalType interface{}
}

NopAction does nothing, is used to wrap arbitrary arguments

func (*NopAction) Eval

func (s *NopAction) Eval(ctx ExecutionContext) (interface{}, error)

Eval runs shell script and returns output as a string

func (*NopAction) MarshalCode

func (s *NopAction) MarshalCode(ctx ExecutionContext) ([]byte, error)

MarshalCode marshals action into code representation

func (*NopAction) String

func (s *NopAction) String() string

func (*NopAction) Type

func (s *NopAction) Type() interface{}

type NopScope

type NopScope struct {
	Func interface{}
}

NopScope wraps func to create new instances not bound to new lexical scope and not referencing any scopes

func (*NopScope) NewInstance

func (n *NopScope) NewInstance(group Group) (Group, interface{})

NewInstance retunrs the same func not bound to any scopes

type OneshotChannel

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

func (*OneshotChannel) Done

func (o *OneshotChannel) Done() <-chan struct{}

func (*OneshotChannel) Events

func (o *OneshotChannel) Events() <-chan Event

func (*OneshotChannel) MarshalCode

func (o *OneshotChannel) MarshalCode(ctx ExecutionContext) ([]byte, error)

MarshalCode marshals channel to code

func (*OneshotChannel) Start

func (o *OneshotChannel) Start(pctx context.Context) error

func (*OneshotChannel) String

func (o *OneshotChannel) String() string

type OneshotEvent

type OneshotEvent struct {
	time.Time
}

func (OneshotEvent) AddMetadata

func (e OneshotEvent) AddMetadata(ctx ExecutionContext)

func (*OneshotEvent) Created

func (o *OneshotEvent) Created() time.Time

func (*OneshotEvent) String

func (o *OneshotEvent) String() string

type ParallelAction

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

ParallelAction runs actions in parallel waits for all to complete, if any of them fail, returns error

func (*ParallelAction) Eval

func (p *ParallelAction) Eval(ctx ExecutionContext) (interface{}, error)

Eval runs actions in parallel and returns a slice of results

func (*ParallelAction) MarshalCode

func (p *ParallelAction) MarshalCode(ctx ExecutionContext) ([]byte, error)

MarshalCode marshals action into code representation

func (*ParallelAction) Type

func (p *ParallelAction) Type() interface{}

Type returns a slice of actions' results

type PipeNetConn

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

PipeNetConn implemetns net.Conn from io.Reader,io.Writer and io.Closer

func NewPipeNetConn

func NewPipeNetConn(reader io.Reader,
	writer io.Writer,
	closer io.Closer,
	fakelocalAddr net.Addr,
	fakeRemoteAddr net.Addr) *PipeNetConn

NewPipeNetConn returns a net.Conn like object using Pipe as an underlying implementation over reader, writer and closer

func (*PipeNetConn) Close

func (nc *PipeNetConn) Close() error

func (*PipeNetConn) LocalAddr

func (nc *PipeNetConn) LocalAddr() net.Addr

func (*PipeNetConn) Read

func (nc *PipeNetConn) Read(buf []byte) (n int, e error)

func (*PipeNetConn) RemoteAddr

func (nc *PipeNetConn) RemoteAddr() net.Addr

func (*PipeNetConn) SetDeadline

func (nc *PipeNetConn) SetDeadline(t time.Time) error

func (*PipeNetConn) SetReadDeadline

func (nc *PipeNetConn) SetReadDeadline(t time.Time) error

func (*PipeNetConn) SetWriteDeadline

func (nc *PipeNetConn) SetWriteDeadline(t time.Time) error

func (*PipeNetConn) Write

func (nc *PipeNetConn) Write(buf []byte) (n int, e error)

type Process

type Process interface {
	Expression
	// Name returns a process name
	Name() string
	// Channel returns a process channel
	Channel() Channel
	// Action returns actions assigned to the process
	Action() Action
	// Events returns a channel that receives events
	Events() chan<- Event
	// Start is a non blocking call
	Start(ctx ExecutionContext) error
	// Runner returns a process group
	// this process belongs to
	Group() Group
	// Done signals that process has completed
	// handling channel events and exited
	Done() <-chan struct{}
	// String returns user friendly process name
	String() string
}

Process is a process that is triggered by the event

type RuntimeScope

type RuntimeScope struct {
	*sync.RWMutex
	ExecutionContext
	// contains filtered or unexported fields
}

RuntimeScope wraps an execution context to create a new one with new variable values

func WithRuntimeScope

func WithRuntimeScope(ctx ExecutionContext) *RuntimeScope

WithRuntimeScope wraps a group to create a new runtime scope

func (*RuntimeScope) SetValue

func (l *RuntimeScope) SetValue(key interface{}, value interface{}) error

SetValue sets a key value pair

func (*RuntimeScope) Value

func (l *RuntimeScope) Value(key interface{}) interface{}

Value returns a value

type ScopeAction

type ScopeAction interface {
	Action
	// EvalWithScope evaluates action in sequence using the passed scope
	EvalWithScope(scope ExecutionContext) (interface{}, error)
}

ScopeAction can run in the context of the scope instead of creating a new one

func If

func If(condition Expression, action Action, elseActions ...Action) (ScopeAction, error)

If performs conditional execution of an action

func Sequence

func Sequence(actions ...Action) (ScopeAction, error)

Sequence groups sequence of commands together, if one fails, the chain stop execution

type Script

type Script struct {
	// ExportEnv exports all variables from host environment
	ExportEnv Expression
	// EchoArgs logs arguments
	EchoArgs Expression
	// Command is an inline script, shortcut for
	// /bin/sh -c args...
	Command Expression
	// Args is a list of arguments, if supplied
	// used instead of the command
	Args []Expression
	// WorkingDir is a working directory
	WorkingDir Expression
	// Env is a list of key value environment variables
	Env []Expression
}

Script is a shell script

func (*Script) CheckAndSetDefaults

func (s *Script) CheckAndSetDefaults(ctx ExecutionContext) error

CheckAndSetDefaults checks and sets default values

type SendAction

type SendAction struct {
	GetEvent GetEventFunc
	Process  Process
}

func (*SendAction) Eval

func (e *SendAction) Eval(ctx ExecutionContext) (interface{}, error)

func (*SendAction) MarshalCode

func (e *SendAction) MarshalCode(ctx ExecutionContext) ([]byte, error)

MarshalCode marshals action to code representation

func (*SendAction) Type

func (e *SendAction) Type() interface{}

type SequenceAction

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

SequenceAction runs actions in a sequence, if the action fails, next actions are not run

func (*SequenceAction) Eval

func (s *SequenceAction) Eval(ctx ExecutionContext) (interface{}, error)

Eval evaluates actions in sequence

func (*SequenceAction) EvalWithScope

func (s *SequenceAction) EvalWithScope(ctx ExecutionContext) (interface{}, error)

RunWithScope runs actions in sequence using the passed scope

func (*SequenceAction) MarshalCode

func (p *SequenceAction) MarshalCode(ctx ExecutionContext) ([]byte, error)

MarshalCode marshals action into code representation

func (*SequenceAction) Type

func (p *SequenceAction) Type() interface{}

type ShellAction

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

ShellAction runs shell script

func (*ShellAction) Eval

func (s *ShellAction) Eval(ctx ExecutionContext) (interface{}, error)

Eval runs shell script and returns output as a string

func (*ShellAction) MarshalCode

func (s *ShellAction) MarshalCode(ctx ExecutionContext) ([]byte, error)

MarshalCode marshals action into code representation

func (*ShellAction) String

func (s *ShellAction) String() string

func (*ShellAction) Type

func (s *ShellAction) Type() interface{}

type Snippet

type Snippet struct {
	Pos    token.Position
	Text   string
	Offset int
}

Snippet is a snippet captured from the source file based on the position

func CaptureSnippet

func CaptureSnippet(pos token.Position, text string) Snippet

CaptureSnippet captures snippet near position near newline

func (Snippet) String

func (s Snippet) String() string

String returns user friendly representation of the offset

type Spec

type Spec struct {
	Name    String
	Watch   Channel
	Run     Action
	EventsC chan Event `code:"-"`
	// Group if set, will assign the process to a specific group,
	// otherwise, will be set to the default runner
	Group Group `code:"-"`
}

Spec is a process specification

func (*Spec) CheckAndSetDefaults

func (s *Spec) CheckAndSetDefaults() error

type String

type String string

String is a constant string variable

func (String) Convert

func (s String) Convert(i interface{}) (interface{}, error)

func (String) Eval

func (s String) Eval(ctx ExecutionContext) (interface{}, error)

Value evaluates function and returns string

func (String) MarshalCode

func (s String) MarshalCode(ctx ExecutionContext) ([]byte, error)

MarshalCode marshals ID action to code

func (String) Type

func (s String) Type() interface{}

Type returns the type of the variable

type StringSlice

type StringSlice []Expression

StringSlice represents a slice of strings

func (StringSlice) Eval

func (s StringSlice) Eval(ctx ExecutionContext) (interface{}, error)

Eval evaluates a list of var references to types

func (StringSlice) MarshalCode

func (s StringSlice) MarshalCode(ctx ExecutionContext) ([]byte, error)

MarshalCode

func (StringSlice) Type

func (s StringSlice) Type() interface{}

Type of slice of expressions

func (StringSlice) Vars

func (s StringSlice) Vars() []Expression

Vars returns string vars

type StringVar

type StringVar struct {
	Expression
}

func (StringVar) Convert

func (s StringVar) Convert(i interface{}) (interface{}, error)

func (StringVar) Eval

func (s StringVar) Eval(ctx ExecutionContext) (interface{}, error)

func (StringVar) Type

func (s StringVar) Type() interface{}

type StringVarFunc

type StringVarFunc func(ctx ExecutionContext) (string, error)

StringVarFunc wraps function and returns an interface StringVar

func (StringVarFunc) Eval

func (f StringVarFunc) Eval(ctx ExecutionContext) (string, error)

Value returns a string value

func (StringVarFunc) Type

func (f StringVarFunc) Type() interface{}

Type returns the type of the variable

type StringsVar

type StringsVar struct {
	Expression
}

func (StringsVar) Convert

func (b StringsVar) Convert(i interface{}) (interface{}, error)

func (StringsVar) Eval

func (b StringsVar) Eval(ctx ExecutionContext) (interface{}, error)

func (StringsVar) Type

func (b StringsVar) Type() interface{}

type SyncBuffer

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

SyncBuffer is in memory bytes buffer that is safe for concurrent writes

func NewSyncBuffer

func NewSyncBuffer() *SyncBuffer

NewSyncBuffer returns new in memory buffer that is safe to read/write by multiple goroutines

func (*SyncBuffer) Bytes

func (b *SyncBuffer) Bytes() []byte

Bytes returns contents of the buffer after this call, all writes will fail

func (*SyncBuffer) Close

func (b *SyncBuffer) Close() error

Close closes reads and writes on the buffer

func (*SyncBuffer) String

func (b *SyncBuffer) String() string

String returns contents of the buffer after this call, all writes will fail

func (*SyncBuffer) Write

func (b *SyncBuffer) Write(data []byte) (n int, err error)

type Test

type Test struct {
	// I is an integer variable
	I Expression
	// S is a string variable
	S Expression
	// B is a bool variable
	B Expression
}

Test is a struct used for tests

type TickEvent

type TickEvent struct {
	time.Time
}

func (TickEvent) AddMetadata

func (e TickEvent) AddMetadata(ctx ExecutionContext)

func (*TickEvent) Created

func (o *TickEvent) Created() time.Time

func (*TickEvent) String

func (o *TickEvent) String() string

type TickerChannel

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

func (*TickerChannel) Done

func (o *TickerChannel) Done() <-chan struct{}

func (*TickerChannel) Events

func (o *TickerChannel) Events() <-chan Event

func (*TickerChannel) MarshalCode

func (o *TickerChannel) MarshalCode(ctx ExecutionContext) ([]byte, error)

MarshalCode marshals channel to code

func (*TickerChannel) Start

func (o *TickerChannel) Start(pctx context.Context) error

func (*TickerChannel) String

func (o *TickerChannel) String() string

type TypeChecker

type TypeChecker interface {
	// ExpectEqualTypes returns nil if the types are identical
	// error otherwise
	ExpectEqualTypes(i interface{}) error
}

TypeChecker is used to test two types for equivalence

type TypeConverter

type TypeConverter struct {
	// Converter is an internal converter
	// type, if present will be used
	Converter Converter
}

TypeConverter is a helper that converts types

func NewTypeConverter

func NewTypeConverter(t reflect.Type) *TypeConverter

NewTypeConverter returns a new type conveter

func (*TypeConverter) Convert

func (c *TypeConverter) Convert(in reflect.Value, t reflect.Type) (reflect.Value, error)

type Unquoter

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

Unquoter unquotes the expression

func Unquote

func Unquote(node Expression) *Unquoter

Unquote evaluates the argument first, and then returns code representation of the returned result

func (*Unquoter) Eval

func (u *Unquoter) Eval(ctx ExecutionContext) (interface{}, error)

Eval evaluates the argument first, and then returns code representation of the returned result

func (*Unquoter) MarshalCode

func (u *Unquoter) MarshalCode(ctx ExecutionContext) ([]byte, error)

MarshalCode marshals code

func (*Unquoter) Type

func (u *Unquoter) Type() interface{}

type VarRef

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

VarRef is a variable reference, evaluates to the expression

func (*VarRef) Eval

func (v *VarRef) Eval(ctx ExecutionContext) (interface{}, error)

Eval evaluates variable reference and checks types

func (*VarRef) MarshalCode

func (v *VarRef) MarshalCode(ctx ExecutionContext) ([]byte, error)

MarshalCode evaluates bool variable reference to code representation

func (*VarRef) Type

func (v *VarRef) Type() interface{}

type WrapContext

type WrapContext struct {
	context.Context
}

WrapContext wraps context

func (*WrapContext) Event

func (c *WrapContext) Event() Event

Event is an event that generated the action

func (*WrapContext) ID

func (c *WrapContext) ID() string

ID is an execution unique identifier

func (*WrapContext) Process

func (c *WrapContext) Process() Process

Process returns a process associated with the context

func (*WrapContext) SetValue

func (w *WrapContext) SetValue(key interface{}, value interface{}) error

SetValue sets a key value pair

Directories

Path Synopsis
internal
pkg
aws
git
log
ssh
ssh/scp
Package scp handles file uploads and downloads via scp command
Package scp handles file uploads and downloads via scp command
tool

Jump to

Keyboard shortcuts

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