backy

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2023 License: Apache-2.0 Imports: 40 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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 ")
View Source
var Sprintf = fmt.Sprintf

Functions

func CheckConfigValues added in v0.1.0

func CheckConfigValues(config *koanf.Koanf, file string)

func GetKnownHosts added in v0.1.0

func GetKnownHosts(khPath string) (string, error)

func GetPassword added in v0.1.0

func GetPassword(pass string, opts *ConfigOpts, log zerolog.Logger) (string, error)

func GetPrivateKeyPassword added in v0.1.0

func GetPrivateKeyPassword(key string, opts *ConfigOpts, log zerolog.Logger) (string, error)

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 CmdConfigSchema struct {
	ID      primitive.ObjectID `bson:"_id,omitempty"`
	CmdList []string           `bson:"command-list,omitempty"`
	Name    string             `bson:"name,omitempty"`
}

type CmdList added in v0.1.0

type CmdList struct {
	Name          string   `yaml:"name,omitempty"`
	Cron          string   `yaml:"cron,omitempty"`
	Order         []string `yaml:"order,omitempty"`
	Notifications []string `yaml:"notifications,omitempty"`
	GetOutput     bool     `yaml:"getOutput,omitempty"`
	NotifyConfig  *notify.Notify
}

type CmdOutput

type CmdOutput struct {
	Err    error
	Output bytes.Buffer
}

type CmdSchema added in v0.1.0

type CmdSchema struct {
	ID   primitive.ObjectID `bson:"_id,omitempty"`
	Cmd  string             `bson:"cmd,omitempty"`
	Args []string           `bson:"args,omitempty"`
	Host string             `bson:"host,omitempty"`
	Dir  string             `bson:"dir,omitempty"`
}

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"`
}

func (*Command) RunCmd

func (command *Command) RunCmd(cmdCtxLogger zerolog.Logger, opts *ConfigOpts) ([]string, error)

RunCmd runs a Command. The environment of local commands will be the machine's environment plus any extra variables specified in the Env file or Environment. Dir can also be specified for local commands.

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 (remoteHost *Host) ConnectThroughBastion(log zerolog.Logger) (*ssh.Client, error)

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 (remoteConfig *Host) GetProxyJumpFromConfig(hosts map[string]*Host) error

func (*Host) GetSshUserFromConfig added in v0.1.0

func (remoteHost *Host) GetSshUserFromConfig()

type ListConfig added in v0.4.0

type ListConfig struct {
	Lists    []string
	Commands []string
	Hosts    []string
}

type MailConfig added in v0.4.0

type MailConfig struct {
	Host          string   `yaml:"host"`
	Port          string   `yaml:"port"`
	Username      string   `yaml:"username"`
	SenderAddress string   `yaml:"senderaddress"`
	To            []string `yaml:"to"`
	Password      string   `yaml:"password"`
}

type MatrixStruct added in v0.4.0

type MatrixStruct struct {
	Homeserver  string    `yaml:"homeserver"`
	Roomid      id.RoomID `yaml:"room-id"`
	AccessToken string    `yaml:"access-token"`
	UserId      id.UserID `yaml:"user-id"`
}

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
}

type VaultConfig added in v0.3.0

type VaultConfig struct {
	Token   string      `yaml:"token"`
	Address string      `yaml:"address"`
	Enabled string      `yaml:"enabled"`
	Keys    []*VaultKey `yaml:"keys"`
}

type VaultKey added in v0.3.0

type VaultKey struct {
	Name      string `yaml:"name"`
	Path      string `yaml:"path"`
	ValueType string `yaml:"type"`
	MountPath string `yaml:"mountpath"`
}

Jump to

Keyboard shortcuts

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