ssh

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2026 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AuthMethodPrivateKey = "privateKey"
	AuthMethodDefault    = AuthMethodPrivateKey
)
View Source
const (
	HostKeyMethodKnownHostsFile = "knownHostsFile"
	HostKeyMethodDefault        = HostKeyMethodKnownHostsFile
)
View Source
const (
	TypeName = "ssh"
)

Variables

This section is empty.

Functions

func GetLinuxInfo

func GetLinuxInfo(c SshClient) (*platform.SystemInfo, error)

func GetOsInfo

func GetOsInfo(c SshClient) (_ string, err error)

func GetWindowsInfo

func GetWindowsInfo(c SshClient) (*platform.SystemInfo, error)

func NewRemoteSession

func NewRemoteSession(c transport.Transport, fs file.FileSystem) *remoteSession

Types

type Address

type Address struct {
	Host string `json:"host" yaml:"host"`
	Port int    `json:"port" yaml:"port"`
	User string `json:"user" yaml:"user"`
}

func (*Address) Clone

func (a *Address) Clone() *Address

func (*Address) Merge

func (a *Address) Merge(other *Address) *Address

func (*Address) SetDefaults

func (a *Address) SetDefaults()

type Auth

type Auth struct {
	Method         string         `json:"method,omitempty" yaml:"method,omitempty"` // privateKey
	PrivateKeyPath string         `json:"privateKeyPath,omitempty" yaml:"privateKeyPath,omitempty"`
	Passphrase     *PassphraseRef `json:"passphraseRef,omitempty" yaml:"passphraseRef,omitempty"`
}

func (*Auth) Clone

func (a *Auth) Clone() *Auth

func (*Auth) CreateSigner

func (a *Auth) CreateSigner(fs file.Opener) (ssh.Signer, error)

func (*Auth) Merge

func (a *Auth) Merge(other *Auth) *Auth

func (*Auth) SetDefaults

func (a *Auth) SetDefaults()

type HostKey

type HostKey struct {
	Method         string `json:"method,omitempty" yaml:"method,omitempty"` // knownHostsFile
	KnownHostsPath string `json:"knownHostsPath,omitempty" yaml:"knownHostsPath,omitempty"`
}

func (*HostKey) Add

func (hk *HostKey) Add(path []string, value any) error

func (*HostKey) Clone

func (hk *HostKey) Clone() *HostKey

func (*HostKey) Merge

func (hk *HostKey) Merge(other *HostKey) *HostKey

func (*HostKey) Remove

func (hk *HostKey) Remove(path []string) error

func (*HostKey) SetDefaults

func (hk *HostKey) SetDefaults()

func (*HostKey) Update

func (hk *HostKey) Update(o patch.Patchable) error

type KnownHosts

type KnownHosts struct {
	Entries []string
	FS      file.FileSystem
}

func NewKnownHosts

func NewKnownHosts(fs file.FileSystem) *KnownHosts

func NewKnownHostsFromFile

func NewKnownHostsFromFile(fs file.FileSystem, path string) (*KnownHosts, error)

func (*KnownHosts) CopyHostEntry

func (k *KnownHosts) CopyHostEntry(c *Transport) error

func (*KnownHosts) LoadHostEntries

func (k *KnownHosts) LoadHostEntries(knownHostsPath string) error

func (*KnownHosts) RemoveHostEntry

func (k *KnownHosts) RemoveHostEntry(t *Transport) error

func (*KnownHosts) SaveToFile

func (k *KnownHosts) SaveToFile(path string, createSafeDir bool) (err error)

type KnownHostsUpdater

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

func NewKnownHostsUpdater

func NewKnownHostsUpdater(operation string, fs file.FileSystem) *KnownHostsUpdater

func (*KnownHostsUpdater) Update

type OpDownload

type OpDownload struct {
	Type   string       `yaml:"type"`
	Local  string       `yaml:"local"`
	Remote string       `yaml:"remote"`
	Perm   *os.FileMode `yaml:"perm,omitempty"`
}

type OpDownloadDir

type OpDownloadDir struct {
	Type      string `yaml:"type"`
	Local     string `yaml:"local"`
	Remote    string `yaml:"remote"`
	Recursive bool   `yaml:"recursive"`
}

type OpExecute

type OpExecute struct {
	Type       string            `yaml:"type"`
	Id         string            `yaml:"id"`
	LocalRoot  string            `yaml:"local_root"`
	RemoteRoot string            `yaml:"remote_root"`
	Cmd        []string          `yaml:"cmd"`
	Workdir    string            `yaml:"workdir"`
	Envs       map[string]string `yaml:"env"`
}

type OpGetWorkRoot

type OpGetWorkRoot struct {
	Type string `yaml:"type"`
}

type OpMkdirAll

type OpMkdirAll struct {
	Type string `yaml:"type"`
	Path string `yaml:"path"`
}

type OpUpload

type OpUpload struct {
	Type   string `yaml:"type"`
	Local  string `yaml:"local"`
	Remote string `yaml:"remote"`
}

type Options

type Options struct {
	ConnectTimeoutSec   int `json:"connectTimeoutSec,omitempty" yaml:"connectTimeoutSec,omitempty"`
	HandshakeTimeoutSec int `json:"handshakeTimeoutSec,omitempty" yaml:"handshakeTimeoutSec,omitempty"`
	RetryMaxCount       int `json:"retryMaxCount,omitempty" yaml:"retryMaxCount,omitempty"`
	RetryIntervalSec    int `json:"retryIntervalSec,omitempty" yaml:"retryIntervalSec,omitempty"`
}

func (*Options) Clone

func (o *Options) Clone() *Options

func (*Options) ConnectTimeout

func (o *Options) ConnectTimeout() time.Duration

func (*Options) HandshakeTimeout

func (o *Options) HandshakeTimeout() time.Duration

func (*Options) Merge

func (o *Options) Merge(other *Options) *Options

func (*Options) RetryInterval

func (o *Options) RetryInterval() time.Duration

func (*Options) RetryMax

func (o *Options) RetryMax() int

func (*Options) SetDefaults

func (o *Options) SetDefaults()

type PassphraseRef

type PassphraseRef struct {
	FromEnv  string `json:"fromEnv,omitempty" yaml:"fromEnv,omitempty"`
	FromFile string `json:"fromFile,omitempty" yaml:"fromFile,omitempty"`
}

func (*PassphraseRef) Clone

func (r *PassphraseRef) Clone() *PassphraseRef

func (*PassphraseRef) GetPassphrase

func (p *PassphraseRef) GetPassphrase(fs file.Opener) (string, error)

func (*PassphraseRef) Merge

func (r *PassphraseRef) Merge(other *PassphraseRef) *PassphraseRef

type Prober

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

func NewProber

func NewProber(t *Transport, fs file.FileSystem) *Prober

func (*Prober) GetSystemInfo

func (p *Prober) GetSystemInfo(ctx context.Context) (_ *platform.SystemInfo, err error)

type SftpClient

type SftpClient interface {
	MkdirAll(path string) error
	Create(path string) (io.WriteCloser, error)
	Open(path string) (io.ReadCloser, error)
	Chmod(path string, perm os.FileMode) error
	Walk(root string) Walker
	Stat(path string) (os.FileInfo, error)

	Close() error
}

func NewSftpClient

func NewSftpClient(client *ssh.Client) (SftpClient, error)

type SimProber

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

func NewSimProber

func NewSimProber(mode string) *SimProber

func (*SimProber) GetSystemInfo

func (p *SimProber) GetSystemInfo(_ context.Context) (*platform.SystemInfo, error)

type SimRemoteSession

type SimRemoteSession struct {
	Operations []any `yaml:"operations"`
}

func NewSimRemoteSession

func NewSimRemoteSession(mode string) *SimRemoteSession

func (*SimRemoteSession) Close

func (s *SimRemoteSession) Close() error

func (*SimRemoteSession) Download

func (s *SimRemoteSession) Download(ctx context.Context, remote, local string, perm *os.FileMode) error

func (*SimRemoteSession) DownloadDir

func (s *SimRemoteSession) DownloadDir(ctx context.Context, remote, local string, recursive bool) error

func (*SimRemoteSession) Execute

func (*SimRemoteSession) GetWorkRoot

func (s *SimRemoteSession) GetWorkRoot(ctx context.Context) (string, error)

func (*SimRemoteSession) MkdirAll

func (s *SimRemoteSession) MkdirAll(ctx context.Context, path string) error

func (*SimRemoteSession) Upload

func (s *SimRemoteSession) Upload(ctx context.Context, local, remote string, perm *os.FileMode) error

type SshClient

type SshClient interface {
	transport.Client
	NewSession() (SshSession, error)
	NewSftpClient() (SftpClient, error)
}

func NewSshClient

func NewSshClient(ctx context.Context, c *Transport, fs file.FileSystem) (SshClient, error)

type SshOperator

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

func (*SshOperator) IsDryRun

func (o *SshOperator) IsDryRun() bool

func (*SshOperator) NewProber

func (o *SshOperator) NewProber(t transport.Transport) (transport.Prober, error)

func (*SshOperator) NewRemoteSession

func (o *SshOperator) NewRemoteSession(ctx context.Context, t transport.Transport) (transport.RemoteSession, error)

func (*SshOperator) NewUpdater

func (o *SshOperator) NewUpdater(operation string) (transport.Updater, error)

func (*SshOperator) WithDryRunMode

func (o *SshOperator) WithDryRunMode(mode string) transport.Operator

func (*SshOperator) WithFileSystem

func (o *SshOperator) WithFileSystem(fs file.FileSystem) transport.Operator

type SshSession

type SshSession interface {
	Output(cmd string) ([]byte, error)
	Run(cmd string) error
	Close() error
	SetStdout(stdout io.Writer)
	SetStderr(stderr io.Writer)
	SetStdin(stdin io.Reader)
	Shell() error
}

type Transport

type Transport struct {
	Address *Address `json:"address,omitempty" yaml:"address,omitempty"`
	Auth    *Auth    `json:"auth,omitempty" yaml:"auth,omitempty"`
	HostKey *HostKey `json:"hostKey,omitempty" yaml:"hostKey,omitempty"`
	Options *Options `json:"-" yaml:"-"`
}

func (*Transport) Add

func (t *Transport) Add(path []string, value any) error

func (*Transport) Clone

func (t *Transport) Clone() transport.Transport

func (*Transport) GetType

func (t *Transport) GetType() string

func (*Transport) Merge

func (*Transport) Remove

func (t *Transport) Remove(path []string) error

func (*Transport) Resolve

func (t *Transport) Resolve(render func(string) (string, error)) error

func (*Transport) SetDefaults

func (t *Transport) SetDefaults()

func (*Transport) Update

func (t *Transport) Update(o patch.Patchable) error

func (*Transport) Validate

func (t *Transport) Validate() error

type Walker

type Walker interface {
	Err() error
	Path() string
	SkipDir()
	Stat() os.FileInfo
	Step() bool
}

Jump to

Keyboard shortcuts

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