Documentation
¶
Overview ¶
backy.go Copyright (C) Andrew Woodlee 2023 License: Apache-2.0
notification.go Copyright (C) Andrew Woodlee 2023 License: Apache-2.0
Index ¶
- Variables
- func AllowedExternalDirectivesStrings() []string
- func CheckConfigValues(config *koanf.Koanf, file string)
- func CheckIfHostHasHostName(host string) (bool, string)
- func CommandTypeStrings() []string
- func GetPassword(pass string, opts *ConfigOpts) string
- func GetPrivateKeyPassword(key string, opts *ConfigOpts) string
- func GetVaultKey(str string, opts *ConfigOpts, log zerolog.Logger) string
- func IsCmdStdOutEnabled() bool
- func IsTerminalActive() bool
- func PackageOperationStrings() []string
- func VariadicFunctionParameterTest(allowedKeys ...string)
- type AllowedExternalDirectives
- func (i AllowedExternalDirectives) IsAAllowedExternalDirectives() bool
- func (i AllowedExternalDirectives) MarshalJSON() ([]byte, error)
- func (i AllowedExternalDirectives) MarshalText() ([]byte, error)
- func (i AllowedExternalDirectives) MarshalYAML() (interface{}, error)
- func (i AllowedExternalDirectives) String() string
- func (i *AllowedExternalDirectives) UnmarshalJSON(data []byte) error
- func (i *AllowedExternalDirectives) UnmarshalText(text []byte) error
- func (i *AllowedExternalDirectives) UnmarshalYAML(unmarshal func(interface{}) error) error
- type BackyOptionFunc
- func AddCommandLists(lists []string) BackyOptionFunc
- func AddCommands(commands []string) BackyOptionFunc
- func EnableCron() BackyOptionFunc
- func SetCmdStdOut(setStdOut bool) BackyOptionFunc
- func SetCmdsToSearch(cmds []string) BackyOptionFunc
- func SetListsToSearch(lists []string) BackyOptionFunc
- func SetLogFile(logFile string) BackyOptionFunc
- type CmdList
- type CmdOutput
- type CmdResult
- type Command
- func (cmd *Command) ExecuteHooks(hookType string, opts *ConfigOpts)
- func (cmd *Command) GenerateLogger(opts *ConfigOpts) zerolog.Logger
- func (c *Command) GetVariablesFromConf(opts *ConfigOpts)
- func (command *Command) RunCmd(cmdCtxLogger zerolog.Logger, opts *ConfigOpts) ([]string, error)
- func (command *Command) RunCmdSSH(cmdCtxLogger zerolog.Logger, opts *ConfigOpts) ([]string, error)
- type CommandType
- func (i CommandType) IsACommandType() bool
- func (i CommandType) MarshalJSON() ([]byte, error)
- func (i CommandType) MarshalText() ([]byte, error)
- func (i CommandType) MarshalYAML() (interface{}, error)
- func (i CommandType) String() string
- func (i *CommandType) UnmarshalJSON(data []byte) error
- func (i *CommandType) UnmarshalText(text []byte) error
- func (i *CommandType) UnmarshalYAML(unmarshal func(interface{}) error) error
- type ConfigOpts
- func (opts *ConfigOpts) Cron()
- func (opts *ConfigOpts) ExecCmdsSSH(cmdList []string, hostsList []string)
- func (opts *ConfigOpts) ExecuteCmds()
- func (opts *ConfigOpts) InitConfig()
- func (opts *ConfigOpts) ListCommand(cmd string)
- func (opts *ConfigOpts) ListCommandList(list string)
- func (c *ConfigOpts) LogLvl(level string) BackyOptionFunc
- func (opts *ConfigOpts) ReadConfig() *ConfigOpts
- func (opts *ConfigOpts) RunListConfig(cron string)
- func (opts *ConfigOpts) SetupNotify()
- type Hooks
- type Host
- func (remoteHost *Host) CombineHostNameWithPort()
- func (remoteHost *Host) ConnectThroughBastion(log zerolog.Logger) (*ssh.Client, error)
- func (remoteConfig *Host) ConnectToHost(opts *ConfigOpts) error
- func (h *Host) DetectOS(opts *ConfigOpts) (string, error)
- func (remoteHost *Host) GetAuthMethods(opts *ConfigOpts) error
- func (remoteHost *Host) GetHostName()
- func (remoteHost *Host) GetKnownHosts() error
- func (remoteHost *Host) GetPort()
- func (remoteHost *Host) GetPrivateKeyFileFromConfig()
- func (remoteConfig *Host) GetProxyJumpConfig(hosts map[string]*Host, opts *ConfigOpts) error
- func (remoteConfig *Host) GetProxyJumpFromConfig(hosts map[string]*Host) error
- func (remoteHost *Host) GetSshUserFromConfig()
- type HttpConfig
- type ListConfig
- type MailConfig
- type MatrixStruct
- type Notifications
- type PackageOperation
- func (i PackageOperation) IsAPackageOperation() bool
- func (i PackageOperation) MarshalJSON() ([]byte, error)
- func (i PackageOperation) MarshalText() ([]byte, error)
- func (i PackageOperation) MarshalYAML() (interface{}, error)
- func (i PackageOperation) String() string
- func (i *PackageOperation) UnmarshalJSON(data []byte) error
- func (i *PackageOperation) UnmarshalText(text []byte) error
- func (i *PackageOperation) UnmarshalYAML(unmarshal func(interface{}) error) error
- type RemoteSource
- type VaultConfig
- type VaultKey
Constants ¶
This section is empty.
Variables ¶
var PrivateKeyExtraInfoErr = errors.New("Private key may be encrypted. \nIf encrypted, make sure the password is specified correctly in the correct section. This may be done in one of two ways: \n Using external directives - see docs \n privatekeypassword: password (not recommended). \n ")
var Sprintf = fmt.Sprintf
var TS = strings.TrimSpace
Functions ¶
func AllowedExternalDirectivesStrings ¶ added in v0.10.2
func AllowedExternalDirectivesStrings() []string
AllowedExternalDirectivesStrings returns a slice of all String values of the enum
func CheckConfigValues ¶ added in v0.1.0
func CheckConfigValues(config *koanf.Koanf, file string)
func CheckIfHostHasHostName ¶ added in v0.7.0
func CommandTypeStrings ¶ added in v0.9.0
func CommandTypeStrings() []string
CommandTypeStrings returns a slice of all String values of the enum
func GetPassword ¶ added in v0.1.0
func GetPassword(pass string, opts *ConfigOpts) string
GetPassword gets any password
func GetPrivateKeyPassword ¶ added in v0.1.0
func GetPrivateKeyPassword(key string, opts *ConfigOpts) string
func GetVaultKey ¶ added in v0.3.0
func GetVaultKey(str string, opts *ConfigOpts, log zerolog.Logger) string
func IsCmdStdOutEnabled ¶ added in v0.1.0
func IsCmdStdOutEnabled() bool
func IsTerminalActive ¶ added in v0.1.0
func IsTerminalActive() bool
func PackageOperationStrings ¶ added in v0.9.0
func PackageOperationStrings() []string
PackageOperationStrings returns a slice of all String values of the enum
func VariadicFunctionParameterTest ¶ added in v0.10.2
func VariadicFunctionParameterTest(allowedKeys ...string)
Types ¶
type AllowedExternalDirectives ¶ added in v0.10.2
type AllowedExternalDirectives int
const ( DefaultExternalDir AllowedExternalDirectives = iota AllowedExternalDirectiveVault // vault AllowedExternalDirectiveVaultFile // vault-file AllowedExternalDirectiveAll // vault-file-env AllowedExternalDirectiveFileEnv // file-env AllowedExternalDirectiveFile // file AllowedExternalDirectiveEnv // env )
func AllowedExternalDirectivesString ¶ added in v0.10.2
func AllowedExternalDirectivesString(s string) (AllowedExternalDirectives, error)
AllowedExternalDirectivesString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.
func AllowedExternalDirectivesValues ¶ added in v0.10.2
func AllowedExternalDirectivesValues() []AllowedExternalDirectives
AllowedExternalDirectivesValues returns all values of the enum
func (AllowedExternalDirectives) IsAAllowedExternalDirectives ¶ added in v0.10.2
func (i AllowedExternalDirectives) IsAAllowedExternalDirectives() bool
IsAAllowedExternalDirectives returns "true" if the value is listed in the enum definition. "false" otherwise
func (AllowedExternalDirectives) MarshalJSON ¶ added in v0.10.2
func (i AllowedExternalDirectives) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface for AllowedExternalDirectives
func (AllowedExternalDirectives) MarshalText ¶ added in v0.10.2
func (i AllowedExternalDirectives) MarshalText() ([]byte, error)
MarshalText implements the encoding.TextMarshaler interface for AllowedExternalDirectives
func (AllowedExternalDirectives) MarshalYAML ¶ added in v0.10.2
func (i AllowedExternalDirectives) MarshalYAML() (interface{}, error)
MarshalYAML implements a YAML Marshaler for AllowedExternalDirectives
func (AllowedExternalDirectives) String ¶ added in v0.10.2
func (i AllowedExternalDirectives) String() string
func (*AllowedExternalDirectives) UnmarshalJSON ¶ added in v0.10.2
func (i *AllowedExternalDirectives) UnmarshalJSON(data []byte) error
UnmarshalJSON implements the json.Unmarshaler interface for AllowedExternalDirectives
func (*AllowedExternalDirectives) UnmarshalText ¶ added in v0.10.2
func (i *AllowedExternalDirectives) UnmarshalText(text []byte) error
UnmarshalText implements the encoding.TextUnmarshaler interface for AllowedExternalDirectives
func (*AllowedExternalDirectives) UnmarshalYAML ¶ added in v0.10.2
func (i *AllowedExternalDirectives) UnmarshalYAML(unmarshal func(interface{}) error) error
UnmarshalYAML implements a YAML Unmarshaler for AllowedExternalDirectives
type BackyOptionFunc ¶
type BackyOptionFunc func(*ConfigOpts)
func AddCommandLists ¶ added in v0.1.0
func AddCommandLists(lists []string) BackyOptionFunc
AddCommandLists adds lists to ConfigOpts
func AddCommands ¶ added in v0.1.0
func AddCommands(commands []string) BackyOptionFunc
AddCommands adds commands to ConfigOpts
func EnableCron ¶ added in v0.7.0
func EnableCron() BackyOptionFunc
EnableCron enables the execution of command lists at specified times
func SetCmdStdOut ¶ added in v0.9.0
func SetCmdStdOut(setStdOut bool) BackyOptionFunc
SetCmdStdOut forces the command output to stdout
func SetCmdsToSearch ¶ added in v0.4.0
func SetCmdsToSearch(cmds []string) BackyOptionFunc
AddPrintLists adds lists to print out
func SetListsToSearch ¶ added in v0.4.0
func SetListsToSearch(lists []string) BackyOptionFunc
SetListsToSearch adds lists to search
func SetLogFile ¶ added in v0.7.0
func SetLogFile(logFile string) BackyOptionFunc
SetLogFile sets the path to the log file
type CmdList ¶ added in v0.1.0
type CmdList struct { Name string `yaml:"name,omitempty"` Cron string `yaml:"cron,omitempty"` RunCmdOnFailure string `yaml:"runCmdOnFailure,omitempty"` Order []string `yaml:"order,omitempty"` Notifications []string `yaml:"notifications,omitempty"` GetOutput bool `yaml:"getOutput,omitempty"` NotifyOnSuccess bool `yaml:"notifyOnSuccess,omitempty"` NotifyConfig *notify.Notify Source string `yaml:"source"` // URL to fetch remote commands Type string `yaml:"type"` }
type Command ¶
type Command struct { Name string `yaml:"name,omitempty"` Cmd string `yaml:"cmd"` // See CommandType enum further down the page for acceptable values Type CommandType `yaml:"type,omitempty"` Host *string `yaml:"host,omitempty"` Hooks *Hooks `yaml:"hooks,omitempty"` Shell string `yaml:"shell,omitempty"` RemoteHost *Host `yaml:"-"` Args []string `yaml:"args,omitempty"` Dir *string `yaml:"dir,omitempty"` Env string `yaml:"env,omitempty"` Environment []string `yaml:"environment,omitempty"` GetOutputInList bool `yaml:"getOutputInList,omitempty"` ScriptEnvFile string `yaml:"scriptEnvFile"` OutputToLog bool `yaml:"outputToLog,omitempty"` OutputFile string `yaml:"outputFile,omitempty"` PackageManager string `yaml:"packageManager,omitempty"` PackageName string `yaml:"packageName,omitempty"` PackageVersion string `yaml:"packageVersion,omitempty"` PackageOperation PackageOperation `yaml:"packageOperation,omitempty"` RemoteSource string `yaml:"remoteSource,omitempty"` FetchBeforeExecution bool `yaml:"fetchBeforeExecution,omitempty"` Fetcher remotefetcher.RemoteFetcher Username string `yaml:"userName,omitempty"` UserID string `yaml:"userID,omitempty"` UserGroups []string `yaml:"userGroups,omitempty"` UserHome string `yaml:"userHome,omitempty"` UserShell string `yaml:"userShell,omitempty"` UserCreateHome bool `yaml:"userCreateHome,omitempty"` UserIsSystem bool `yaml:"userIsSystem,omitempty"` UserPassword string `yaml:"userPassword,omitempty"` UserSshPubKeys []string `yaml:"userSshPubKeys,omitempty"` // OS for the command, only used when type is user OS string `yaml:"OS,omitempty"` UserOperation string `yaml:"userOperation,omitempty"` // contains filtered or unexported fields }
func (*Command) ExecuteHooks ¶ added in v0.5.0
func (cmd *Command) ExecuteHooks(hookType string, opts *ConfigOpts)
func (*Command) GenerateLogger ¶ added in v0.6.0
func (cmd *Command) GenerateLogger(opts *ConfigOpts) zerolog.Logger
func (*Command) GetVariablesFromConf ¶ added in v0.10.2
func (c *Command) GetVariablesFromConf(opts *ConfigOpts)
type CommandType ¶ added in v0.9.0
type CommandType int
use ints so we can use enums
const ( DefaultCT CommandType = iota // ScriptCT // script ScriptFileCT // scriptFile RemoteScriptCT // remoteScript PackageCT // package UserCT // user )
func CommandTypeString ¶ added in v0.9.0
func CommandTypeString(s string) (CommandType, error)
CommandTypeString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.
func CommandTypeValues ¶ added in v0.9.0
func CommandTypeValues() []CommandType
CommandTypeValues returns all values of the enum
func (CommandType) IsACommandType ¶ added in v0.9.0
func (i CommandType) IsACommandType() bool
IsACommandType returns "true" if the value is listed in the enum definition. "false" otherwise
func (CommandType) MarshalJSON ¶ added in v0.9.0
func (i CommandType) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface for CommandType
func (CommandType) MarshalText ¶ added in v0.9.0
func (i CommandType) MarshalText() ([]byte, error)
MarshalText implements the encoding.TextMarshaler interface for CommandType
func (CommandType) MarshalYAML ¶ added in v0.9.0
func (i CommandType) MarshalYAML() (interface{}, error)
MarshalYAML implements a YAML Marshaler for CommandType
func (CommandType) String ¶ added in v0.9.0
func (i CommandType) String() string
func (*CommandType) UnmarshalJSON ¶ added in v0.9.0
func (i *CommandType) UnmarshalJSON(data []byte) error
UnmarshalJSON implements the json.Unmarshaler interface for CommandType
func (*CommandType) UnmarshalText ¶ added in v0.9.0
func (i *CommandType) UnmarshalText(text []byte) error
UnmarshalText implements the encoding.TextUnmarshaler interface for CommandType
func (*CommandType) UnmarshalYAML ¶ added in v0.9.0
func (i *CommandType) UnmarshalYAML(unmarshal func(interface{}) error) error
UnmarshalYAML implements a YAML Unmarshaler for CommandType
type ConfigOpts ¶ added in v0.3.0
type ConfigOpts struct { // Cmds holds the commands for a list. // Key is the name of the command, Cmds map[string]*Command `yaml:"commands"` // CmdConfigLists holds the lists of commands to be run in order. // Key is the command list name. CmdConfigLists map[string]*CmdList `yaml:"cmdLists"` // Hosts holds the Host config. // key is the host. Hosts map[string]*Host `yaml:"hosts"` Logger zerolog.Logger // Global log level BackyLogLvl *string CmdStdOut bool ConfigFilePath string ConfigDir string LogFilePath string CmdListFile string List ListConfig Vars map[string]string `yaml:"variables"` VaultKeys []*VaultKey `yaml:"keys"` NotificationConf *Notifications `yaml:"notifications"` Cache *remotefetcher.Cache CachedData []*remotefetcher.CacheData // contains filtered or unexported fields }
func NewOpts ¶
func NewOpts(configFilePath string, opts ...BackyOptionFunc) *ConfigOpts
func (*ConfigOpts) Cron ¶ added in v0.3.0
func (opts *ConfigOpts) Cron()
func (*ConfigOpts) ExecCmdsSSH ¶ added in v0.6.0
func (opts *ConfigOpts) ExecCmdsSSH(cmdList []string, hostsList []string)
func (*ConfigOpts) ExecuteCmds ¶ added in v0.4.0
func (opts *ConfigOpts) ExecuteCmds()
func (*ConfigOpts) InitConfig ¶ added in v0.3.0
func (opts *ConfigOpts) InitConfig()
func (*ConfigOpts) ListCommand ¶ added in v0.5.0
func (opts *ConfigOpts) ListCommand(cmd string)
ListCommand searches the commands in the file to find one
func (*ConfigOpts) ListCommandList ¶ added in v0.9.0
func (opts *ConfigOpts) ListCommandList(list string)
func (*ConfigOpts) LogLvl ¶ added in v0.3.0
func (c *ConfigOpts) LogLvl(level string) BackyOptionFunc
func (*ConfigOpts) ReadConfig ¶ added in v0.7.0
func (opts *ConfigOpts) ReadConfig() *ConfigOpts
func (*ConfigOpts) RunListConfig ¶ added in v0.4.0
func (opts *ConfigOpts) RunListConfig(cron string)
RunListConfig runs a command list from the ConfigFile.
func (*ConfigOpts) SetupNotify ¶ added in v0.4.0
func (opts *ConfigOpts) SetupNotify()
SetupNotify sets up notify instances for each command list.
type Host ¶
type Host struct { OS string `yaml:"OS,omitempty"` ConfigFilePath string `yaml:"config,omitempty"` Host string `yaml:"host,omitempty"` HostName string `yaml:"hostname,omitempty"` KnownHostsFile string `yaml:"knownHostsFile,omitempty"` ClientConfig *ssh.ClientConfig SSHConfigFile *sshConfigFile SshClient *ssh.Client Port uint16 `yaml:"port,omitempty"` ProxyJump string `yaml:"proxyjump,omitempty"` Password string `yaml:"password,omitempty"` PrivateKeyPath string `yaml:"privateKeyPath,omitempty"` PrivateKeyPassword string `yaml:"privateKeyPassword,omitempty"` User string `yaml:"user,omitempty"` // ProxyHost holds the configuration for a ProxyJump host ProxyHost []*Host // contains filtered or unexported fields }
Host defines a host to which to connect. If not provided, the values will be looked up in the default ssh config files
func (*Host) CombineHostNameWithPort ¶ added in v0.2.0
func (remoteHost *Host) CombineHostNameWithPort()
func (*Host) ConnectThroughBastion ¶ added in v0.1.0
func (*Host) ConnectToHost ¶ added in v0.6.0
func (remoteConfig *Host) ConnectToHost(opts *ConfigOpts) error
ConnectToHost connects to a host by looking up the config values in the file ~/.ssh/config It uses any set values and looks up an unset values in the config files remoteConfig is modified directly. The *ssh.Client is returned as part of remoteConfig, If configFile is empty, any required configuration is looked up in the default config files If any value is not found, defaults are used
func (*Host) GetAuthMethods ¶ added in v0.1.0
func (remoteHost *Host) GetAuthMethods(opts *ConfigOpts) error
func (*Host) GetHostName ¶ added in v0.2.0
func (remoteHost *Host) GetHostName()
func (*Host) GetKnownHosts ¶ added in v0.5.0
GetKnownHosts resolves the host's KnownHosts file if it is defined if not defined, the default location for this file is used
func (*Host) GetPort ¶ added in v0.2.0
func (remoteHost *Host) GetPort()
GetPort checks if the port from the config file is 0 If it is the port is searched in the SSH config file(s)
func (*Host) GetPrivateKeyFileFromConfig ¶ added in v0.2.0
func (remoteHost *Host) GetPrivateKeyFileFromConfig()
GetPrivateKeyFromConfig checks to see if the privateKeyPath is empty. If not, it keeps the value. If empty, the key is looked for in the specified config file. If that path is empty, the default config file is searched. If not found in the default file, the privateKeyPath is set to ~/.ssh/id_rsa
func (*Host) GetProxyJumpConfig ¶ added in v0.2.0
func (remoteConfig *Host) GetProxyJumpConfig(hosts map[string]*Host, opts *ConfigOpts) error
func (*Host) GetProxyJumpFromConfig ¶ added in v0.2.0
func (*Host) GetSshUserFromConfig ¶ added in v0.1.0
func (remoteHost *Host) GetSshUserFromConfig()
type HttpConfig ¶ added in v0.10.2
type ListConfig ¶ added in v0.4.0
type MailConfig ¶ added in v0.4.0
type MatrixStruct ¶ added in v0.4.0
type Notifications ¶ added in v0.4.0
type Notifications struct { MailConfig map[string]MailConfig `yaml:"mail,omitempty"` MatrixConfig map[string]MatrixStruct `yaml:"matrix,omitempty"` HttpConfig map[string]HttpConfig `yaml:"http,omitempty"` }
type PackageOperation ¶ added in v0.9.0
type PackageOperation int
const ( DefaultPO PackageOperation = iota // PackOpInstall // install PackOpUpgrade // upgrade PackOpPurge // purge PackOpRemove // remove PackOpCheckVersion // checkVersion PackOpIsInstalled // isInstalled )
func PackageOperationString ¶ added in v0.9.0
func PackageOperationString(s string) (PackageOperation, error)
PackageOperationString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.
func PackageOperationValues ¶ added in v0.9.0
func PackageOperationValues() []PackageOperation
PackageOperationValues returns all values of the enum
func (PackageOperation) IsAPackageOperation ¶ added in v0.9.0
func (i PackageOperation) IsAPackageOperation() bool
IsAPackageOperation returns "true" if the value is listed in the enum definition. "false" otherwise
func (PackageOperation) MarshalJSON ¶ added in v0.9.0
func (i PackageOperation) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface for PackageOperation
func (PackageOperation) MarshalText ¶ added in v0.9.0
func (i PackageOperation) MarshalText() ([]byte, error)
MarshalText implements the encoding.TextMarshaler interface for PackageOperation
func (PackageOperation) MarshalYAML ¶ added in v0.9.0
func (i PackageOperation) MarshalYAML() (interface{}, error)
MarshalYAML implements a YAML Marshaler for PackageOperation
func (PackageOperation) String ¶ added in v0.9.0
func (i PackageOperation) String() string
func (*PackageOperation) UnmarshalJSON ¶ added in v0.9.0
func (i *PackageOperation) UnmarshalJSON(data []byte) error
UnmarshalJSON implements the json.Unmarshaler interface for PackageOperation
func (*PackageOperation) UnmarshalText ¶ added in v0.9.0
func (i *PackageOperation) UnmarshalText(text []byte) error
UnmarshalText implements the encoding.TextUnmarshaler interface for PackageOperation
func (*PackageOperation) UnmarshalYAML ¶ added in v0.9.0
func (i *PackageOperation) UnmarshalYAML(unmarshal func(interface{}) error) error
UnmarshalYAML implements a YAML Unmarshaler for PackageOperation