ssh

package
v1.0.21 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: MIT Imports: 27 Imported by: 1

Documentation

Overview

Package ssh implements SSH transport.

Index

Constants

View Source
const (
	NoStatusResult = -1000
)

Variables

This section is empty.

Functions

func DialConnCtx

func DialConnCtx(ctx context.Context, conn net.Conn, addr string, config *ssh.ClientConfig) (*ssh.Client, error)

func DialCtx

func DialCtx(ctx context.Context, endpoint Endpoint, additionalEndpoints []Endpoint, config *ssh.ClientConfig, logger *zap.Logger) (*ssh.Client, error)

DialCtx ssh.Dial version with context arg

Types

type Endpoint

type Endpoint struct {
	Host    string
	Port    int
	Network Network
}

func NewEndpoint

func NewEndpoint(host string, port int, network Network) Endpoint

func (*Endpoint) Addr added in v1.0.19

func (endpoint *Endpoint) Addr() string

func (Endpoint) String

func (endpoint Endpoint) String() string

type Network added in v1.0.19

type Network string
const (
	TCP   Network = "tcp"
	TCPv4 Network = "tcp4"
	TCPv6 Network = "tcp6"
)

type SSHSignersLogger

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

SSHSignersLogger wraps ssh.Signer interface in order to log actions relateds to keys

func NewSSHSignersLogger

func NewSSHSignersLogger(s ssh.Signer, logger *zap.Logger) *SSHSignersLogger

func (SSHSignersLogger) PublicKey

func (m SSHSignersLogger) PublicKey() ssh.PublicKey

func (SSHSignersLogger) Sign

func (m SSHSignersLogger) Sign(rand io.Reader, data []byte) (*ssh.Signature, error)

type SSHSignersLoggerAlgorithmSigner

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

func NewSSHSignersAlgorithmSignerLogger

func NewSSHSignersAlgorithmSignerLogger(s ssh.AlgorithmSigner, logger *zap.Logger) *SSHSignersLoggerAlgorithmSigner

func (SSHSignersLoggerAlgorithmSigner) PublicKey

func (SSHSignersLoggerAlgorithmSigner) Sign

func (m SSHSignersLoggerAlgorithmSigner) Sign(rand io.Reader, data []byte) (*ssh.Signature, error)

func (SSHSignersLoggerAlgorithmSigner) SignWithAlgorithm

func (m SSHSignersLoggerAlgorithmSigner) SignWithAlgorithm(rand io.Reader, data []byte, algorithm string) (*ssh.Signature, error)

type SSHTunnel

type SSHTunnel struct {
	Server Endpoint
	Config *ssh.ClientConfig
	// contains filtered or unexported fields
}

func NewSSHTunnel

func NewSSHTunnel(host string, credentials credentials.Credentials, opts ...SSHTunnelOption) *SSHTunnel

func (*SSHTunnel) Close

func (m *SSHTunnel) Close()

func (*SSHTunnel) CreateConnect

func (m *SSHTunnel) CreateConnect(ctx context.Context) error

func (*SSHTunnel) IsConnected

func (m *SSHTunnel) IsConnected() bool

func (*SSHTunnel) StartForward

func (m *SSHTunnel) StartForward(network Network, remoteAddr string) (net.Conn, error)

type SSHTunnelOption

type SSHTunnelOption func(m *SSHTunnel)

func SSHTunnelWitPort added in v1.0.20

func SSHTunnelWitPort(port int) SSHTunnelOption

func SSHTunnelWithLogger

func SSHTunnelWithLogger(log *zap.Logger) SSHTunnelOption

func SSHTunnelWithNetwork added in v1.0.20

func SSHTunnelWithNetwork(network Network) SSHTunnelOption

type Streamer

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

func NewNetconfStreamer

func NewNetconfStreamer(host string, credentials credentials.Credentials, opts ...StreamerOption) *Streamer

func NewStreamer

func NewStreamer(host string, credentials credentials.Credentials, opts ...StreamerOption) *Streamer

func (*Streamer) Close

func (m *Streamer) Close()

func (*Streamer) Cmd

func (m *Streamer) Cmd(ctx context.Context, cmd string) (gcmd.CmdRes, error)

func (*Streamer) Download

func (m *Streamer) Download(filePaths []string, recurse bool) (map[string]streamer.File, error)

func (*Streamer) EnableSFTP

func (m *Streamer) EnableSFTP()

func (*Streamer) GetConfig

func (m *Streamer) GetConfig(ctx context.Context) (*ssh.ClientConfig, error)

func (*Streamer) GetCredentials

func (m *Streamer) GetCredentials() credentials.Credentials

func (*Streamer) HasFeature

func (m *Streamer) HasFeature(feature streamer.Const) bool

func (*Streamer) Init

func (m *Streamer) Init(ctx context.Context) error

func (*Streamer) InitAgentForward

func (m *Streamer) InitAgentForward() error

func (*Streamer) Read

func (m *Streamer) Read(ctx context.Context, size int) ([]byte, error)

func (*Streamer) ReadTo

func (m *Streamer) ReadTo(ctx context.Context, expr expr.Expr) (streamer.ReadRes, error)

func (*Streamer) SFTPSudoTry added in v1.0.6

func (m *Streamer) SFTPSudoTry()

func (*Streamer) SetCredentialsInterceptor

func (m *Streamer) SetCredentialsInterceptor(inter func(credentials.Credentials) credentials.Credentials)

func (*Streamer) SetReadTimeout

func (m *Streamer) SetReadTimeout(timeout time.Duration) time.Duration

func (*Streamer) SetTerminalSize added in v1.0.11

func (m *Streamer) SetTerminalSize(w, h int)

func (*Streamer) SetTrace

func (m *Streamer) SetTrace(cb trace.CB)

func (*Streamer) Upload

func (m *Streamer) Upload(filePaths map[string]streamer.File) error

func (*Streamer) WithCloseSessionCallback

func (m *Streamer) WithCloseSessionCallback(fn func(*ssh.Session) error)

func (*Streamer) WithOpenSessionCallback

func (m *Streamer) WithOpenSessionCallback(fn func(*ssh.Session) error)

func (*Streamer) Write

func (m *Streamer) Write(text []byte) error

type StreamerOption

type StreamerOption func(*Streamer)

func WithAdditionalEndpoints added in v1.0.19

func WithAdditionalEndpoints(endpoints []Endpoint) StreamerOption

WithAdditionalEndpoints adds slice of endpoints that Streamer will sequentially try to connect to untill success of dial, if original host dial fails

func WithEnv

func WithEnv(key, value string) StreamerOption

func WithKnownHostsFiles

func WithKnownHostsFiles(files ...string) (StreamerOption, error)

func WithLogger

func WithLogger(log *zap.Logger) StreamerOption

func WithNetwork added in v1.0.19

func WithNetwork(network Network) StreamerOption

WithNetwork sets network for default endpoint

func WithPort

func WithPort(port int) StreamerOption

WithPort sets port for default endpoint

func WithProgram

func WithProgram(program, programData string) StreamerOption

func WithSSHNetconf

func WithSSHNetconf() StreamerOption

func WithSSHTunnel

func WithSSHTunnel(tunnel Tunnel) StreamerOption

WithSSHTunnel sets tunnel as ssh proxy. We do not close after usage because it can be shared with other connections.

func WithTrace

func WithTrace(trace trace.CB) StreamerOption

type Tunnel

type Tunnel interface {
	Close()
	IsConnected() bool
	CreateConnect(context.Context) error
	StartForward(network Network, addr string) (net.Conn, error)
}

Jump to

Keyboard shortcuts

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