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 CheckConfigValues(config *koanf.Koanf, file string)
- func GetKnownHosts(khPath string) (string, error)
- func GetPassword(pass string, opts *ConfigOpts, log zerolog.Logger) (string, error)
- func GetPrivateKeyPassword(key string, opts *ConfigOpts, log zerolog.Logger) (string, error)
- func GetVaultKey(str string, opts *ConfigOpts, log zerolog.Logger) string
- func IsCmdStdOutEnabled() bool
- func IsTerminalActive() bool
- type BackyOptionFunc
- type CmdConfigSchema
- type CmdList
- type CmdOutput
- type CmdSchema
- type Command
- type ConfigOpts
- func (opts *ConfigOpts) Cron()
- func (config *ConfigOpts) ExecuteCmds(opts *ConfigOpts)
- func (opts *ConfigOpts) InitConfig()
- func (opts *ConfigOpts) InitMongo()
- func (opts *ConfigOpts) ListConfiguration()
- func (c *ConfigOpts) LogLvl(level string) BackyOptionFunc
- func (opts *ConfigOpts) RunListConfig(cron string)
- func (opts *ConfigOpts) SetupNotify()
- type Host
- func (remoteHost *Host) CombineHostNameWithPort()
- func (remoteHost *Host) ConnectThroughBastion(log zerolog.Logger) (*ssh.Client, error)
- func (remoteConfig *Host) ConnectToSSHHost(opts *ConfigOpts) error
- func (remoteHost *Host) GetAuthMethods(opts *ConfigOpts) error
- func (remoteHost *Host) GetHostName()
- 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 ListConfig
- type MailConfig
- type MatrixStruct
- type Notifications
- type Schemas
- 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: \n privatekeypassword: env:PR_KEY_PASS \n privatekeypassword: file:/path/to/password-file \n privatekeypassword: password (not recommended). \n ")
var Sprintf = fmt.Sprintf
var TS = strings.TrimSpace
Functions ¶
func CheckConfigValues ¶ added in v0.1.0
func CheckConfigValues(config *koanf.Koanf, file string)
func GetKnownHosts ¶ added in v0.1.0
func GetPassword ¶ added in v0.1.0
func GetPrivateKeyPassword ¶ added in v0.1.0
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
Types ¶
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 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
AddPrintLists adds lists to print out
func UseCron ¶ added in v0.1.0
func UseCron() BackyOptionFunc
UseCron enables the execution of command lists at specified times
type CmdConfigSchema ¶ added in v0.1.0
type Command ¶
type Command struct { // command to run Cmd string `yaml:"cmd"` // Possible values: script, scriptFile // If blank, it is regualar command. Type string `yaml:"type"` // host on which to run cmd Host *string `yaml:"host,omitempty"` /* Shell specifies which shell to run the command in, if any. Not applicable when host is defined. */ Shell string `yaml:"shell,omitempty"` RemoteHost *Host `yaml:"-"` // Args is an array that holds the arguments to cmd Args []string `yaml:"args,omitempty"` /* Dir specifies a directory in which to run the command. Ignored if Host is set. */ Dir *string `yaml:"dir,omitempty"` // Env points to a file containing env variables to be used with the command Env string `yaml:"env,omitempty"` // Environment holds env variables to be used with the command Environment []string `yaml:"environment,omitempty"` // Output determines if output is requested. // Only works if command is in a list. GetOutput bool `yaml:"getOutput,omitempty"` ScriptEnvFile string `yaml:"scriptEnvFile"` }
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:"cmd-lists"` // Hosts holds the Host config. // key is the host. Hosts map[string]*Host `yaml:"hosts"` Logger zerolog.Logger // Global log level BackyLogLvl *string // Holds config file ConfigFilePath string Schemas DB *mongo.Database List ListConfig VaultKeys []*VaultKey `yaml:"keys"` NotificationConf *Notifications `yaml:"notifications"` // contains filtered or unexported fields }
func NewOpts ¶
func NewOpts(configFilePath string, opts ...BackyOptionFunc) *ConfigOpts
func ReadConfig ¶ added in v0.1.0
func ReadConfig(opts *ConfigOpts) *ConfigOpts
ReadConfig validates and reads the config file.
func (*ConfigOpts) Cron ¶ added in v0.3.0
func (opts *ConfigOpts) Cron()
func (*ConfigOpts) ExecuteCmds ¶ added in v0.4.0
func (config *ConfigOpts) ExecuteCmds(opts *ConfigOpts)
func (*ConfigOpts) InitConfig ¶ added in v0.3.0
func (opts *ConfigOpts) InitConfig()
func (*ConfigOpts) InitMongo ¶ added in v0.3.0
func (opts *ConfigOpts) InitMongo()
func (*ConfigOpts) ListConfiguration ¶ added in v0.4.0
func (opts *ConfigOpts) ListConfiguration()
func (*ConfigOpts) LogLvl ¶ added in v0.3.0
func (c *ConfigOpts) LogLvl(level string) BackyOptionFunc
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 { 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) ConnectToSSHHost ¶
func (remoteConfig *Host) ConnectToSSHHost(opts *ConfigOpts) error
ConnectToSSHHost connects to a host by looking up the config values in the directory ~/.ssh/config It uses any set values and looks up an unset values in the config files It returns an ssh.Client used to run commands against. 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) 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 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"` }
type Schemas ¶ added in v0.1.0
type Schemas struct { CmdConfigSchema CmdSchema }