testssh

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateSettings

func CreateSettings() settings.Settings

Types

type Bastion

type Bastion struct {
	Host string
	Port string
	User string

	NoSession bool
}

type Client

type Client struct {
	Settings settings.Settings

	SessionSettings *session.Session
	// contains filtered or unexported fields
}

func NewClient

func NewClient(session *session.Session, privKeys []session.AgentPrivateKey) *Client

func (*Client) AddCommandProvider

func (c *Client) AddCommandProvider(host string, f CommandProvider) *Client

func (*Client) AddScriptProvider

func (c *Client) AddScriptProvider(host string, f UploadScriptProvider) *Client

func (*Client) Check

func (c *Client) Check() connection.Check

UploadScript is used to upload script and execute it on remote server

func (*Client) Command

func (c *Client) Command(name string, arg ...string) connection.Command

Command is used to run commands on remote server

func (*Client) File

func (c *Client) File() connection.File

File is used to upload and download files and directories

func (*Client) IsStopped

func (c *Client) IsStopped() bool

func (*Client) KubeProxy

func (c *Client) KubeProxy() connection.KubeProxy

KubeProxy is used to start kubectl proxy and create a tunnel from local port to proxy port

func (*Client) Loop

func (c *Client) Loop(fn connection.SSHLoopHandler) error

Loop Looping all available hosts

func (*Client) OnlyPreparePrivateKeys

func (c *Client) OnlyPreparePrivateKeys() error

func (*Client) PrivateKeys

func (c *Client) PrivateKeys() []session.AgentPrivateKey

func (*Client) RefreshPrivateKeys

func (c *Client) RefreshPrivateKeys() error

func (*Client) ReverseTunnel

func (c *Client) ReverseTunnel(address string) connection.ReverseTunnel

ReverseTunnel is used to open remote (R) tunnel

func (*Client) Session

func (c *Client) Session() *session.Session

func (*Client) SetFileProvider

func (c *Client) SetFileProvider(host string, f FileProvider) *Client

func (*Client) Start

func (c *Client) Start() error

func (*Client) Stop

func (c *Client) Stop()

Stop the client

func (*Client) Tunnel

func (c *Client) Tunnel(address string) connection.Tunnel

Tunnel is used to open local (L) and remote (R) tunnels

func (*Client) UploadScript

func (c *Client) UploadScript(scriptPath string, args ...string) connection.Script

UploadScript is used to upload script and execute it on remote server

func (*Client) WithSettings

func (c *Client) WithSettings(sett settings.Settings) *Client

type Command

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

func NewCommand

func NewCommand(stdOut []byte) *Command

func (*Command) Cmd

func (t *Command) Cmd(ctx context.Context)

func (*Command) CombinedOutput

func (t *Command) CombinedOutput(context.Context) ([]byte, error)

func (*Command) OnCommandStart

func (t *Command) OnCommandStart(fn func())

func (*Command) Output

func (t *Command) Output(context.Context) ([]byte, []byte, error)

func (*Command) Run

func (t *Command) Run(ctx context.Context) error

func (*Command) Start

func (t *Command) Start() error

func (*Command) StderrBytes

func (t *Command) StderrBytes() []byte

func (*Command) StdoutBytes

func (t *Command) StdoutBytes() []byte

func (*Command) Stop

func (t *Command) Stop()

func (*Command) Sudo

func (t *Command) Sudo(ctx context.Context)

func (*Command) WithEnv

func (t *Command) WithEnv(env map[string]string)

func (*Command) WithErr

func (t *Command) WithErr(err error) *Command

func (*Command) WithRun

func (t *Command) WithRun(f func()) *Command

func (*Command) WithSSHArgs

func (t *Command) WithSSHArgs(args ...string)

func (*Command) WithStdErr

func (t *Command) WithStdErr(s []byte) *Command

func (*Command) WithStderrHandler

func (t *Command) WithStderrHandler(h func(line string))

func (*Command) WithStdoutHandler

func (t *Command) WithStdoutHandler(h func(line string))

func (*Command) WithTimeout

func (t *Command) WithTimeout(timeout time.Duration)

type CommandProvider

type CommandProvider func(withBastion Bastion, scriptPath string, args ...string) *Command

type DownloadFn

type DownloadFn func(srcPath string) ([]byte, error)

type File

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

func NewFile

func NewFile(upload UploadFn, download DownloadFn) *File

func (*File) Download

func (f *File) Download(ctx context.Context, srcPath, dstPath string) error

func (*File) DownloadBytes

func (f *File) DownloadBytes(ctx context.Context, remotePath string) ([]byte, error)

func (*File) Upload

func (f *File) Upload(ctx context.Context, srcPath, dstPath string) error

func (*File) UploadBytes

func (f *File) UploadBytes(ctx context.Context, data []byte, remotePath string) error

type FileProvider

type FileProvider func(bastion Bastion) *File

type SSHProvider

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

func NewSSHProvider

func NewSSHProvider(initSession *session.Session, once bool) *SSHProvider

func (*SSHProvider) AddCommandProvider

func (p *SSHProvider) AddCommandProvider(host string, f CommandProvider) *SSHProvider

func (*SSHProvider) AddScriptProvider

func (p *SSHProvider) AddScriptProvider(host string, f UploadScriptProvider) *SSHProvider

func (*SSHProvider) Cleanup

func (p *SSHProvider) Cleanup(context.Context) error

func (*SSHProvider) Client

func (*SSHProvider) InitSession

func (p *SSHProvider) InitSession() *session.Session

func (*SSHProvider) NewAdditionalClient

func (p *SSHProvider) NewAdditionalClient(context.Context) (connection.SSHClient, error)

func (*SSHProvider) NewStandaloneClient

func (p *SSHProvider) NewStandaloneClient(ctx context.Context, sess *session.Session, privateKeys []session.AgentPrivateKey, opts ...connection.StandaloneClientOpt) (connection.SSHClient, error)

func (*SSHProvider) SetFileProvider

func (p *SSHProvider) SetFileProvider(host string, f FileProvider) *SSHProvider

func (*SSHProvider) SwitchClient

func (p *SSHProvider) SwitchClient(_ context.Context, sess *session.Session, privateKeys []session.AgentPrivateKey) (connection.SSHClient, error)

func (*SSHProvider) SwitchToDefault

func (p *SSHProvider) SwitchToDefault(ctx context.Context) (connection.SSHClient, error)

func (*SSHProvider) Switches

func (p *SSHProvider) Switches() []Switch

func (*SSHProvider) WithInitPrivateKeys

func (p *SSHProvider) WithInitPrivateKeys(k []session.AgentPrivateKey) *SSHProvider

func (*SSHProvider) WithSwitchHandler

func (p *SSHProvider) WithSwitchHandler(f SwitchHandler) *SSHProvider

type Script

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

func NewScript

func NewScript(stdOut []byte) *Script

func (*Script) Execute

func (t *Script) Execute(context.Context) ([]byte, error)

func (*Script) ExecuteBundle

func (t *Script) ExecuteBundle(ctx context.Context, parentDir, bundleDir string) ([]byte, error)

func (*Script) Sudo

func (t *Script) Sudo()

func (*Script) WithBundlerOpts

func (t *Script) WithBundlerOpts(opts ...connection.BundlerOption)

func (*Script) WithCleanupAfterExec

func (t *Script) WithCleanupAfterExec(doCleanup bool)

func (*Script) WithEnvs

func (t *Script) WithEnvs(envs map[string]string)

func (*Script) WithError

func (t *Script) WithError(err error) *Script

func (*Script) WithExecuteUploadDir

func (t *Script) WithExecuteUploadDir(dir string)

func (*Script) WithNoLogStepOutOnError

func (t *Script) WithNoLogStepOutOnError(enabled bool)

func (*Script) WithRun

func (t *Script) WithRun(f func()) *Script

func (*Script) WithStdoutHandler

func (t *Script) WithStdoutHandler(handler func(string))

func (*Script) WithTimeout

func (t *Script) WithTimeout(timeout time.Duration)

type Switch

type Switch struct {
	Bastion     Bastion
	Session     *session.Session
	PrivateKeys []session.AgentPrivateKey
}

type SwitchHandler

type SwitchHandler func(s Switch)

type UploadFn

type UploadFn func(data []byte, dstPath string) error

type UploadScriptProvider

type UploadScriptProvider func(withBastion Bastion, scriptPath string, args ...string) *Script

Jump to

Keyboard shortcuts

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