Documentation
¶
Index ¶
- type Executor
- type LocalExecutor
- func (e *LocalExecutor) Close() error
- func (e *LocalExecutor) CreateScript(script, path string) error
- func (e *LocalExecutor) CreateSession() (Session, error)
- func (e *LocalExecutor) CreateTunnel(localPort, remotePort int) (TunnelCloser, error)
- func (e *LocalExecutor) Execute(command string) (string, error)
- func (e *LocalExecutor) IsRemote() bool
- func (e *LocalExecutor) UploadFile(localPath, destPath string) error
- type LocalSession
- type RemoteExecutor
- func (e *RemoteExecutor) Close() error
- func (e *RemoteExecutor) CreateScript(script, path string) error
- func (e *RemoteExecutor) CreateSession() (Session, error)
- func (e *RemoteExecutor) CreateTunnel(localPort, remotePort int) (TunnelCloser, error)
- func (e *RemoteExecutor) Execute(command string) (string, error)
- func (e *RemoteExecutor) GetSSHClient() *SSHClient
- func (e *RemoteExecutor) IsRemote() bool
- func (e *RemoteExecutor) UploadFile(localPath, remotePath string) error
- type RemoteSession
- type SSHClient
- func (c *SSHClient) Close() error
- func (c *SSHClient) CreateScript(script, path string) error
- func (c *SSHClient) CreateSession() (*ssh.Session, error)
- func (c *SSHClient) CreateTunnel(localPort, remotePort int) (*Tunnel, error)
- func (c *SSHClient) Execute(command string) (string, error)
- func (c *SSHClient) UploadFile(localPath, remotePath string) error
- type Session
- type SudoWrapper
- type Tunnel
- type TunnelCloser
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Executor ¶
type Executor interface {
// Execute 執行 shell 指令
Execute(command string) (string, error)
// CreateSession 建立一個流式執行 session
CreateSession() (Session, error)
// UploadFile 上傳/複製檔案
UploadFile(localPath, remotePath string) error
// CreateScript 建立腳本檔案
CreateScript(script, path string) error
// CreateTunnel 建立 SSH tunnel (僅遠端模式)
CreateTunnel(localPort, remotePort int) (TunnelCloser, error)
// Close 關閉連接
Close() error
// IsRemote 判斷是否為遠端模式
IsRemote() bool
}
Executor 定義了執行操作的抽象接口
func NewExecutor ¶
func NewExecutor(rc *config.RuntimeConfig) (Executor, error)
NewExecutor 根據配置建立對應的 Executor
type LocalExecutor ¶
type LocalExecutor struct {
// contains filtered or unexported fields
}
LocalExecutor 本地執行器
func NewLocalExecutor ¶
func NewLocalExecutor(rc *config.RuntimeConfig) (*LocalExecutor, error)
NewLocalExecutor 創建本地執行器
func (*LocalExecutor) Close ¶
func (e *LocalExecutor) Close() error
func (*LocalExecutor) CreateScript ¶
func (e *LocalExecutor) CreateScript(script, path string) error
func (*LocalExecutor) CreateSession ¶
func (e *LocalExecutor) CreateSession() (Session, error)
func (*LocalExecutor) CreateTunnel ¶
func (e *LocalExecutor) CreateTunnel(localPort, remotePort int) (TunnelCloser, error)
func (*LocalExecutor) IsRemote ¶
func (e *LocalExecutor) IsRemote() bool
func (*LocalExecutor) UploadFile ¶
func (e *LocalExecutor) UploadFile(localPath, destPath string) error
type LocalSession ¶
type LocalSession struct {
// contains filtered or unexported fields
}
LocalSession 本地命令執行 session
func (*LocalSession) Close ¶
func (s *LocalSession) Close() error
func (*LocalSession) Start ¶
func (s *LocalSession) Start(command string) error
func (*LocalSession) StdoutPipe ¶
func (s *LocalSession) StdoutPipe() (io.Reader, error)
func (*LocalSession) Wait ¶
func (s *LocalSession) Wait() error
type RemoteExecutor ¶
type RemoteExecutor struct {
// contains filtered or unexported fields
}
RemoteExecutor 遠端執行器
func NewRemoteExecutor ¶
func NewRemoteExecutor(rc *config.RuntimeConfig) (*RemoteExecutor, error)
NewRemoteExecutor 創建遠端執行器
func (*RemoteExecutor) Close ¶
func (e *RemoteExecutor) Close() error
func (*RemoteExecutor) CreateScript ¶
func (e *RemoteExecutor) CreateScript(script, path string) error
func (*RemoteExecutor) CreateSession ¶
func (e *RemoteExecutor) CreateSession() (Session, error)
func (*RemoteExecutor) CreateTunnel ¶
func (e *RemoteExecutor) CreateTunnel(localPort, remotePort int) (TunnelCloser, error)
func (*RemoteExecutor) GetSSHClient ¶
func (e *RemoteExecutor) GetSSHClient() *SSHClient
GetSSHClient 返回底層的 SSH client (僅用於需要直接訪問的場景)
func (*RemoteExecutor) IsRemote ¶
func (e *RemoteExecutor) IsRemote() bool
func (*RemoteExecutor) UploadFile ¶
func (e *RemoteExecutor) UploadFile(localPath, remotePath string) error
type RemoteSession ¶
type RemoteSession struct {
// contains filtered or unexported fields
}
RemoteSession SSH 遠端執行 session
func (*RemoteSession) Close ¶
func (s *RemoteSession) Close() error
func (*RemoteSession) Start ¶
func (s *RemoteSession) Start(command string) error
func (*RemoteSession) StdoutPipe ¶
func (s *RemoteSession) StdoutPipe() (io.Reader, error)
func (*RemoteSession) Wait ¶
func (s *RemoteSession) Wait() error
type SSHClient ¶ added in v0.0.14
type SSHClient struct {
// contains filtered or unexported fields
}
func NewSSHClient ¶ added in v0.0.14
func NewSSHClient(cfg config.RemoteHost) (*SSHClient, error)
func (*SSHClient) CreateScript ¶ added in v0.0.14
func (*SSHClient) CreateSession ¶ added in v0.0.14
func (*SSHClient) CreateTunnel ¶ added in v0.0.14
func (*SSHClient) UploadFile ¶ added in v0.0.14
type Session ¶
type Session interface {
// StdoutPipe 返回標準輸出管道
StdoutPipe() (io.Reader, error)
// Start 啟動命令
Start(command string) error
// Wait 等待命令完成
Wait() error
// Close 關閉 session
Close() error
}
Session 定義了流式命令執行的統一接口
type SudoWrapper ¶ added in v0.0.14
type SudoWrapper struct {
// contains filtered or unexported fields
}
SudoWrapper 提供通用的 sudo 命令包装功能 支持临时提权 bash 执行命令,提高命令兼容性
func NewSudoWrapper ¶ added in v0.0.14
func NewSudoWrapper(enabled bool, password string) *SudoWrapper
NewSudoWrapper 创建 sudo 包装器
func (*SudoWrapper) Enabled ¶ added in v0.0.14
func (w *SudoWrapper) Enabled() bool
Enabled 返回是否启用 sudo
func (*SudoWrapper) HasPassword ¶ added in v0.0.14
func (w *SudoWrapper) HasPassword() bool
HasPassword 返回是否配置了密码
func (*SudoWrapper) Wrap ¶ added in v0.0.14
func (w *SudoWrapper) Wrap(command string) string
Wrap 将命令包装为带 sudo 的形式 使用临时提权 bash 来运行命令,提高兼容性
func (*SudoWrapper) WrapMultiple ¶ added in v0.0.14
func (w *SudoWrapper) WrapMultiple(parts ...string) string
WrapMultiple 包装多个命令参数组成的命令 例如: WrapMultiple("docker", "ps", "-a") -> sudo bash -c 'docker ps -a'
Click to show internal directories.
Click to hide internal directories.