connector

package
v0.15.3 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2026 License: MIT Imports: 10 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 func(*ssh.ClientConfig)

AuthMethod is the method to use to authenticate agaist the device

func AuthByKey

func AuthByKey(username string, key io.Reader, keyPassphrase string) (AuthMethod, error)

AuthByKey uses public key authentication

func AuthByPassword

func AuthByPassword(username, password string) AuthMethod

AuthByPassword uses password authentication

type Device

type Device struct {
	Host string
	Auth AuthMethod
}

Device is the basic configuration needed to connect to the device

func (*Device) String

func (d *Device) String() string

type Option

type Option func(*SSHConnectionManager)

Option defines options for the manager which are applied on creation

func WithExpiredConnectionTimeout

func WithExpiredConnectionTimeout(d time.Duration) Option

WithExpiredConnectionTime sets the timeout after an unused ssh connection will not be keepalived

func WithKeepAliveInterval

func WithKeepAliveInterval(d time.Duration) Option

WithKeepAliveInterval sets the keep alive interval (default 10 seconds)

func WithKeepAliveTimeout

func WithKeepAliveTimeout(d time.Duration) Option

WithKeepAliveTimeout sets the timeout after an ssh connection to be determined dead (default 15 seconds)

func WithReconnectInterval

func WithReconnectInterval(d time.Duration) Option

WithReconnectInterval sets the reconnect interval (default 10 seconds)

type SSHConnection

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

SSHConnection encapsulates the connection to the device

func NewSSHConnection

func NewSSHConnection(device *Device, keepAliveInterval time.Duration, keepAliveTimeout time.Duration) *SSHConnection

func (*SSHConnection) Device

func (c *SSHConnection) Device() *Device

Device returns the device information of the connected device

func (*SSHConnection) GetLastUsed

func (c *SSHConnection) GetLastUsed() time.Time

func (*SSHConnection) Host

func (c *SSHConnection) Host() string

Host returns the hostname of the connected device

func (*SSHConnection) IsConnected

func (c *SSHConnection) IsConnected() bool

func (*SSHConnection) RunCommand

func (c *SSHConnection) RunCommand(cmd string) ([]byte, error)

RunCommand runs a command against the device

func (*SSHConnection) Start

func (c *SSHConnection) Start(expiredConnectionTimeout time.Duration) error

func (*SSHConnection) Stop

func (c *SSHConnection) Stop(err error)

type SSHConnectionManager

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

SSHConnectionManager manages SSH connections to different devices

func NewConnectionManager

func NewConnectionManager(opts ...Option) *SSHConnectionManager

NewConnectionManager creates a new connection manager

func (*SSHConnectionManager) CloseAll

func (m *SSHConnectionManager) CloseAll() error

CloseAll closes all TCP connections and stops keep alives

func (*SSHConnectionManager) GetSSHConnection

func (m *SSHConnectionManager) GetSSHConnection(device *Device) (*SSHConnection, error)

GetSSHConnection gets a cached SSHConnection or creates a fresh one, if necessary

Jump to

Keyboard shortcuts

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