transport

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: MIT Imports: 13 Imported by: 9

Documentation

Index

Constants

View Source
const (
	// DefaultTransport is the default transport constant for scrapligo, this defaults to the
	// "system" transport.
	DefaultTransport = "system"
)
View Source
const (
	// FileTransport transport name.
	FileTransport = "file"
)
View Source
const (
	// StandardTransport is the standard (crypto/ssh) transport for scrapligo.
	StandardTransport = "standard"
)
View Source
const (
	// SystemTransport is the default "system" (/bin/ssh wrapper) transport for scrapligo.
	SystemTransport = "system"
)
View Source
const (
	// TelnetTransport is the telnet transport for scrapligo.
	TelnetTransport = "telnet"
)

Variables

This section is empty.

Functions

func GetNetconfTransportNames added in v1.0.0

func GetNetconfTransportNames() []string

GetNetconfTransportNames returns a slice of available NETCONF transport type names.

func GetTransportNames added in v1.0.0

func GetTransportNames() []string

GetTransportNames is returns a slice of available transport type names.

Types

type Args added in v1.0.0

type Args struct {
	UserImplementation Implementation
	Host               string
	Port               int
	User               string
	Password           string
	TimeoutSocket      time.Duration
	ReadSize           int
	TermHeight         int
	TermWidth          int
	// contains filtered or unexported fields
}

Args is a struct representing common transport arguments.

func NewArgs added in v1.0.0

func NewArgs(l *logging.Instance, host string, options ...util.Option) (*Args, error)

NewArgs returns an instance of Args with the logging instance, host, and any provided args set. Users should *generally* not need to call this function as this is called during Transport creation (which is called by the Driver creation).

type File added in v1.0.0

type File struct {
	F string

	Writes [][]byte
	// contains filtered or unexported fields
}

File transport is a transport object that "connects" to a file rather than a device, it probably has no use outside of testing.

func NewFileTransport added in v1.0.0

func NewFileTransport() (*File, error)

NewFileTransport returns an instance of File transport. This is for testing purposes only.

func (*File) Close added in v1.0.0

func (t *File) Close() error

Close is a noop for the File transport.

func (*File) IsAlive added in v1.0.0

func (t *File) IsAlive() bool

IsAlive always returns true for File transport.

func (*File) Open added in v1.0.0

func (t *File) Open(a *Args) error

Open opens the File transport.

func (*File) Read added in v1.0.0

func (t *File) Read(_ int) ([]byte, error)

Read reads n bytes from the transport. File transport ignores EOF errors, see comment below.

func (*File) Write added in v1.0.0

func (t *File) Write(b []byte) error

Write writes bytes b to the transport.

type Implementation

type Implementation interface {
	Open(a *Args) error
	Close() error
	IsAlive() bool
	Read(n int) ([]byte, error)
	Write(b []byte) error
}

Implementation defines a valid base scrapligo transport -- for SSH-specific transports users should satisfy SSHImplementation -- and for transports that require authentication "in channel" users should satisfy InChannelAuthImplementation (this could be in addition to the SSH one!).

type InChannelAuthData added in v1.0.3

type InChannelAuthData struct {
	Type                 InChannelAuthType
	User                 string
	Password             string
	PrivateKeyPassPhrase string
}

InChannelAuthData is a struct containing all necessary information for the Channel to handle "in-channel" auth if necessary.

type InChannelAuthImplementation added in v1.3.0

type InChannelAuthImplementation interface {
	Implementation
	GetInChannelAuthType() InChannelAuthType
}

InChannelAuthImplementation is an interface that when satisfied tells us that the transport wants to do "in channel" authentication -- meaning actually look for user/password prompt and send those values in the connection rather than in the protocol/out of band.

type InChannelAuthType added in v1.3.0

type InChannelAuthType string

InChannelAuthType is an enum-ish string that represents valid in channel auth flavors.

const (
	// InChannelAuthUnsupported indicates that the transport does *not* support in channel auth.
	InChannelAuthUnsupported InChannelAuthType = "unsupported"
	// InChannelAuthSSH indicates that the transport supports in channel ssh auth.
	InChannelAuthSSH InChannelAuthType = "ssh"
	// InChannelAuthTelnet indicates that the transport supports in channel telnet auth.
	InChannelAuthTelnet InChannelAuthType = "telnet"
)

type SSHArgs added in v1.0.0

type SSHArgs struct {
	StrictKey            bool
	PrivateKeyPath       string
	PrivateKeyPassPhrase string
	ConfigFile           string
	KnownHostsFile       string
	NetconfConnection    bool
}

SSHArgs is a struct representing common transport SSH specific arguments.

func NewSSHArgs added in v1.0.0

func NewSSHArgs(options ...util.Option) (*SSHArgs, error)

NewSSHArgs returns an instance of SSH arguments with provided options set. Just like NewArgs, this should generally not be called by users directly.

type SSHImplementation added in v1.3.0

type SSHImplementation interface {
	Implementation
	GetSSHArgs() *SSHArgs
}

SSHImplementation is an interface that SSH transports *may* implement, this is currently only required if the SSH transport also requires (or just supports) "in-channel" ssh authentication.

type Standard

type Standard struct {
	SSHArgs *SSHArgs

	ExtraCiphers []string
	ExtraKexs    []string
	// contains filtered or unexported fields
}

Standard is the standard (crypto/ssh) transport object.

func NewStandardTransport added in v1.0.0

func NewStandardTransport(s *SSHArgs) (*Standard, error)

NewStandardTransport returns an instance of Standard transport.

func (*Standard) Close

func (t *Standard) Close() error

Close closes the Standard transport.

func (*Standard) IsAlive

func (t *Standard) IsAlive() bool

IsAlive returns true if the Standard transport session attribute is not nil.

func (*Standard) Open

func (t *Standard) Open(a *Args) error

Open opens the Standard transport.

func (*Standard) Read

func (t *Standard) Read(n int) ([]byte, error)

Read reads n bytes from the transport.

func (*Standard) Write

func (t *Standard) Write(b []byte) error

Write writes bytes b to the transport.

type System

type System struct {
	SSHArgs   *SSHArgs
	ExtraArgs []string
	OpenBin   string
	OpenArgs  []string
	// contains filtered or unexported fields
}

System is the default (/bin/ssh wrapper) transport object.

func NewSystemTransport added in v1.0.0

func NewSystemTransport(a *SSHArgs) (*System, error)

NewSystemTransport returns an instance of System transport.

func (*System) Close

func (t *System) Close() error

Close closes the System transport.

func (*System) GetInChannelAuthType added in v1.3.0

func (t *System) GetInChannelAuthType() InChannelAuthType

GetInChannelAuthType returns the in channel auth flavor for the system transport.

func (*System) GetSSHArgs added in v1.3.0

func (t *System) GetSSHArgs() *SSHArgs

GetSSHArgs returns the ssh args for the system transport.

func (*System) IsAlive

func (t *System) IsAlive() bool

IsAlive returns true if the System transport file descriptor is not nil.

func (*System) Open

func (t *System) Open(a *Args) error

Open opens the System transport.

func (*System) Read

func (t *System) Read(n int) ([]byte, error)

Read reads n bytes from the transport.

func (*System) Write

func (t *System) Write(b []byte) error

Write writes bytes b to the transport.

type Telnet

type Telnet struct {
	TelnetArgs *TelnetArgs
	// contains filtered or unexported fields
}

Telnet is the telnet transport object.

func NewTelnetTransport added in v1.0.0

func NewTelnetTransport(a *TelnetArgs) (*Telnet, error)

NewTelnetTransport returns an instance of Telnet transport.

func (*Telnet) Close

func (t *Telnet) Close() error

Close closes the Telnet connection.

func (*Telnet) GetInChannelAuthType added in v1.3.0

func (t *Telnet) GetInChannelAuthType() InChannelAuthType

GetInChannelAuthType returns the in channel auth flavor for the telnet transport.

func (*Telnet) IsAlive

func (t *Telnet) IsAlive() bool

IsAlive returns true if the connection (c) attribute of the Telnet object is not nil.

func (*Telnet) Open

func (t *Telnet) Open(a *Args) error

Open opens the Telnet connection.

func (*Telnet) Read

func (t *Telnet) Read(n int) ([]byte, error)

Read reads n bytes from the transport.

func (*Telnet) Write

func (t *Telnet) Write(b []byte) error

Write writes bytes b to the transport.

type TelnetArgs added in v1.0.0

type TelnetArgs struct{}

TelnetArgs is a struct representing common transport Telnet specific arguments.

func NewTelnetArgs added in v1.0.0

func NewTelnetArgs(options ...util.Option) (*TelnetArgs, error)

NewTelnetArgs returns an instance of TelnetArgs with any provided options set. This should, just like the other NewXArgs functions, not be called directly by users.

type Transport

type Transport struct {
	Args *Args
	Impl Implementation
	// contains filtered or unexported fields
}

Transport is a struct which wraps a transportImpl object and provides a unified interface to any type of transport selected by the user.

func NewTransport added in v1.0.0

func NewTransport(
	l *logging.Instance,
	host, transportType string,
	options ...util.Option,
) (*Transport, error)

NewTransport returns an instance of Transport with the requested transport implementation (as defined in transportType) set. Typically, users should not need to call this as the process of Driver creation will handle this for you.

func (*Transport) Close

func (t *Transport) Close(force bool) error

Close closes the underlying transportImpl transport object. force option is required for netconf as there will almost certainly always be a read in progress that we cannot stop and will block, therefore we need a way to bypass the lock.

func (*Transport) GetHost added in v1.0.0

func (t *Transport) GetHost() string

GetHost is a convenience method to return the Transport Args Host value.

func (*Transport) GetPort added in v1.0.0

func (t *Transport) GetPort() int

GetPort is a convenience method to return the Transport Args Port value.

func (*Transport) InChannelAuthData added in v1.0.3

func (t *Transport) InChannelAuthData() *InChannelAuthData

InChannelAuthData returns an instance of InChannelAuthData indicating if in-channel auth is supported, and if so, the necessary fields to accomplish that.

func (*Transport) IsAlive

func (t *Transport) IsAlive() bool

IsAlive returns true if the underlying transportImpl reports liveness, otherwise false.

func (*Transport) Open

func (t *Transport) Open() error

Open opens the underlying transportImpl transport object.

func (*Transport) Read

func (t *Transport) Read() ([]byte, error)

Read reads the Transport Args ReadSize bytes from the transportImpl.

func (*Transport) ReadN

func (t *Transport) ReadN(n int) ([]byte, error)

ReadN reads n bytes from the transportImpl.

func (*Transport) Write

func (t *Transport) Write(b []byte) error

Write writes bytes b to the transportImpl.

Jump to

Keyboard shortcuts

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