Documentation ¶
Index ¶
- Constants
- Variables
- func InitializeSSHClientStore(ttl time.Duration)
- func VisitConfig(builder ConfigBuilder, c *Config) (interface{}, error)
- type Branch
- type Command
- type CommandTarget
- type Config
- type ConfigBuilder
- type ExecutionTreeBuilder
- func (*ExecutionTreeBuilder) Command(cmd *Command) interface{}
- func (e *ExecutionTreeBuilder) Commands(cmd *Command) Group
- func (e *ExecutionTreeBuilder) ContextBounds(child interface{}) interface{}
- func (e *ExecutionTreeBuilder) ErrorSafeguard(child interface{}) interface{}
- func (*ExecutionTreeBuilder) Forwarding(f *Forwarding) interface{}
- func (e *ExecutionTreeBuilder) Host(c *Config, h *Host) Group
- func (e *ExecutionTreeBuilder) HostLogger(hostName string, h *Host) interface{}
- func (e *ExecutionTreeBuilder) Hosts() Group
- func (e *ExecutionTreeBuilder) Job(name string) Group
- func (e *ExecutionTreeBuilder) JobLogger(jobName string) interface{}
- func (*ExecutionTreeBuilder) LocalCommand(cmd *Command) interface{}
- func (*ExecutionTreeBuilder) Output(o *Output) interface{}
- func (e *ExecutionTreeBuilder) Parallel() Group
- func (e *ExecutionTreeBuilder) Retry(child interface{}, numRetries uint) interface{}
- func (e *ExecutionTreeBuilder) SCP(scp *ScpData) interface{}
- func (*ExecutionTreeBuilder) SSHClient(host, user, keyFile, password string, keyboardInteractive map[string]string) interface{}
- func (e *ExecutionTreeBuilder) Sequential() Group
- func (*ExecutionTreeBuilder) Stderr(o *Output) interface{}
- func (e *ExecutionTreeBuilder) Stdout(o *Output) interface{}
- func (e *ExecutionTreeBuilder) Templating(config *Config, host *Host) interface{}
- func (e *ExecutionTreeBuilder) Timeout(timeout time.Duration) interface{}
- func (*ExecutionTreeBuilder) Tunnel(f *Forwarding) interface{}
- type Forwarding
- type Group
- type Host
- type Leaf
- type Output
- type ScpData
- type SimpleBranch
- type StringBuilder
- func (s *StringBuilder) Command(cmd *Command) interface{}
- func (s *StringBuilder) Commands(cmd *Command) Group
- func (s *StringBuilder) ContextBounds(child interface{}) interface{}
- func (s *StringBuilder) ErrorSafeguard(child interface{}) interface{}
- func (*StringBuilder) Forwarding(f *Forwarding) interface{}
- func (s *StringBuilder) Host(c *Config, h *Host) Group
- func (s *StringBuilder) HostLogger(jobName string, h *Host) interface{}
- func (s *StringBuilder) Hosts() Group
- func (s *StringBuilder) Job(name string) Group
- func (s *StringBuilder) JobLogger(jobName string) interface{}
- func (s *StringBuilder) LocalCommand(cmd *Command) interface{}
- func (s *StringBuilder) Output(o *Output) interface{}
- func (*StringBuilder) Parallel() Group
- func (s *StringBuilder) Retry(child interface{}, retries uint) interface{}
- func (*StringBuilder) SCP(scp *ScpData) interface{}
- func (*StringBuilder) SSHClient(host, user, keyFile, password string, keyboardInteractive map[string]string) interface{}
- func (*StringBuilder) Sequential() Group
- func (s *StringBuilder) Stderr(o *Output) interface{}
- func (s *StringBuilder) Stdout(o *Output) interface{}
- func (s *StringBuilder) Templating(c *Config, h *Host) interface{}
- func (*StringBuilder) Timeout(timeout time.Duration) interface{}
- func (*StringBuilder) Tunnel(f *Forwarding) interface{}
- type Stringer
- type TemplatingEngine
- type TreeBuilder
- type Vars
Constants ¶
const ( OutputKey contextKey = "output" LoggerKey contextKey = "logger" SshClientKey contextKey = "sshClient" TemplatingKey contextKey = "templating" StdoutKey contextKey = "stdout" StderrKey contextKey = "stderr" )
Variables ¶
var ( // KeepAliveInterval between two keep-alive messages. // Changes to the time interval only apply to newly // created connections. KeepAliveInterval = 30 * time.Second )
Functions ¶
func InitializeSSHClientStore ¶
InitializeSSHClientStore initialies the global SSH connection store and sets the time-to-live for unused connections.
func VisitConfig ¶ added in v0.15.0
func VisitConfig(builder ConfigBuilder, c *Config) (interface{}, error)
Types ¶
type Command ¶ added in v0.15.0
type Command struct { Name string `json:"name,omitempty"` Command string `json:"command,omitempty"` Commands []*Command `json:"commands,omitempty"` Flow string `json:"flow,omitempty"` Target CommandTarget `json:"target,omitempty"` Retries uint `json:"retries,omitempty"` Timeout string `json:"timeout,omitempty"` IgnoreError bool `json:"ignoreError,omitempty"` Stdout *Output `json:"stdout,omitempty"` Stderr *Output `json:"stderr,omitempty"` }
Command describes a command that can be executed on the client or a remote host connected via SSH.
type CommandTarget ¶ added in v0.18.0
type CommandTarget string
const CommandTargetLocal CommandTarget = "local"
type Config ¶
type Config struct { Name string `json:"name,omitempty"` Schedule string `json:"schedule,omitempty"` Timeout string `json:"timeout,omitempty"` Telemetry bool `json:"telemetry,omitempty"` Output *Output `json:"output,omitempty"` Host *Host `json:"host,omitempty"` HostsFile hostsFileOrArray `json:"hosts,omitempty"` Pre *Command `json:"pre,omitempty"` Command *Command `json:"command,omitempty"` Post *Command `json:"post,omitempty"` Forwarding *Forwarding `json:"forwarding,omitempty"` Tunnel *Forwarding `json:"tunnel,omitempty"` SCP *ScpData `json:"scp,omitempty"` }
Config is the in-memory representation of a job configuration.
func ReadConfig ¶
ReadConfig parses the file into a Config.
func (*Config) ExecutionTree ¶
ExecutionTree creates the execution tree necessary to executeCommand the configured steps.
type ConfigBuilder ¶ added in v0.15.0
type ConfigBuilder interface { Sequential() Group Parallel() Group Job(name string) Group Output(o *Output) interface{} JobLogger(jobName string) interface{} HostLogger(jobName string, h *Host) interface{} Timeout(timeout time.Duration) interface{} SCP(scp *ScpData) interface{} Hosts() Group Host(c *Config, h *Host) Group ErrorSafeguard(child interface{}) interface{} ContextBounds(child interface{}) interface{} Retry(child interface{}, retries uint) interface{} Templating(c *Config, h *Host) interface{} SSHClient(host, user, keyFile, password string, keyboardInteractive map[string]string) interface{} Forwarding(f *Forwarding) interface{} Tunnel(f *Forwarding) interface{} Commands(cmd *Command) Group Command(cmd *Command) interface{} LocalCommand(cmd *Command) interface{} Stdout(o *Output) interface{} Stderr(o *Output) interface{} }
type ExecutionTreeBuilder ¶ added in v0.15.0
type ExecutionTreeBuilder struct{}
ExecutionTreeBuilder creates subtrees of an execution tree.
func (*ExecutionTreeBuilder) Command ¶ added in v0.15.0
func (*ExecutionTreeBuilder) Command(cmd *Command) interface{}
Command returns a Flunc that, when executed, runs the command on the host.
It requires a logger, a SSHClient and a TemplatingEngine to function properly. It also redirects the commands STDERR and STDOUT to the ones in the context, if available. Otherwise os.Stderr and os.Stdout will be used, respectivly.
func (*ExecutionTreeBuilder) Commands ¶ added in v0.15.0
func (e *ExecutionTreeBuilder) Commands(cmd *Command) Group
Commands returns a Group that executes its contents sequentially.
func (*ExecutionTreeBuilder) ContextBounds ¶ added in v0.15.0
func (e *ExecutionTreeBuilder) ContextBounds(child interface{}) interface{}
ContextBounds returns a Flunc that, when executed, doesn't propagade the context it received from its child to its parent. Additionally the context passed to the child gets canceled as soon as the child returns. This cleans up any go routines started by the child waiting for the context.
func (*ExecutionTreeBuilder) ErrorSafeguard ¶ added in v0.15.0
func (e *ExecutionTreeBuilder) ErrorSafeguard(child interface{}) interface{}
ErrorSafeguard returns a Flunc that, when executed, will call its child. If the child returns an error the error will be logged but otherwise discarded and not passed to the parent.
It requires a logger to function properly.
func (*ExecutionTreeBuilder) Forwarding ¶ added in v0.15.0
func (*ExecutionTreeBuilder) Forwarding(f *Forwarding) interface{}
Forwarding returns a Flunc that, when executed, establishes a port forwarding from the host to the client.
It requires a logger and a SSHClient to function properly.
func (*ExecutionTreeBuilder) Host ¶ added in v0.15.0
func (e *ExecutionTreeBuilder) Host(c *Config, h *Host) Group
Host returns a Group that executes its contents sequentially.
func (*ExecutionTreeBuilder) HostLogger ¶ added in v0.15.0
func (e *ExecutionTreeBuilder) HostLogger(hostName string, h *Host) interface{}
HostLogger returns a Flunc that, when executed, adds log.Logger to the context that prefixes the log messages it prints with the host name.
It requires an Output to function properly.
func (*ExecutionTreeBuilder) Hosts ¶ added in v0.15.0
func (e *ExecutionTreeBuilder) Hosts() Group
Hosts returns a Group that executes its contents in parallel.
func (*ExecutionTreeBuilder) Job ¶ added in v0.15.0
func (e *ExecutionTreeBuilder) Job(name string) Group
Job returns a container for job-level Fluncs.
func (*ExecutionTreeBuilder) JobLogger ¶ added in v0.15.0
func (e *ExecutionTreeBuilder) JobLogger(jobName string) interface{}
JobLogger returns a Flunc that, when executed, adds log.Logger to the context that prefixes the log messages it prints with the job name.
It requires an Output to function properly.
func (*ExecutionTreeBuilder) LocalCommand ¶ added in v0.15.0
func (*ExecutionTreeBuilder) LocalCommand(cmd *Command) interface{}
LocalCommand returns a Flunc that, when executed, runs the command on the client.
It requires a logger and a TemplatingEngine to function properly. It also redirects the commands STDERR and STDOUT to the ones in the context, if available. Otherwise os.Stderr and os.Stdout will be used, respectivly.
func (*ExecutionTreeBuilder) Output ¶ added in v0.15.0
func (*ExecutionTreeBuilder) Output(o *Output) interface{}
Output returns a Flunc that, when executed, adds an io.Writer to the context. If there is already an output present, it creates an io.MultiWriter that writes to both outputs.
It requires a TemplatingEngine to function properly.
func (*ExecutionTreeBuilder) Parallel ¶ added in v0.15.0
func (e *ExecutionTreeBuilder) Parallel() Group
Parallel returns a Group that executes its contents parallel.
func (*ExecutionTreeBuilder) Retry ¶ added in v0.15.0
func (e *ExecutionTreeBuilder) Retry(child interface{}, numRetries uint) interface{}
Retry returns a Flunc that, when executed, restarts its child, if it returned an error. When numRetires retries have been made and the child still failed the latest error will be returned to the parent.
It requires a logger to function properly.
func (*ExecutionTreeBuilder) SCP ¶ added in v0.15.0
func (e *ExecutionTreeBuilder) SCP(scp *ScpData) interface{}
SCP returns a Flunc that, when executed, starts a new SCP server with the given configuration.
It requires a logger to function properly.
func (*ExecutionTreeBuilder) SSHClient ¶ added in v0.15.0
func (*ExecutionTreeBuilder) SSHClient(host, user, keyFile, password string, keyboardInteractive map[string]string) interface{}
SSHClient returns a Flunc that, when executed, adds a SSH client to the context. This is either a new client or an existing client that is being reused.
It requires a logger to function properly.
func (*ExecutionTreeBuilder) Sequential ¶ added in v0.15.0
func (e *ExecutionTreeBuilder) Sequential() Group
Sequential returns a Group that executes its contents sequentially.
func (*ExecutionTreeBuilder) Stderr ¶ added in v0.15.0
func (*ExecutionTreeBuilder) Stderr(o *Output) interface{}
Stderr returns a Flunc that, when executed, adds a file to the context that can be used as STDERR for Commands. It will close the file when the Flunc returns.
It requires a logger and a TemplatingEngine to function properly.
func (*ExecutionTreeBuilder) Stdout ¶ added in v0.15.0
func (e *ExecutionTreeBuilder) Stdout(o *Output) interface{}
Stdout returns a Flunc that, when executed, adds a file to the context that can be used as STDOUT for Commands. It will close the file, when the Flunc returns.
It requires a logger and a TemplatingEngine to function properly.
func (*ExecutionTreeBuilder) Templating ¶ added in v0.15.0
func (e *ExecutionTreeBuilder) Templating(config *Config, host *Host) interface{}
Templating returns a Flunc that, when executed, adds a new TemplatingEngine with the information from config and host to the context.
func (*ExecutionTreeBuilder) Timeout ¶ added in v0.15.0
func (e *ExecutionTreeBuilder) Timeout(timeout time.Duration) interface{}
Timeout returns a Flunc that, when executed, adds a timeout to the context after the given duration.
It requires a logger to function properly.
func (*ExecutionTreeBuilder) Tunnel ¶ added in v0.15.0
func (*ExecutionTreeBuilder) Tunnel(f *Forwarding) interface{}
Tunnel returns a Flunc that, when executed, establishes a port forwaring from the client to the host.
It requires a logger and a SSHClient to function properly.
type Forwarding ¶ added in v0.15.0
type Forwarding struct { RemoteHost string `json:"remoteHost,omitempty"` RemotePort uint16 `json:"remotePort,omitempty"` LocalHost string `json:"localHost,omitempty"` LocalPort uint16 `json:"localPort,omitempty"` }
Forwarding describes a tunnel between client and host independent from the tunnels direction.
type Group ¶ added in v0.15.0
type Group interface { Append(children ...interface{}) Wrap() interface{} }
type Host ¶ added in v0.15.0
type Host struct { Name string `json:"name,omitempty"` Addr string `json:"addr,omitempty"` Port uint `json:"port,omitempty"` User string `json:"user,omitempty"` PrivateKey string `json:"privateKey,omitempty"` Password string `json:"password,omitempty"` KeyboardInteractive map[string]string `json:"keyboardInteractive,omitempty"` Tags map[string]string `json:"tags,omitempty"` }
Host holds all information about a host such as its address and means to authenticate via SSH.
type Output ¶ added in v0.15.0
type Output struct { File string `json:"file,omitempty"` Raw bool `json:"raw,omitempty"` Overwrite bool `json:"overwrite,omitempty"` }
Output describes a file used for output in different scenarios such as logging and STDOUT and STDERR of commands.
func (*Output) MarshalJSON ¶ added in v0.15.0
MarshalJSON either marshals the Output as a JSON string, if both Raw and Overwrite are false. If one or both are true the Output is marshaled as a JSON object.
func (*Output) UnmarshalJSON ¶ added in v0.15.0
UnmarshalJSON unmarshals an Output either from a JSON string. In this case both Raw and Overwrite will be false. Or from a JSON object in that case Raw and Overwrite will have the values provided.
type ScpData ¶ added in v0.15.0
type ScpData struct { Addr string `json:"addr,omitempty"` Port uint `json:"port,omitempty"` Key string `json:"key,omitempty"` Verbose bool `json:"verbose,omitempty"` }
ScpData describes configuration for a SCP server.
type SimpleBranch ¶ added in v0.15.0
SimpleBranch implements the Branch interface.
func (*SimpleBranch) Append ¶ added in v0.15.0
func (s *SimpleBranch) Append(children ...interface{})
Append adds any given number of children to the branch. All children have to implement Stringer.
func (*SimpleBranch) String ¶ added in v0.15.0
func (s *SimpleBranch) String(v *Vars) string
func (*SimpleBranch) Wrap ¶ added in v0.15.0
func (s *SimpleBranch) Wrap() interface{}
Wrap returns the branch.
type StringBuilder ¶ added in v0.15.0
func (*StringBuilder) Command ¶ added in v0.15.0
func (s *StringBuilder) Command(cmd *Command) interface{}
func (*StringBuilder) Commands ¶ added in v0.15.0
func (s *StringBuilder) Commands(cmd *Command) Group
func (*StringBuilder) ContextBounds ¶ added in v0.15.0
func (s *StringBuilder) ContextBounds(child interface{}) interface{}
func (*StringBuilder) ErrorSafeguard ¶ added in v0.15.0
func (s *StringBuilder) ErrorSafeguard(child interface{}) interface{}
func (*StringBuilder) Forwarding ¶ added in v0.15.0
func (*StringBuilder) Forwarding(f *Forwarding) interface{}
func (*StringBuilder) Host ¶ added in v0.15.0
func (s *StringBuilder) Host(c *Config, h *Host) Group
func (*StringBuilder) HostLogger ¶ added in v0.15.0
func (s *StringBuilder) HostLogger(jobName string, h *Host) interface{}
func (*StringBuilder) Hosts ¶ added in v0.15.0
func (s *StringBuilder) Hosts() Group
func (*StringBuilder) Job ¶ added in v0.15.0
func (s *StringBuilder) Job(name string) Group
func (*StringBuilder) JobLogger ¶ added in v0.15.0
func (s *StringBuilder) JobLogger(jobName string) interface{}
func (*StringBuilder) LocalCommand ¶ added in v0.15.0
func (s *StringBuilder) LocalCommand(cmd *Command) interface{}
func (*StringBuilder) Output ¶ added in v0.15.0
func (s *StringBuilder) Output(o *Output) interface{}
func (*StringBuilder) Parallel ¶ added in v0.15.0
func (*StringBuilder) Parallel() Group
func (*StringBuilder) Retry ¶ added in v0.15.0
func (s *StringBuilder) Retry(child interface{}, retries uint) interface{}
func (*StringBuilder) SCP ¶ added in v0.15.0
func (*StringBuilder) SCP(scp *ScpData) interface{}
func (*StringBuilder) SSHClient ¶ added in v0.15.0
func (*StringBuilder) SSHClient(host, user, keyFile, password string, keyboardInteractive map[string]string) interface{}
func (*StringBuilder) Sequential ¶ added in v0.15.0
func (*StringBuilder) Sequential() Group
func (*StringBuilder) Stderr ¶ added in v0.15.0
func (s *StringBuilder) Stderr(o *Output) interface{}
func (*StringBuilder) Stdout ¶ added in v0.15.0
func (s *StringBuilder) Stdout(o *Output) interface{}
func (*StringBuilder) Templating ¶ added in v0.15.0
func (s *StringBuilder) Templating(c *Config, h *Host) interface{}
func (*StringBuilder) Timeout ¶ added in v0.15.0
func (*StringBuilder) Timeout(timeout time.Duration) interface{}
func (*StringBuilder) Tunnel ¶ added in v0.15.0
func (*StringBuilder) Tunnel(f *Forwarding) interface{}
type TemplatingEngine ¶ added in v0.15.0
type TemplatingEngine struct { Config *Config Host *Host Env map[string]string // contains filtered or unexported fields }
A TemplatingEngine can treat templating strings as defined by the Go text/template package. It uses information from the Config, Host, environment variables and the current time to replace place holders in the string.
func (*TemplatingEngine) Interpolate ¶ added in v0.15.0
func (t *TemplatingEngine) Interpolate(templ string) (string, error)
Interpolate tries to replace all place holders present in templ with information stored in the TemplatingEngine.
type TreeBuilder ¶ added in v0.15.0
type TreeBuilder struct { }
TreeBuilder builds a tree that can be used to create a textual representation of an execution tree.
type Vars ¶ added in v0.15.0
type Vars struct {
Te *TemplatingEngine
}
Vars is used to store information needed to create a proper string representation of an execution tree.