action

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2023 License: Apache-2.0 Imports: 27 Imported by: 10

Documentation

Overview

Package action provides implementations of discovering and running actions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertInputToStruct

func ConvertInputToStruct(cmd *Command, conf *Config) map[string]interface{}

ConvertInputToStruct creates an arbitrary struct from input variables.

func ForwardAllSignals

func ForwardAllSignals(ctx context.Context, cli driver.ContainerRunner, cid string, sigc <-chan os.Signal)

ForwardAllSignals forwards signals to the container

The channel you pass in must already be setup to receive any signals you want to forward.

Types

type Action

type Action struct {
	Title       string               `yaml:"title"`
	Description string               `yaml:"description"`
	Arguments   ArgumentsList        `yaml:"arguments"`
	Options     OptionsList          `yaml:"options"`
	Command     StrSlice             `yaml:"command"`
	Image       string               `yaml:"image"`
	Build       *cli.BuildDefinition `yaml:"build"`
	ExtraHosts  []string             `yaml:"extra_hosts"`
	Env         EnvSlice             `yaml:"env"`
}

Action is a representation of an action structure of an action yaml

func (*Action) BuildDefinition

func (a *Action) BuildDefinition(wd string) *cli.BuildDefinition

BuildDefinition provides resolved image build info

type Argument

type Argument struct {
	Name        string          `yaml:"name"`
	Title       string          `yaml:"title"`
	Description string          `yaml:"description"`
	Type        jsonschema.Type `yaml:"type"`
	RawMap      map[string]interface{}
}

Argument stores command arguments declaration.

type ArgumentsList

type ArgumentsList []*Argument

ArgumentsList is used for custom yaml parsing of arguments list.

func (*ArgumentsList) UnmarshalYAML

func (l *ArgumentsList) UnmarshalYAML(nodeList *yaml.Node) (err error)

UnmarshalYAML implements yaml.Unmarshaler to parse for ArgumentsList.

type Command

type Command struct {
	WorkingDir  string
	Filepath    string
	CommandName string

	Loader Loader

	InputArgs    map[string]string
	InputOptions map[string]interface{}
	// contains filtered or unexported fields
}

Command holds a definition of a discovered action file.

func (*Command) Action

func (cmd *Command) Action() *Action

Action returns action with replaces variables.

func (*Command) Compile

func (cmd *Command) Compile() error

Compile load config with replaced arguments and options.

func (*Command) Dir

func (cmd *Command) Dir() string

Dir returns an action file directory.

func (*Command) SetArgsInput

func (cmd *Command) SetArgsInput(args []string)

SetArgsInput saves passed cobra arguments for later processing in run, templates, etc.

func (*Command) SetOptsInput

func (cmd *Command) SetOptsInput(options map[string]interface{})

SetOptsInput saves passed cobra flags for later processing in run, templates, etc.

func (*Command) ValidateInput

func (cmd *Command) ValidateInput() error

ValidateInput validates arguments and options according to a specified json schema in action definition.

type Config

type Config struct {
	Version string  `yaml:"version"`
	Action  *Action `yaml:"action"`
}

Config is a representation of an action yaml

func CreateFromYaml

func CreateFromYaml(r io.Reader) (*Config, error)

CreateFromYaml creates action definition from yaml configuration. It returns pointer to Config or nil on error.

func CreateFromYamlTpl

func CreateFromYamlTpl(b []byte) (*Config, error)

CreateFromYamlTpl creates action definition from yaml configuration as CreateFromYaml but considers that it has unescaped template values.

type Discovery

type Discovery interface {
	Discover() ([]*Command, error)
}

Discovery finds action files and parses them.

func NewYamlDiscovery

func NewYamlDiscovery(fs fs.FS) Discovery

NewYamlDiscovery creates an instance of action discovery.

type EnvSlice

type EnvSlice []string

EnvSlice is an array of env vars or key-value.

func (*EnvSlice) UnmarshalYAML

func (l *EnvSlice) UnmarshalYAML(n *yaml.Node) (err error)

UnmarshalYAML implements yaml.Unmarshaler to parse env []string or map[string]string.

type Executor

type Executor interface {
	Exec(ctx context.Context, cli cli.Cli, cmd *Command) error
	Close() error
}

Executor is a common interface for all container executors.

func NewContainerExecutor

func NewContainerExecutor(t driver.Type) (Executor, error)

NewContainerExecutor creates a new action executor in container environment.

func NewDockerExecutor

func NewDockerExecutor() (Executor, error)

NewDockerExecutor creates a new action executor in Docker environment.

type LoadProcessor

type LoadProcessor interface {
	Process([]byte) ([]byte, error)
}

LoadProcessor is an interface for processing input on load.

func NewPipeProcessor

func NewPipeProcessor(p ...LoadProcessor) LoadProcessor

NewPipeProcessor creates a new processor containing several processors that handles input consequentially.

type Loader

type Loader interface {
	Content() ([]byte, error)
	Load() (*Config, error)
	LoadRaw() (*Config, error)
}

Loader is an interface for loading a config file.

type Option

type Option struct {
	Name        string          `yaml:"name"`
	Title       string          `yaml:"title"`
	Description string          `yaml:"description"`
	Type        jsonschema.Type `yaml:"type"`
	Default     interface{}     `yaml:"default"`
	Required    bool            `yaml:"required"`
	RawMap      map[string]interface{}
}

Option stores command options declaration.

type OptionsList

type OptionsList []*Option

OptionsList is used for custom yaml parsing of options list.

func (*OptionsList) UnmarshalYAML

func (l *OptionsList) UnmarshalYAML(nodeList *yaml.Node) (err error)

UnmarshalYAML implements yaml.Unmarshaler to parse for OptionsList.

type StrSlice

type StrSlice []string

StrSlice is an array of strings for command execution.

func (*StrSlice) UnmarshalYAML

func (l *StrSlice) UnmarshalYAML(n *yaml.Node) (err error)

UnmarshalYAML implements yaml.Unmarshaler to parse a string or a list of strings.

Jump to

Keyboard shortcuts

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