kssh

package
v0.0.22 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DebugCount int

Debug count

Functions

This section is empty.

Types

type SSHKind

type SSHKind interface {
	// Start a config transaction
	Start(s *SSHTransport, transaction bool) error
	// Commit a config transaction
	Commit(s *SSHTransport) (*SSHReply, error)
	// Commit a config transaction
	Compare(s *SSHTransport) (*SSHReply, error) // Prompt parsing function
	Discard(s *SSHTransport) (*SSHReply, error) // Prompt parsing function
	//
	// This function receives string, split by the delimiter and should ensure this is a valid prompt
	// Valid prompt, strip the prompt from the result and add it to the prompt in SSHReply
	//
	// A default implementation is promptParseNoSpaces, which simply ensures there are
	// no spaces between the start of the line and the #
	PromptParse(s *SSHTransport, in *string) *SSHReply
}

An interface to implement kind specific methods for transactions and prompt checking each kind should implement this interface

type SSHKindSRL

type SSHKindSRL struct{}

implements SShKind

func (*SSHKindSRL) Commit

func (sk *SSHKindSRL) Commit(s *SSHTransport) (*SSHReply, error)

func (*SSHKindSRL) Compare

func (sk *SSHKindSRL) Compare(s *SSHTransport) (*SSHReply, error)

func (*SSHKindSRL) Discard

func (sk *SSHKindSRL) Discard(s *SSHTransport) (*SSHReply, error)

func (*SSHKindSRL) PromptParse

func (sk *SSHKindSRL) PromptParse(s *SSHTransport, in *string) *SSHReply

func (*SSHKindSRL) Start

func (sk *SSHKindSRL) Start(s *SSHTransport, transaction bool) error

type SSHKindVRSROS

type SSHKindVRSROS struct{}

implements SShKind

func (*SSHKindVRSROS) Commit

func (sk *SSHKindVRSROS) Commit(s *SSHTransport) (*SSHReply, error)

func (*SSHKindVRSROS) Compare

func (sk *SSHKindVRSROS) Compare(s *SSHTransport) (*SSHReply, error)

func (*SSHKindVRSROS) Discard

func (sk *SSHKindVRSROS) Discard(s *SSHTransport) (*SSHReply, error)

func (*SSHKindVRSROS) PromptParse

func (sk *SSHKindVRSROS) PromptParse(s *SSHTransport, in *string) *SSHReply

func (*SSHKindVRSROS) Start

func (sk *SSHKindVRSROS) Start(s *SSHTransport, transaction bool) error

type SSHReply

type SSHReply struct{ Node, Source, Prompt, Command, Response string }

The SSH reply, executed command and the prompt

func (*SSHReply) Debug

func (r *SSHReply) Debug(message string)

func (*SSHReply) Log

func (r *SSHReply) Log(level ...log.Level) *SSHReply

func (*SSHReply) Slog

func (r *SSHReply) Slog() string

The Slog will include the entire SSHReply

Each field will be prefixed by a character.
# - command sent
| - result received
? - prompt part of the result

type SSHSession

type SSHSession struct {
	In      io.Reader
	Out     io.WriteCloser
	Session *ssh.Session
}

func NewSSHSession

func NewSSHSession(host string, sshConfig *ssh.ClientConfig) (*SSHSession, error)

Create a new SSH session (Dial, open in/out pipes and start the shell) pass the authntication details in sshConfig

func (*SSHSession) Close

func (ses *SSHSession) Close() error

func (*SSHSession) Writeln

func (ses *SSHSession) Writeln(command string) (int, error)

type SSHTransport

type SSHTransport struct {

	// Contains the first read after connecting
	LoginMessage *SSHReply
	// SSH parameters used in connect
	// default: 22
	Port int

	// Keep the target for logging
	Target string

	// SSH Options
	// required!
	SSHConfig *ssh.ClientConfig

	// Character to split the incoming stream (#/$/>)
	// default: #
	PromptChar string

	// Kind specific transactions & prompt checking function
	K SSHKind
	// contains filtered or unexported fields
}

SSHTransport setting needs to be set before calling Connect() SSHTransport implements the Transport interface

func NewSSHTransport

func NewSSHTransport(node *types.NodeConfig, options ...SSHTransportOption) (*SSHTransport, error)

func (*SSHTransport) Close

func (t *SSHTransport) Close() error

Close the Session and channels Part of the Transport interface

func (*SSHTransport) Connect

func (t *SSHTransport) Connect(host string) error

Connect to a host Part of the Transport interface

func (*SSHTransport) InChannel

func (t *SSHTransport) InChannel()

Creates the channel reading the SSH connection

The first prompt is saved in LoginMessages

  • The channel read the SSH session, splits on PromptChar
  • Uses SSHKind's PromptParse to split the received data in *result* and *prompt* parts (if no valid prompt was found, prompt will simply be empty and result contain all the data)
  • Emit data

func (*SSHTransport) Run

func (t *SSHTransport) Run(command string, timeout time.Duration) *SSHReply

Run a single command and wait for the reply

func (*SSHTransport) Write

func (t *SSHTransport) Write(data []string) ([]*SSHReply, error)

type SSHTransportOption

type SSHTransportOption func(*SSHTransport) error

func HostKeyCallback

func HostKeyCallback(callback ...ssh.HostKeyCallback) SSHTransportOption

Add a basic username & password to a config Will initialize the config if required

func WithUserNamePassword

func WithUserNamePassword(username, password string) SSHTransportOption

Add username & password authentication

Jump to

Keyboard shortcuts

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