sshclient

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: May 31, 2024 License: MPL-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Tcp = "tcp"
)

Variables

This section is empty.

Functions

func NewHostPortAddr

func NewHostPortAddr(net string, host string, port uint16) net.Addr

func ParseBase64PublicKey

func ParseBase64PublicKey(publicKey string) (ssh.PublicKey, error)

ParseBase64PublicKey parses a base64 encoded SSH public key using ssh.ParsePublicKey

Types

type AuthMethod

type AuthMethod func() ([]ssh.AuthMethod, error)

func Agent

func Agent() AuthMethod

func AgentExplicitIdentities

func AgentExplicitIdentities(identities ...string) AuthMethod

func Certificate

func Certificate(cert string, privateKey string) AuthMethod

func Password

func Password(password string) AuthMethod

func PrivateKey

func PrivateKey(privateKey string) AuthMethod

PrivateKey returns an AuthMethod which authenticates using a private key.

type Client

type Client struct {
	*ssh.Client
	// contains filtered or unexported fields
}

Client is high level ssh client which relies on golang.org/x/crypto/ssh

func New

func New(connectFunc ConnectFunc) *Client

func (*Client) Close

func (c *Client) Close() error

func (*Client) Connect

func (c *Client) Connect(ctx context.Context) error

Connect establishes an ssh connection.

func (*Client) Connected

func (c *Client) Connected(ctx context.Context) error

Connected ensures that an ssh connection is established.

type ConnectFunc

type ConnectFunc func(ctx context.Context) (ssh.Conn, <-chan ssh.NewChannel, <-chan *ssh.Request, error)

func Connect

func Connect(opts ...ConnectOption) ConnectFunc

Connect returns a ConnectFunc which validates the provided ConnectOption when the connection is established.

func ConnectCustom

func ConnectCustom(netConnectFunc NetConnectFunc, addr net.Addr, clientConfig *ssh.ClientConfig) ConnectFunc

ConnectCustom returns a ConnectFunc to a remote net.Addr using a connection method NetConnectFunc. The underlying ssh client is configured in ssh.ClientConfig. ConnectCustom allows for the highest d be used when more convenient ConnectFunc factory functions cannot be applied

func Prepare

func Prepare(opts ...ConnectOption) (ConnectFunc, error)

Prepare returns a ConnectFunc and validates the provided ConnectOption immediately

type ConnectMiddleware

type ConnectMiddleware func(ConnectFunc) ConnectFunc

func CircuitBreak

func CircuitBreak() ConnectMiddleware

CircuitBreak wraps a ConnectFunc and ensures that the ConnectFunc will not be called again when a previous call returned an error. If the ConnectFunc has returned an error previously, CircuitBreak will not call it again and return the same error.

func Retry

func Retry(backoff retry.Backoff) ConnectMiddleware

Retry wraps a NetConnectFunc and attempts retries according to the provided retry.Backoff

type ConnectOption

type ConnectOption func(*connectArgs) error

func Addr

func Addr(addr net.Addr) ConnectOption

func Auth

func Auth(authMethod AuthMethod) ConnectOption

func HostKey

func HostKey(hostKeyVerifier HostKeyVerifier) ConnectOption

func HostKeyCallback

func HostKeyCallback(callback ssh.HostKeyCallback) ConnectOption

func Net

func Net(netConnectFunc NetConnectFunc) ConnectOption

func Timeout

func Timeout(timeout time.Duration) ConnectOption

func User

func User(user string) ConnectOption

type HostKeyVerifier

type HostKeyVerifier func() (ssh.HostKeyCallback, error)

func StaticHostKey

func StaticHostKey(publicKey string) HostKeyVerifier

StaticHostKey returns an ssh.HostKeyCallback which accepts only the provided public key. StaticHostKey expects a base64 encoded public key which is parsed using ssh.ParsePublicKey. StaticHostKey uses ssh.FixedHostKey with the decoded public key. Use ssh.FixedHostKey instead of StaticHostKey if an ssh.PublicKey is already available.

type NetConnectFunc

type NetConnectFunc func(context.Context) (net.Conn, error)

func Dial

func Dial(addr net.Addr, timeout time.Duration) NetConnectFunc

Dial returns a NetConnectFunc which connects to the remote via net.Dial

func Proxy

func Proxy(proxy *Client, addr net.Addr) NetConnectFunc

Proxy returns a NetConnectFunc which connects to the remote via a proxy Client

type NetConnectMiddleware

type NetConnectMiddleware func(NetConnectFunc) NetConnectFunc

func NetCircuitBreaker

func NetCircuitBreaker() NetConnectMiddleware

NetCircuitBreaker wraps a NetConnectFunc and ensures that the NetConnectFunc will not be called again when a previous call returned an error. If the NetConnectFunc has returned an error previously, NetCircuitBreaker will not call it again and return the same error.

func NetRetry

func NetRetry(backoff retry.Backoff) NetConnectMiddleware

NetRetry wraps a NetConnectFunc and attempts retries according to the provided retry.Backoff

Jump to

Keyboard shortcuts

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