bycli

package
v22.11.9 Latest Latest
Warning

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

Go to latest
Published: May 30, 2023 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CliCommand

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

CliCommand defines a SSH command

func (*CliCommand) Close

func (scmd *CliCommand) Close() (ferr fail.Error)

Close is called to clean Command (close tunnel(s), remove temporary files, ...)

func (*CliCommand) CombinedOutput

func (scmd *CliCommand) CombinedOutput() ([]byte, fail.Error)

CombinedOutput returns the combined standard of command started output and standard error.

func (*CliCommand) Kill

func (scmd *CliCommand) Kill() fail.Error

Kill kills Command process.

func (*CliCommand) Output

func (scmd *CliCommand) Output() ([]byte, fail.Error)

Output returns the standard output of command started. Any returned error will usually be of type *ExitError. If c.Stderr was nil, Output populates ExitError.Stderr.

func (*CliCommand) RunWithTimeout

func (scmd *CliCommand) RunWithTimeout(inctx context.Context, outs outputs.Enum, timeout time.Duration) (int, string, string, fail.Error)

RunWithTimeout ... returns:

  • retcode int
  • stdout string
  • stderr string
  • xerr fail.Error . *fail.ErrNotAvailable if remote SSH is not available . *fail.ErrTimeout if 'timeout' is reached

Note: if you want to RunWithTimeout in a loop, you MUST create the scmd inside the loop, otherwise you risk to call twice os/exec.Wait, which may panic

func (*CliCommand) Start

func (scmd *CliCommand) Start() fail.Error

Start starts the specified command but does not wait for it to complete. The Wait method will wait for completion and return the exit code.

func (*CliCommand) String

func (scmd *CliCommand) String() string

func (*CliCommand) Wait

func (scmd *CliCommand) Wait() error

Wait waits for the command to exit and waits for any copying to stdin or copying from stdout or stderr to complete. The command must have been started by Start. The returned error is nil if the command runs, has no problems copying stdin, stdout, and stderr, and exits with a zero exit status. If the command fails to run or doesn't complete successfully, the error is of type *ExitError. Other error types may be returned for I/O problems. Wait also waits for the I/O loop copying from c.Stdin into the process's standard input to complete. Wait does not release resources associated with the cmd; Command.Close() must be called for that. !!!WARNING!!!: the error returned is NOT USING fail.Error because we may NEED TO CAST the error to recover return code

type Profile

type Profile struct {
	Hostname               string        `json:"hostname"`
	IPAddress              string        `json:"ip_address"`
	Port                   int           `json:"port"`
	User                   string        `json:"user"`
	PrivateKey             string        `json:"private_key"`
	LocalPort              int           `json:"-"`
	LocalHost              string        `json:"local_host"`
	GatewayConfig          sshapi.Config `json:"primary_gateway_config,omitempty"`
	SecondaryGatewayConfig sshapi.Config `json:"secondary_gateway_config,omitempty"`
}

Profile helper to manage ssh session

func NewConnector

func NewConnector(ac sshapi.Config) (*Profile, fail.Error)

func NewProfile

func NewProfile(hostname string, ipAddress string, port int, user string, privateKey string, localPort int, localHost string, gatewayConfig sshapi.Config, secondaryGatewayConfig sshapi.Config) *Profile

func (*Profile) Clone

func (sconf *Profile) Clone() *Profile

Clone clones the Profile

func (*Profile) Config

func (sconf *Profile) Config() (sshapi.Config, fail.Error)

func (*Profile) CopyWithTimeout

func (sconf *Profile) CopyWithTimeout(
	inctx context.Context, remotePath, localPath string, isUpload bool, timeout time.Duration,
) (int, string, string, fail.Error)

CopyWithTimeout copies a file/directory from/to local to/from remote, and fails after 'timeout'

func (*Profile) CreatePersistentTunneling

func (sconf *Profile) CreatePersistentTunneling() (ferr fail.Error)

func (*Profile) CreateTunneling

func (sconf *Profile) CreateTunneling() (_ Tunnels, _ *Profile, ferr fail.Error)

CreateTunneling ...

func (*Profile) Enter

func (sconf *Profile) Enter(ctx context.Context, username string, shell string) (ferr fail.Error)

Enter to interactive shell, aka 'safescale ssh connect'

func (*Profile) GetGatewayConfig

func (sconf *Profile) GetGatewayConfig(num uint) (sshapi.Config, fail.Error)

func (*Profile) GetHostname

func (sconf *Profile) GetHostname() (string, fail.Error)

func (*Profile) GetIPAddress

func (sconf *Profile) GetIPAddress() (string, fail.Error)

func (*Profile) GetLocalHost

func (sconf *Profile) GetLocalHost() (string, fail.Error)

func (*Profile) GetLocalPort

func (sconf *Profile) GetLocalPort() (uint, fail.Error)

func (*Profile) GetPort

func (sconf *Profile) GetPort() (uint, fail.Error)

func (*Profile) GetPrimaryGatewayConfig

func (sconf *Profile) GetPrimaryGatewayConfig() (sshapi.Config, fail.Error)

func (*Profile) GetPrivateKey

func (sconf *Profile) GetPrivateKey() (string, fail.Error)

func (*Profile) GetSecondaryGatewayConfig

func (sconf *Profile) GetSecondaryGatewayConfig() (sshapi.Config, fail.Error)

func (*Profile) GetUser

func (sconf *Profile) GetUser() (string, fail.Error)

func (*Profile) HasGateways

func (sconf *Profile) HasGateways() (bool, fail.Error)

func (*Profile) IsNull

func (sconf *Profile) IsNull() bool

IsNull tells if the instance is a null value

func (*Profile) NewCommand

func (sconf *Profile) NewCommand(ctx context.Context, cmdString string) (sshapi.Command, fail.Error)

NewCommand returns the cmd struct to execute runCmdString remotely

func (*Profile) NewSudoCommand

func (sconf *Profile) NewSudoCommand(ctx context.Context, cmdString string) (sshapi.Command, fail.Error)

NewSudoCommand returns the cmd struct to execute runCmdString remotely. NewCommand is executed with sudo

func (*Profile) WaitServerReady

func (sconf *Profile) WaitServerReady(ctx context.Context, phase string, timeout time.Duration) (out string, ferr fail.Error)

WaitServerReady waits until the SSH server is ready

type Tunnel

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

Tunnel a SSH tunnel

func (*Tunnel) Close

func (stun *Tunnel) Close() fail.Error

Close closes ssh tunnel

type Tunnels

type Tunnels []*Tunnel

func (Tunnels) Close

func (tunnels Tunnels) Close() fail.Error

Close closes all the tunnels

Jump to

Keyboard shortcuts

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