ssh

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2019 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Command

type Command struct {
	Command    string
	Stdin      bytes.Buffer
	Stdout     bytes.Buffer
	Stderr     bytes.Buffer
	ExitStatus int
}

Command encapsulate a remote command

type CommandResult

type CommandResult struct {
	Hosts    HostCommandResultMap
	Success  uint32 `json:"success" yaml:"success" toml:"success" mapstructure:"success"`
	Failures uint32 `json:"failures" yaml:"failures" toml:"failures" mapstructure:"failures"`
}

CommandResult encapsulate the results of a command execution per host

func (*CommandResult) JSON

func (r *CommandResult) JSON(pp bool) ([]byte, error)

JSON returns the command result in JSON format. With pp will be an indent JSON

func (*CommandResult) TOML

func (r *CommandResult) TOML() ([]byte, error)

TOML returns the command result in TOML format

func (*CommandResult) YAML

func (r *CommandResult) YAML() ([]byte, error)

YAML returns the command result in YAML format

type Config

type Config struct {
	Address string
	// contains filtered or unexported fields
}

Config store the SSH configuration

func New

func New(username, address, privateKey, password string) (*Config, error)

New returns an instance of the SSH configuration

func (*Config) Close

func (c *Config) Close() error

Close closes the client connection if exists

func (*Config) CreateFile

func (c *Config) CreateFile(target, data string, perm os.FileMode) error

CreateFile creates a file with the filename 'target' and the given content using the uid, gid and permissions provided.

func (*Config) CreateFileWithReader

func (c *Config) CreateFileWithReader(target string, reader io.Reader, perm os.FileMode) error

CreateFileWithReader creates a file with the filename 'target' and the given content using the uid, gid and permissions provided.

func (*Config) CreateGroup

func (c *Config) CreateGroup(name string) error

CreateGroup create group for users

func (*Config) CreateZip

func (c *Config) CreateZip(target, data string) error

CreateZip creates a zip file with the filename 'target' and content given in 'data'

func (*Config) Exec

func (c *Config) Exec(command string) (stdOut string, stdErr string, exitStatus int, err error)

Exec executes a command in the remote host

func (*Config) ExecAndWait

func (c *Config) ExecAndWait(command string) (stdOut string, stdErr string, exitStatus int, err error)

ExecAndWait executes a command in the remote host and waits for it to exit

func (*Config) ExistsFile

func (c *Config) ExistsFile(file string) (bool, error)

ExistsFile return true if a file exists

func (*Config) GetFile

func (c *Config) GetFile(to, from string, perm os.FileMode) (int64, error)

GetFile streams a file from the remote host and writes it out to "to"

func (*Config) MkDir

func (c *Config) MkDir(dir string) error

MkDir creates a remote directory

func (*Config) SetChmod

func (c *Config) SetChmod(name, mode string) error

SetChmod to set the permissions of a remote object

func (*Config) SetChown

func (c *Config) SetChown(name string, uid string) error

SetChown to set the owner of a remote object

func (*Config) Shell

func (c *Config) Shell(inReader io.Reader, outWriter, errWriter io.Writer) error

Shell initiate an interactive remote shell

func (*Config) Start

func (c *Config) Start(cmd *Command) error

Start initiate the connection and runs command on remote host

func (*Config) StartAndWait

func (c *Config) StartAndWait(cmd *Command) error

StartAndWait initiates the connection, runs command on remote host and waits for output

func (*Config) SudoMkDir

func (c *Config) SudoMkDir(dir string) error

SudoMkDir creates a remote directory

func (*Config) UnZip

func (c *Config) UnZip(target, data string) error

UnZip unzips the content of 'data' into the remote directory given in 'target'

func (*Config) UserMod

func (c *Config) UserMod(name string, group string) error

UserMod adds user to group

type HostCommandResult

type HostCommandResult struct {
	Stdout     string `json:"stdout" yaml:"stdout" toml:"stdout" mapstructure:"stdout"`
	Stderr     string `json:"stderr" yaml:"stderr" toml:"stderr" mapstructure:"stderr"`
	ExitStatus int    `json:"exitstatus" yaml:"exitstatus" toml:"exitstatus" mapstructure:"exitstatus"`
}

HostCommandResult encapsulate the results of a command from one host

type HostCommandResultMap

type HostCommandResultMap struct {
	sync.RWMutex `json:"-" yaml:"-" toml:"-" mapstructure:"-"`
	Results      map[string]*HostCommandResult `json:"hosts" yaml:"hosts" toml:"hosts" mapstructure:"hosts"` // this was set to an exportable field to allow for easier marshaling
}

HostCommandResultMap is a type safe map wrapped with mutex locks around get/set calls where the keys are the hosts and values are HostCommandResults

func NewHostCommandResultMap

func NewHostCommandResultMap() HostCommandResultMap

NewHostCommandResultMap initializes/makes the map

func (*HostCommandResultMap) GetSnapshot

func (rm *HostCommandResultMap) GetSnapshot() map[string]*HostCommandResult

GetSnapshot returns a snapshot of the given HostCommandResultMap

func (*HostCommandResultMap) Load

Load returns the HostCommandResult associated with the host in the given HostCommandResultMap

func (*HostCommandResultMap) Store

func (rm *HostCommandResultMap) Store(key string, value *HostCommandResult)

Store updates the value at the given key in the given HostCommandResultMap

Jump to

Keyboard shortcuts

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