ssh

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2024 License: MPL-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthMethod

type AuthMethod interface {
	Method() gossh.AuthMethod
}

AuthMethod abstracts the SSH authentication method

type BaseClient

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

BaseClient provides a base implementation of the Client interface

func (*BaseClient) SetClientConfig

func (c *BaseClient) SetClientConfig(config *ClientConfig)

SetClientConfig sets the client configuration for the SSH client

func (*BaseClient) SetClientConfigFile

func (c *BaseClient) SetClientConfigFile(configStr, hostname string) error

SetClientConfigFile sets the client configuration from a string (either a filename or config content) and a hostname

type Client

type Client interface {
	Dial(network, addr string, config *ClientConfig) (ClientConn, error)
	Connect() (ClientConn, error)
	SetClientConfig(config *ClientConfig)
	SetClientConfigFile(configStr, hostname string) error
}

Client interface abstracts the SSH client

type ClientConfig

type ClientConfig struct {
	User            string
	Auth            []AuthMethod
	HostKeyCallback HostKeyCallback
	HostName        string
	Port            string
}

ClientConfig abstracts the SSH client configuration

type ClientConn

type ClientConn interface {
	Close() error
	NewSession() (Session, error)
}

ClientConn interface abstracts the SSH client connection

type HostKeyCallback

type HostKeyCallback interface {
	Callback() gossh.HostKeyCallback
}

HostKeyCallback abstracts the SSH host key callback

type MockAuthMethod

type MockAuthMethod struct {
	MethodFunc func() interface{}
}

MockAuthMethod is the mock implementation of the AuthMethod interface

func (*MockAuthMethod) Method

func (m *MockAuthMethod) Method() gossh.AuthMethod

type MockClient

type MockClient struct {
	DialFunc                func(network, addr string, config *ClientConfig) (ClientConn, error)
	ConnectFunc             func() (ClientConn, error)
	SetClientConfigFunc     func(config *ClientConfig)
	SetClientConfigFileFunc func(configStr, hostname string) error
}

MockClient is the mock implementation of the Client interface

func NewMockSSHClient

func NewMockSSHClient() *MockClient

NewMockSSHClient creates a new MockClient with default function implementations

func (*MockClient) Connect

func (m *MockClient) Connect() (ClientConn, error)

func (*MockClient) Dial

func (m *MockClient) Dial(network, addr string, config *ClientConfig) (ClientConn, error)

func (*MockClient) SetClientConfig

func (m *MockClient) SetClientConfig(config *ClientConfig)

func (*MockClient) SetClientConfigFile

func (m *MockClient) SetClientConfigFile(configStr, hostname string) error

type MockClientConn

type MockClientConn struct {
	NewSessionFunc func() (Session, error)
	CloseFunc      func() error
}

MockClientConn is the mock implementation of the ClientConn interface

func (*MockClientConn) Close

func (m *MockClientConn) Close() error

func (*MockClientConn) NewSession

func (m *MockClientConn) NewSession() (Session, error)

type MockHostKeyCallback

type MockHostKeyCallback struct {
	CallbackFunc func() interface{}
}

MockHostKeyCallback is the mock implementation of the HostKeyCallback interface

func (*MockHostKeyCallback) Callback

type MockPublicKeyAuthMethod

type MockPublicKeyAuthMethod struct {
	SignerFunc func() gossh.Signer
}

MockPublicKeyAuthMethod is the mock implementation of the PublicKeyAuthMethod interface

func (*MockPublicKeyAuthMethod) Method

type MockSession

type MockSession struct {
	RunFunc            func(cmd string) error
	CombinedOutputFunc func(cmd string) ([]byte, error)
	SetStdoutFunc      func(w io.Writer)
	SetStderrFunc      func(w io.Writer)
	CloseFunc          func() error
}

MockSession is the mock implementation of the Session interface

func (*MockSession) Close

func (m *MockSession) Close() error

func (*MockSession) CombinedOutput

func (m *MockSession) CombinedOutput(cmd string) ([]byte, error)

func (*MockSession) Run

func (m *MockSession) Run(cmd string) error

func (*MockSession) SetStderr

func (m *MockSession) SetStderr(w io.Writer)

func (*MockSession) SetStdout

func (m *MockSession) SetStdout(w io.Writer)

type PublicKeyAuthMethod

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

PublicKeyAuthMethod implements the AuthMethod interface using a public key

func (*PublicKeyAuthMethod) Method

func (p *PublicKeyAuthMethod) Method() gossh.AuthMethod

type RealClientConn

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

RealClientConn wraps *gossh.Client and implements the ClientConn interface

func (*RealClientConn) Close

func (c *RealClientConn) Close() error

Close closes the client connection

func (*RealClientConn) NewSession

func (c *RealClientConn) NewSession() (Session, error)

NewSession creates a new SSH session

type RealSession

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

RealSession wraps *gossh.Session and implements the Session interface

func (*RealSession) Close

func (s *RealSession) Close() error

func (*RealSession) CombinedOutput

func (s *RealSession) CombinedOutput(cmd string) ([]byte, error)

func (*RealSession) Run

func (s *RealSession) Run(cmd string) error

func (*RealSession) SetStderr

func (s *RealSession) SetStderr(w io.Writer)

func (*RealSession) SetStdout

func (s *RealSession) SetStdout(w io.Writer)

type SSHClient

type SSHClient struct {
	BaseClient
}

SSHClient is the real implementation of the Client interface

func NewSSHClient

func NewSSHClient() *SSHClient

NewSSHClient creates a new SSHClient with the default SSH config path

func (*SSHClient) Connect

func (c *SSHClient) Connect() (ClientConn, error)

Connect connects to the SSH server using the provided client configuration

func (*SSHClient) Dial

func (c *SSHClient) Dial(network, addr string, config *ClientConfig) (ClientConn, error)

Dial connects to the SSH server and returns a client connection

type Session

type Session interface {
	Run(cmd string) error
	CombinedOutput(cmd string) ([]byte, error)
	SetStdout(w io.Writer)
	SetStderr(w io.Writer)
	Close() error
}

Session interface abstracts the SSH session

Jump to

Keyboard shortcuts

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