entity

package
v0.0.0-...-03481f5 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2025 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const CsupDoSudoEnv = "SUP_SUDO"
View Source
const CsupPasswdEnv = "SUP_PASSWORD"
View Source
const PassSeparator = " | "
View Source
const SPEW_DEPTH = 1
View Source
const TASK_TAIL = "_ssup_exec_script.sh"
View Source
const TubeNameSeparator = " << "
View Source
const VARS_TAIL = "_ssup_vars.env"
View Source
const VERSION = "0.5"

Variables

View Source
var (
	Colors = []string{
		"\033[32m",
		"\033[33m",
		"\033[36m",
		"\033[35m",
		"\033[31m",
		"\033[34m",
	}
	ResetColor = "\033[0m"
)
View Source
var (
	ErrUsage            = errors.New("Usage: sup [OPTIONS] NETWORK COMMAND [...]\n       sup [ --help | -v | --version ]")
	ErrUnknownNetwork   = errors.New("Unknown network\nif Supfile has networks: section defined\nyou MUST give network name as a first argument")
	ErrNetworkNoHosts   = errors.New("No hosts defined for a given network")
	ErrCmd              = errors.New("Unknown command/target")
	ErrTargetNoCommands = errors.New("No commands defined for a given target")
	ErrConfigFile       = errors.New("Unknown ssh_config file")
)

Functions

This section is empty.

Types

type AffixMappig

type AffixMappig struct {
	TargetName     string
	AffixedNetwork string
	CommandName    string
}

type ArgParserFacade

type ArgParserFacade interface {
	Parse(conf *Supfile, initialArgs *InitialArgs, helpMenu HelpDisplayer) (*PlayBook, error)
}

type ClientFacade

type ClientFacade interface {
	Connect(host NetworkHost) error
	SetRcloneCfg(config string)
	Run(task *Task) error
	Wait() error
	Close() error
	Prefix() (string, int)
	Write(p []byte) (n int, err error)
	WriteClose() error
	Stdin() io.WriteCloser
	Stderr() io.Reader
	Stdout() io.Reader
	Signal(os.Signal) error
	Upload(src string, dest string, cfg string) error
	Download(src string, dest string, silent bool) error
	GenerateOnRemote(data []byte) error
	GetHost() string
	GetTube() string
	SetTube(name string)
}

type Command

type Command struct {
	Name     string      `yaml:"-"`      // Command name.
	Desc     string      `yaml:"desc"`   // Command description.
	Local    string      `yaml:"local"`  // Command(s) to be run locally.
	Run      string      `yaml:"run"`    // Command(s) to be run remotelly.
	Script   string      `yaml:"script"` // Load command(s) from script and run it remotelly.
	Upload   []*Upload   `yaml:"upload"` // See Upload struct.
	Copy     *CopyOrder  `yaml:"copy"`   // See Upload struct.
	Stdin    bool        `yaml:"stdin"`  // Attach localhost STDOUT to remote commands' STDIN?
	Once     bool        `yaml:"once"`   // The command should be run "once" (on one host only).
	Serial   int         `yaml:"serial"` // Max number of clients processing a task in parallel.
	Fetch    *FetchOrder `yaml:"fetch" ` // See Fetch struct.
	Sudo     bool        `yaml:"sudo" `  // Run command(s) as root?
	SudoPass string      `yaml:"sudo_pass"`
	Env      EnvList     `yaml:"env"`

	// API backward compatibility. Will be deprecated in v1.0.
	RunOnce bool `yaml:"run_once"` // The command should be run once only.
}

Command represents command(s) to be run remotely.

type Commands

type Commands struct {
	Names []string
	Cmds  map[string]Command
}

Commands is a list of user-defined commands

func (*Commands) Get

func (c *Commands) Get(name string) (Command, bool)

func (*Commands) Has

func (c *Commands) Has(name string) bool

func (*Commands) UnmarshalYAML

func (c *Commands) UnmarshalYAML(unmarshal func(interface{}) error) error

type CopyOrder

type CopyOrder struct {
	Src string `yaml:"src"`
	Dst string `yaml:"dst"`
}

type EnvList

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

EnvList is a list of environment variables that maps to a YAML map, but maintains order, enabling late variables to reference early variables.

func (*EnvList) AsExport

func (e *EnvList) AsExport() string

func (EnvList) Get

func (e EnvList) Get(key string) string

func (EnvList) Keys

func (e EnvList) Keys() []string

func (*EnvList) Set

func (e *EnvList) Set(key, value string)

Set key to be equal value in this list.

func (EnvList) Slice

func (e EnvList) Slice() []string

func (*EnvList) UnmarshalYAML

func (e *EnvList) UnmarshalYAML(unmarshal func(interface{}) error) error

type EnvVar

type EnvVar struct {
	Key   string
	Value string
}

EnvVar represents an environment variable

func (EnvVar) AsExport

func (e EnvVar) AsExport() string

AsExport returns the environment variable as a bash export statement

func (EnvVar) String

func (e EnvVar) String() string

type ErrMustUpdate

type ErrMustUpdate struct {
	Msg string
}

func (ErrMustUpdate) Error

func (e ErrMustUpdate) Error() string

type ErrTask

type ErrTask struct {
	Task   *Task
	Reason string
}

func (ErrTask) Error

func (e ErrTask) Error() string

type ErrUnsupportedSupfileVersion

type ErrUnsupportedSupfileVersion struct {
	Msg string
}

func (ErrUnsupportedSupfileVersion) Error

type FetchOrder

type FetchOrder struct {
	Src string `yaml:"src"`
	Dst string `yaml:"dst"`
}

type FlagStringSlice

type FlagStringSlice []string

func (*FlagStringSlice) Set

func (f *FlagStringSlice) Set(value string) error

func (*FlagStringSlice) String

func (f *FlagStringSlice) String() string

type HelpDisplayer

type HelpDisplayer struct {
	ShowNetwork bool
	ShowCmd     bool
	// ShowTarget   bool
	ShowMakeMode bool
	Color        bool
}

func (*HelpDisplayer) Show

func (h *HelpDisplayer) Show(conf *Supfile)

func (*HelpDisplayer) ShowAll

func (h *HelpDisplayer) ShowAll(conf *Supfile)

type HostNamespace

type HostNamespace struct {
	EnvStore map[string]string
}

HostNamespace stores env vars from the host it has methods to get and set env variables

func (*HostNamespace) Get

func (h *HostNamespace) Get(key string) string

Get returns the value of the env var

func (HostNamespace) Set

func (h HostNamespace) Set(key, value string)

Set sets the value of the env var

func (*HostNamespace) Unset

func (h *HostNamespace) Unset(key string)

Unset unsets the value of the env var

type InitState

type InitState struct {
	Conf        *Supfile
	InitialArgs *InitialArgs
}

type InitialArgs

type InitialArgs struct {
	Supfile     string
	EnvVars     FlagStringSlice
	SshConfig   string
	OnlyHosts   string
	ExceptHosts string

	Debug         bool
	DisablePrefix bool

	ShowVersion  bool
	ShowHelp     bool
	DisableColor bool
	CommandArgs  []string
}

type Network

type Network struct {
	Env       EnvList       `yaml:"env"`
	Inventory string        `yaml:"inventory"`
	Hosts     []NetworkHost `yaml:"hosts"`
	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 Supfile.
	User         string `yaml:"user"`
	Password     string `yaml:"pass" `
	IdentityFile string `yaml:"id_file"`
	Name         string
}

Network is group of hosts with extra custom env vars.

func (Network) ParseInventory

func (n Network) ParseInventory() ([]NetworkHost, error)

ParseInventory runs the inventory command, if provided, and appends the command's output lines to the manually defined list of hosts.

func (*Network) UnmarshalYAML

func (n *Network) UnmarshalYAML(unmarshal func(interface{}) error) error

type NetworkHost

type NetworkHost struct {
	Host     string  `yaml:"host"`
	User     string  `yaml:"user"`
	Password string  `yaml:"pass"`
	Tube     string  `yaml:"tube"`
	Env      EnvList `yaml:"env"`
	Sudo     bool    `yaml:"sudo" default:"false"`
}

func (*NetworkHost) UnmarshalYAML

func (n *NetworkHost) UnmarshalYAML(unmarshal func(interface{}) error) error

type Networks

type Networks struct {
	Names []string
	Nets  map[string]Network
}

Networks is a list of user-defined networks

func (*Networks) Get

func (n *Networks) Get(name string) (Network, bool)

func (*Networks) Set

func (n *Networks) Set(name string, value string)

this is just to set localhost so we dont process slice of values as we should be...

func (*Networks) UnmarshalYAML

func (n *Networks) UnmarshalYAML(unmarshal func(interface{}) error) error

type Play

type Play struct {
	Nets     *Network
	Commands []*Command
}

type PlayBook

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

ParsedData encapsulates parsed inital arguments

func (*PlayBook) AddPlay

func (p *PlayBook) AddPlay(play Play)

func (*PlayBook) GetPlays

func (p *PlayBook) GetPlays() []Play

type Supfile

type Supfile struct {
	Networks Networks `yaml:"networks"`
	Commands Commands `yaml:"commands"`
	Targets  Targets  `yaml:"targets"`
	Env      EnvList  `yaml:"env"`
	Version  string   `yaml:"version"`
	Desc     string   `yaml:"desc"`
}

Supfile represents the Stack Up configuration YAML file.

func (Supfile) GetNetworkByName

func (s Supfile) GetNetworkByName(name string) (*Network, error)

type Targets

type Targets struct {
	Names []string
	// contains filtered or unexported fields
}

Targets is a list of user-defined targets by default affixed are mapped by command name

func (*Targets) Get

func (t *Targets) Get(name string) ([]string, bool)

func (*Targets) GetAffixByCommandName

func (t *Targets) GetAffixByCommandName(name string) (AffixMappig, bool)

func (*Targets) Has

func (t *Targets) Has(name string) bool

func (*Targets) HasAffixes

func (t *Targets) HasAffixes() bool

func (*Targets) UnmarshalYAML

func (t *Targets) UnmarshalYAML(unmarshal func(interface{}) error) error

type Task

type Task struct {
	Run     string
	Input   io.Reader
	Clients []ClientFacade
	TTY     bool
	Sudo    bool `yaml:"sudo" default:"false"`
	Env     EnvList
}

Task represents a set of commands to be run.

type Upload

type Upload struct {
	Src string `yaml:"src"`
	Dst string `yaml:"dst"`
	Exc string `yaml:"exclude"`
}

Upload represents file copy operation from localhost Src path to Dst path of every host in a given Network.

Jump to

Keyboard shortcuts

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