修复服务器 SSH 公钥自动部署

为服务器密钥流程增加仅 Shell 的 SSH 连接,避免远端 SFTP 子系统影响公钥部署和私钥登录验证,并记录脱敏阶段错误。
This commit is contained in:
xuans committed 2026-09-27 16:01:21 +08:00
1 parent 9593fb4e2e
commit cd85d929ad
3 files changed
+36 -2

No files matched your search

+5
View File
@@ -24,3 +24,8 @@ type Client interface {
type ClientFactory interface {
Connect(ctx context.Context, server Server) (Client, error)
}
// ShellClientFactory 为只需要 SSH Shell 的操作提供连接入口,避免无关的 SFTP 子系统阻塞密钥部署。
type ShellClientFactory interface {
ConnectShell(ctx context.Context, server Server) (Client, error)
}
+11
View File
@@ -28,6 +28,14 @@ type SSHFactory struct {
}
func (f SSHFactory) Connect(ctx context.Context, server Server) (Client, error) {
return f.connect(ctx, server, true)
}
func (f SSHFactory) ConnectShell(ctx context.Context, server Server) (Client, error) {
return f.connect(ctx, server, false)
}
func (f SSHFactory) connect(ctx context.Context, server Server, requireSFTP bool) (Client, error) {
server = server.Normalize()
if err := server.Validate(); err != nil {
return nil, err
@@ -82,6 +90,9 @@ func (f SSHFactory) Connect(ctx context.Context, server Server) (Client, error)
return nil, err
}
adapter := &sshClientAdapter{ssh: sshClient}
if !requireSFTP {
return adapter, nil
}
sftpClient, err := sshOperation(timeoutContext, adapter, func() (*sftp.Client, error) {
return sftp.NewClient(sshClient)
})