sshutils

package
v0.0.0-...-d73d392 Latest Latest
Warning

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

Go to latest
Published: May 3, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const AUTOMATE_KNOWN_HOSTS = ".automate_known_hosts"

Variables

This section is empty.

Functions

This section is empty.

Types

type ISshClient

type ISshClient interface {
	Dial(network string, addr string, config *ssh.ClientConfig) (*ssh.Client, error)
	NewSession(*ssh.Client) (*ssh.Session, error)
	ParsePrivateKey(pemBytes []byte) (ssh.Signer, error)
	PublicKey(signers ssh.Signer) ssh.AuthMethod
	CombinedOutput(cmd string, session *ssh.Session) ([]byte, error)
	Close(*ssh.Session) error
	Normalize(address string) string
	New(files ...string) (ssh.HostKeyCallback, error)
}

func NewSshClient

func NewSshClient() ISshClient

type MockSSHUtilsImpl

type MockSSHUtilsImpl struct {
	Executefunc                      func(sshConfig SSHConfig, cmd string) (string, error)
	ExecuteConcurrentlyFunc          func(sshConfig SSHConfig, cmd string, hostIPs []string) []Result
	CopyFileToRemoteFunc             func(sshConfig SSHConfig, srcFilePath string, destFileName string, destDir string, removeFile bool) error
	CopyFileToRemoteConcurrentlyFunc func(sshConfig SSHConfig, srcFilePath string, destFileName string, destDir string, removeFile bool, hostIPs []string) []Result
}

func (*MockSSHUtilsImpl) CopyFileToRemote

func (mssh *MockSSHUtilsImpl) CopyFileToRemote(sshConfig SSHConfig, srcFilePath string, destFileName string, destDir string, removeFile bool) error

func (*MockSSHUtilsImpl) CopyFileToRemoteConcurrently

func (mssh *MockSSHUtilsImpl) CopyFileToRemoteConcurrently(sshConfig SSHConfig, srcFilePath string, destFileName string, destDir string, removeFile bool, hostIPs []string) []Result

func (*MockSSHUtilsImpl) Execute

func (mssh *MockSSHUtilsImpl) Execute(sshConfig SSHConfig, cmd string) (string, error)

func (*MockSSHUtilsImpl) ExecuteConcurrently

func (mssh *MockSSHUtilsImpl) ExecuteConcurrently(sshConfig SSHConfig, cmd string, hostIPs []string) []Result

type MockSshClient

type MockSshClient struct {
	Dialfunc            func(network string, addr string, config *ssh.ClientConfig) (*ssh.Client, error)
	NewSessionfunc      func(*ssh.Client) (*ssh.Session, error)
	ParsePrivateKeyfunc func(pemBytes []byte) (ssh.Signer, error)
	PublicKeyfunc       func(signers ssh.Signer) ssh.AuthMethod
	CombinedOutputfunc  func(cmd string, session *ssh.Session) ([]byte, error)
	Closefunc           func(*ssh.Session) error
	Normalizefunc       func(address string) string
	Newfunc             func(files ...string) (ssh.HostKeyCallback, error)
}

func (*MockSshClient) Close

func (mssh *MockSshClient) Close(session *ssh.Session) error

func (*MockSshClient) CombinedOutput

func (mssh *MockSshClient) CombinedOutput(cmd string, session *ssh.Session) ([]byte, error)

func (*MockSshClient) Dial

func (mssh *MockSshClient) Dial(network string, addr string, config *ssh.ClientConfig) (*ssh.Client, error)

func (*MockSshClient) New

func (mssh *MockSshClient) New(files ...string) (ssh.HostKeyCallback, error)

func (*MockSshClient) NewSession

func (mssh *MockSshClient) NewSession(client *ssh.Client) (*ssh.Session, error)

func (*MockSshClient) Normalize

func (mssh *MockSshClient) Normalize(address string) string

func (*MockSshClient) ParsePrivateKey

func (mssh *MockSshClient) ParsePrivateKey(pemBytes []byte) (ssh.Signer, error)

func (*MockSshClient) PublicKey

func (mssh *MockSshClient) PublicKey(signers ssh.Signer) ssh.AuthMethod

type Result

type Result struct {
	HostIP string
	Output string
	Error  error
}

type SSHConfig

type SSHConfig struct {
	SshUser    string
	SshPort    string
	SshKeyFile string
	HostIP     string
	Timeout    int
}

func NewSshConfig

func NewSshConfig(ip string, port string, keyFile string, userName string) SSHConfig

func NewSshConfigWithTimeout

func NewSshConfigWithTimeout(ip string, port string, keyFile string, userName string, timeout int) SSHConfig

type SSHUtil

type SSHUtil interface {
	Execute(sshConfig SSHConfig, cmd string) (string, error)
	ExecuteConcurrently(sshConfig SSHConfig, cmd string, hostIPs []string) []Result
	CopyFileToRemote(sshConfig SSHConfig, srcFilePath string, destFileName string, destDir string, removeFile bool) error
	CopyFileToRemoteConcurrently(sshConfig SSHConfig, srcFilePath string, destFileName string, destDir string, removeFile bool, hostIPs []string) []Result
}

type SSHUtilImpl

type SSHUtilImpl struct {
	SshClient ISshClient

	Exec command.Executor
	// contains filtered or unexported fields
}

func NewSSHUtil

func NewSSHUtil(sshclient ISshClient, logger logger.Logger) *SSHUtilImpl

func NewSSHUtilWithCommandExecutor

func NewSSHUtilWithCommandExecutor(sshclient ISshClient, logger logger.Logger, exec command.Executor) *SSHUtilImpl

func (*SSHUtilImpl) AddHostKey

func (s *SSHUtilImpl) AddHostKey(host, known_hosts_path string, remote net.Addr, pubKey ssh.PublicKey) error

func (*SSHUtilImpl) CheckKnownHosts

func (s *SSHUtilImpl) CheckKnownHosts(knownHostPath string) (ssh.HostKeyCallback, error)

func (*SSHUtilImpl) CopyFileToRemote

func (s *SSHUtilImpl) CopyFileToRemote(sshConfig SSHConfig, srcFilePath string, destFileName string, destDir string, removeFile bool) error

func (*SSHUtilImpl) CopyFileToRemoteConcurrently

func (s *SSHUtilImpl) CopyFileToRemoteConcurrently(sshConfig SSHConfig, srcFilePath string, destFileName string, destDir string, removeFile bool, hostIPs []string) []Result

func (*SSHUtilImpl) CreateKnownHosts

func (s *SSHUtilImpl) CreateKnownHosts(knownHostPath string) error

func (*SSHUtilImpl) Execute

func (s *SSHUtilImpl) Execute(sshConfig SSHConfig, cmd string) (string, error)

func (*SSHUtilImpl) ExecuteConcurrently

func (s *SSHUtilImpl) ExecuteConcurrently(sshConfig SSHConfig, cmd string, hostIPs []string) []Result

func (*SSHUtilImpl) GetClientConfig

func (s *SSHUtilImpl) GetClientConfig(sshConfig SSHConfig) (*ssh.ClientConfig, error)

func (*SSHUtilImpl) GetConnection

func (s *SSHUtilImpl) GetConnection(sshConfig SSHConfig) (*ssh.Client, error)

func (*SSHUtilImpl) HostKeyCallback

func (s *SSHUtilImpl) HostKeyCallback(host string, remote net.Addr, pubkey ssh.PublicKey) error

type SshClient

type SshClient struct{}

func (*SshClient) Close

func (sc *SshClient) Close(session *ssh.Session) error

func (*SshClient) CombinedOutput

func (sc *SshClient) CombinedOutput(cmd string, session *ssh.Session) ([]byte, error)

func (*SshClient) Dial

func (sc *SshClient) Dial(network string, addr string, config *ssh.ClientConfig) (*ssh.Client, error)

func (*SshClient) New

func (sc *SshClient) New(files ...string) (ssh.HostKeyCallback, error)

func (*SshClient) NewSession

func (sc *SshClient) NewSession(conn *ssh.Client) (*ssh.Session, error)

func (*SshClient) Normalize

func (sc *SshClient) Normalize(address string) string

func (*SshClient) ParsePrivateKey

func (sc *SshClient) ParsePrivateKey(pemBytes []byte) (ssh.Signer, error)

func (*SshClient) PublicKey

func (sc *SshClient) PublicKey(signers ssh.Signer) ssh.AuthMethod

Jump to

Keyboard shortcuts

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