gossh

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: 33 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckLocalPath

func CheckLocalPath(path string) (string, error)

CheckLocalPath see if file exists and determine if it is a directory. Error is returned if file is not exists.

func CopyFile

func CopyFile(
	ctx context.Context,
	fileReader io.Reader,
	remotePath string,
	permissions string,
	session *gossh.Session,
) error

func CreateEmptyTmpFile

func CreateEmptyTmpFile(sett settings.Settings) (string, error)

Types

type Client

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

func NewClient

func NewClient(ctx context.Context, sett settings.Settings, session *session.Session, privKeys []session.AgentPrivateKey) *Client

func (*Client) Check

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

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

func (*Client) Command

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

Command is used to run commands on remote server

func (*Client) File

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

File is used to upload and download files and directories

func (*Client) GetClient

func (s *Client) GetClient() *gossh.Client

func (*Client) IsStopped

func (s *Client) IsStopped() bool

func (*Client) KubeProxy

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

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

func (*Client) Live

func (s *Client) Live() bool

func (*Client) Loop

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

Loop Looping all available hosts

func (*Client) NewSSHSession

func (s *Client) NewSSHSession() (*gossh.Session, error)

func (*Client) OnlyPreparePrivateKeys

func (s *Client) OnlyPreparePrivateKeys() error

func (*Client) PrivateKeys

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

func (*Client) RefreshPrivateKeys

func (s *Client) RefreshPrivateKeys() error

func (*Client) ReverseTunnel

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

ReverseTunnel is used to open remote (R) tunnel

func (*Client) Session

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

func (*Client) Settings

func (s *Client) Settings() settings.Settings

func (*Client) Start

func (s *Client) Start() error

func (*Client) Stop

func (s *Client) Stop()

Stop the client

func (*Client) Tunnel

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

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

func (*Client) UnregisterSession

func (s *Client) UnregisterSession(sess *gossh.Session)

func (*Client) UploadScript

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

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

func (*Client) WithID

func (s *Client) WithID(id string) *Client

func (*Client) WithLoopsParams

func (s *Client) WithLoopsParams(p ClientLoopsParams) *Client

type ClientLoopsParams

type ClientLoopsParams struct {
	ConnectToBastion        retry.Params
	ConnectToHostViaBastion retry.Params
	ConnectToHostDirectly   retry.Params
	NewSession              retry.Params
	CheckReverseTunnel      retry.Params
}

type KubeProxy

type KubeProxy struct {
	*kubeproxy.BaseKubeProxy
}

func NewKubeProxy

func NewKubeProxy(client *Client) *KubeProxy

type PassThru

type PassThru func(r io.Reader, total int64) io.Reader

type ReverseTunnel

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

func NewReverseTunnel

func NewReverseTunnel(sshClient *Client, address string) *ReverseTunnel

func (*ReverseTunnel) StartHealthMonitor

func (*ReverseTunnel) Stop

func (t *ReverseTunnel) Stop()

func (*ReverseTunnel) String

func (t *ReverseTunnel) String() string

func (*ReverseTunnel) Up

func (t *ReverseTunnel) Up() error

type SSHCommand

type SSHCommand struct {
	Name string
	Args []string
	Env  []string

	SSHArgs []string

	StdoutSplitter bufio.SplitFunc

	StdinPipe bool
	Stdin     io.WriteCloser

	Matchers     []*utils.ByteSequenceMatcher
	MatchHandler func(pattern string) string

	WaitHandler func(err error)

	OutBytes bytes.Buffer
	ErrBytes bytes.Buffer

	Cancel func() error
	// contains filtered or unexported fields
}

func NewSSHCommand

func NewSSHCommand(client *Client, name string, arg ...string) *SSHCommand

func (*SSHCommand) CaptureStderr

func (c *SSHCommand) CaptureStderr(buf *bytes.Buffer) *SSHCommand

func (*SSHCommand) CaptureStdout

func (c *SSHCommand) CaptureStdout(buf *bytes.Buffer) *SSHCommand

func (*SSHCommand) Cmd

func (c *SSHCommand) Cmd(ctx context.Context)

func (*SSHCommand) CombinedOutput

func (c *SSHCommand) CombinedOutput(ctx context.Context) ([]byte, error)

func (*SSHCommand) ConsumeLines

func (c *SSHCommand) ConsumeLines(r io.Reader, fn func(l string))

func (*SSHCommand) OnCommandStart

func (c *SSHCommand) OnCommandStart(fn func())

func (*SSHCommand) OpenStdinPipe

func (c *SSHCommand) OpenStdinPipe() *SSHCommand

func (*SSHCommand) Output

func (c *SSHCommand) Output(ctx context.Context) ([]byte, []byte, error)

func (*SSHCommand) ProcessWait

func (c *SSHCommand) ProcessWait()

func (*SSHCommand) Run

func (c *SSHCommand) Run(ctx context.Context) error

func (*SSHCommand) SetupStreamHandlers

func (c *SSHCommand) SetupStreamHandlers() error

func (*SSHCommand) Start

func (c *SSHCommand) Start() error

func (*SSHCommand) StderrBytes

func (c *SSHCommand) StderrBytes() []byte

func (*SSHCommand) StdoutBytes

func (c *SSHCommand) StdoutBytes() []byte

func (*SSHCommand) Stop

func (c *SSHCommand) Stop()

func (*SSHCommand) Sudo

func (c *SSHCommand) Sudo(ctx context.Context)

func (*SSHCommand) WaitError

func (c *SSHCommand) WaitError() error

func (*SSHCommand) WithEnv

func (c *SSHCommand) WithEnv(env map[string]string)

func (*SSHCommand) WithMatchHandler

func (c *SSHCommand) WithMatchHandler(fn func(pattern string) string) *SSHCommand

func (*SSHCommand) WithMatchers

func (c *SSHCommand) WithMatchers(matchers ...*utils.ByteSequenceMatcher) *SSHCommand

func (*SSHCommand) WithSSHArgs

func (c *SSHCommand) WithSSHArgs(args ...string)

func (*SSHCommand) WithStderrHandler

func (c *SSHCommand) WithStderrHandler(handler func(string))

func (*SSHCommand) WithStdoutHandler

func (c *SSHCommand) WithStdoutHandler(handler func(string))

func (*SSHCommand) WithTimeout

func (c *SSHCommand) WithTimeout(timeout time.Duration)

func (*SSHCommand) WithWaitHandler

func (c *SSHCommand) WithWaitHandler(waitHandler func(error)) *SSHCommand

type SSHFile

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

func NewSSHFile

func NewSSHFile(sett settings.Settings, client *Client) *SSHFile

func (*SSHFile) Download

func (f *SSHFile) Download(ctx context.Context, remotePath, dstPath string) error

func (*SSHFile) DownloadBytes

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

Download remote file and returns its content as an array of bytes.

func (*SSHFile) Upload

func (f *SSHFile) Upload(ctx context.Context, srcPath, remotePath string) error

func (*SSHFile) UploadBytes

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

UploadBytes creates a tmp file and upload it to remote dstPath

type SSHUploadScript

type SSHUploadScript struct {
	ScriptPath string
	Args       []string
	// contains filtered or unexported fields
}

func NewSSHUploadScript

func NewSSHUploadScript(sshClient *Client, scriptPath string, args ...string) *SSHUploadScript

func (*SSHUploadScript) Execute

func (u *SSHUploadScript) Execute(ctx context.Context) ([]byte, error)

func (*SSHUploadScript) ExecuteBundle

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

func (*SSHUploadScript) IsSudo

func (u *SSHUploadScript) IsSudo() bool

func (*SSHUploadScript) Settings

func (u *SSHUploadScript) Settings() settings.Settings

func (*SSHUploadScript) Sudo

func (u *SSHUploadScript) Sudo()

func (*SSHUploadScript) UploadDir

func (u *SSHUploadScript) UploadDir() string

func (*SSHUploadScript) WithBundlerOpts

func (u *SSHUploadScript) WithBundlerOpts(opts ...connection.BundlerOption)

func (*SSHUploadScript) WithCleanupAfterExec

func (u *SSHUploadScript) WithCleanupAfterExec(doCleanup bool)

WithCleanupAfterExec option tells if ssh executor should delete uploaded script after execution was attempted or not. It does not care if script was executed successfully of failed.

func (*SSHUploadScript) WithEnvs

func (u *SSHUploadScript) WithEnvs(envs map[string]string)

func (*SSHUploadScript) WithExecuteUploadDir

func (u *SSHUploadScript) WithExecuteUploadDir(dir string)

func (*SSHUploadScript) WithNoLogStepOutOnError

func (u *SSHUploadScript) WithNoLogStepOutOnError(enabled bool)

func (*SSHUploadScript) WithStdoutHandler

func (u *SSHUploadScript) WithStdoutHandler(handler func(string))

func (*SSHUploadScript) WithTimeout

func (u *SSHUploadScript) WithTimeout(timeout time.Duration)

type Tunnel

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

func NewTunnel

func NewTunnel(sshClient *Client, address string) *Tunnel

func (*Tunnel) HealthMonitor

func (t *Tunnel) HealthMonitor(errorOutCh chan<- error)

func (*Tunnel) Stop

func (t *Tunnel) Stop()

func (*Tunnel) String

func (t *Tunnel) String() string

func (*Tunnel) Up

func (t *Tunnel) Up(ctx context.Context) error

Jump to

Keyboard shortcuts

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