Documentation ¶
Index ¶
- Constants
- Variables
- func Errorf(format string, v ...interface{})
- func Infof(format string, v ...interface{})
- func LocalTarCmdArgs(path, exclude string) []string
- func MaskUserHostWithPasswd(host string) string
- func NewTarStreamReader(cwd, path, exclude string) (io.Reader, error)
- func PadStringWithTimestamp(s string, n int) string
- func RemoteTarCommand(dir string) string
- func ResolveLocalPath(cwd, path, env string) (string, error)
- func Warnf(format string, v ...interface{})
- type Book
- type Books
- type Client
- type Command
- type Commands
- type EnvVar
- type EnvVars
- type ErrBook
- type ErrConnect
- type ErrMustUpgrade
- type ErrPlayfileVersion
- type LocalClient
- func (c *LocalClient) Close() error
- func (c *LocalClient) Connect(_ string) error
- func (c *LocalClient) LastError() error
- func (c *LocalClient) Prompt() string
- func (c *LocalClient) Run(book *Book) error
- func (c *LocalClient) Signal(sig os.Signal) error
- func (c *LocalClient) Stderr() io.Reader
- func (c *LocalClient) Stdin() io.WriteCloser
- func (c *LocalClient) Stdout() io.Reader
- func (c *LocalClient) Wait() error
- func (c *LocalClient) Write(p []byte) (n int, err error)
- type Network
- type Networks
- type Play
- type Playfile
- type SSHClient
- func (c *SSHClient) Close() error
- func (c *SSHClient) Connect(host string) error
- func (c *SSHClient) ConnectWith(host string, dialer SSHDialFunc) error
- func (c *SSHClient) LastError() error
- func (c *SSHClient) Prompt() string
- func (c *SSHClient) Run(book *Book) error
- func (c *SSHClient) Signal(sig os.Signal) error
- func (c *SSHClient) Stderr() io.Reader
- func (c *SSHClient) Stdin() io.WriteCloser
- func (c *SSHClient) Stdout() io.Reader
- func (c *SSHClient) Wait() error
- func (c *SSHClient) Write(p []byte) (n int, err error)
- type SSHDialFunc
- type Upload
Constants ¶
const (
VERSION = "1.0.0"
)
VERSION defines current package version
Variables ¶
var ( ErrEmptyClient = errors.New("Client is empty.") ErrEmptyCommand = errors.New("Command is empty.") ErrRunning = errors.New("Command alreay running.") ErrNotRunning = errors.New("Command not running or has finished.") ErrConnected = errors.New("Client has connected.") ErrNotConnected = errors.New("Client not connected.") ErrOpened = errors.New("Session has opened.") ErrNotOpened = errors.New("Session not opened.") ErrNotSupported = errors.New("Not supported.") )
Functions ¶
func LocalTarCmdArgs ¶
LocalTarCmdArgs returns command to be run on local host.
func MaskUserHostWithPasswd ¶
MaskUserHostWithPasswd masks passwd for sensitive
func NewTarStreamReader ¶
NewTarStreamReader creates a tar stream reader from a local path. TODO: Refactor. Use "archive/tar" instead.
func PadStringWithTimestamp ¶
PadStringWithTimestamp returns new string leads with time
func RemoteTarCommand ¶
RemoteTarCommand returns command to be run on remote SSH host to properly receive the created TAR stream. TODO: Check for relative directory.
func ResolveLocalPath ¶
ResolveLocalPath determines local file path related to cwd
Types ¶
type Book ¶
type Book struct {
// contains filtered or unexported fields
}
Book represents a set of commands to be run.
type Books ¶
type Books struct { Names []string // contains filtered or unexported fields }
Books is a list of user-defined books
func (*Books) UnmarshalYAML ¶
type Client ¶
type Client interface { io.WriteCloser Connect(host string) error Run(book *Book) error Wait() error Stdin() io.WriteCloser Stderr() io.Reader Stdout() io.Reader Signal(os.Signal) error Prompt() string LastError() error }
Client is an interface wraps the connection/sessions.
type Command ¶
type Command struct { Name string `yaml:"-"` // Command name. Desc string `yaml:"desc"` // Command description. Run string `yaml:"run"` // Command(s) to be run remotelly. Script string `yaml:"script"` // Load command(s) from script and run it remotelly. Uploads map[string]Upload `yaml:"uploads"` // See Upload struct. Serial int `yaml:"serial"` // Max number of clients processing a book in parallel. Locally bool `yaml:"locally"` // Command(s) to be run locally. Stdin bool `yaml:"stdin"` // Attach localhost STDOUT to remote commands' STDIN? Once bool `yaml:"once"` // The command should be run "once" (randomly on one host only). }
Command represents command(s) to be run remotely.
type Commands ¶
type Commands struct { Names []string // contains filtered or unexported fields }
Commands is a list of user-defined commands
func (*Commands) UnmarshalYAML ¶
type EnvVar ¶
EnvVar represents an environment variable
type EnvVars ¶
type EnvVars []*EnvVar
EnvVars is a list of environment variables that maps to a YAML map, but maintains order, enabling late variables to reference early variables.
func (*EnvVars) ResolveValues ¶
func (*EnvVars) UnmarshalYAML ¶
type ErrConnect ¶
ErrConnect defines connection error with reason
type ErrMustUpgrade ¶
type ErrMustUpgrade struct {
Msg string
}
ErrMustUpgrade defines upgrade error for old client
func (ErrMustUpgrade) Error ¶
func (e ErrMustUpgrade) Error() string
type ErrPlayfileVersion ¶
type ErrPlayfileVersion struct {
Msg string
}
ErrPlayfileVersion defines error for unsupported playfile version
func (ErrPlayfileVersion) Error ¶
func (e ErrPlayfileVersion) Error() string
type LocalClient ¶
type LocalClient struct {
// contains filtered or unexported fields
}
LocalClient is a wrapper over the local host.
func NewLocalClient ¶
func NewLocalClient(env string) *LocalClient
NewLocalClient creates a local client with given env, and export PLAY_HOST=localhost
func (*LocalClient) Close ¶
func (c *LocalClient) Close() error
func (*LocalClient) Connect ¶
func (c *LocalClient) Connect(_ string) error
Connect returns current user for local
func (*LocalClient) LastError ¶
func (c *LocalClient) LastError() error
func (*LocalClient) Prompt ¶
func (c *LocalClient) Prompt() string
func (*LocalClient) Stderr ¶
func (c *LocalClient) Stderr() io.Reader
func (*LocalClient) Stdin ¶
func (c *LocalClient) Stdin() io.WriteCloser
func (*LocalClient) Stdout ¶
func (c *LocalClient) Stdout() io.Reader
func (*LocalClient) Wait ¶
func (c *LocalClient) Wait() error
Wait waits book to finish or return from error
type Network ¶
type Network struct { Envs EnvVars `yaml:"env"` Hosts []string `yaml:"hosts"` Inventory string `yaml:"inventory"` Bastion string `yaml:"bastion"` // Jump host for the environment // Should these live on Hosts too? We'd have to change []string to struct, even in Playfile. User string `yaml:"user"` Passwd string `yaml:"passwd"` Port int `yaml:"port"` IdentityFile string `yaml:"identity_file"` }
Network is group of hosts with extra custom env vars.
func (Network) ParseInventory ¶
ParseInventory runs the inventory command, if provided, and appends the command's output lines to the manually defined list of hosts.
type Networks ¶
type Networks struct { Names []string // contains filtered or unexported fields }
Networks is a list of user-defined networks
func (*Networks) UnmarshalYAML ¶
type Play ¶
type Play struct {
// contains filtered or unexported fields
}
Play holds all books for running
type Playfile ¶
type Playfile struct { Version string `yaml:"version"` Envs EnvVars `yaml:"envs"` Networks Networks `yaml:"networks"` Commands Commands `yaml:"commands"` Books Books `yaml:"books"` }
Playfile represents the play configuration YAML file.
func NewPlayfile ¶
NewPlayfile parses configuration file and returns Playfile or error.
func NewPlayfileFromFile ¶
NewPlayfileFromFile returns *Playfile by parsing filename given or error
type SSHClient ¶
type SSHClient struct {
// contains filtered or unexported fields
}
SSHClient is a wrapper over the SSH connection/sessions.
func (*SSHClient) Connect ¶
Connect creates SSH connection to a specified host. It expects the host of the form "[ssh://][user:passwd@]host[:port]".
func (*SSHClient) ConnectWith ¶
func (c *SSHClient) ConnectWith(host string, dialer SSHDialFunc) error
ConnectWith creates a SSH connection to a specified host. It will use dialer to establish the connection. TODO: Split Signers to its own method.
func (*SSHClient) Stdin ¶
func (c *SSHClient) Stdin() io.WriteCloser
type SSHDialFunc ¶
SSHDialFunc can dial a ssh server and return a client