From 2fd57621d86d96014a883b3cc2d135effc4bc798 Mon Sep 17 00:00:00 2001 From: Fu Diwei Date: Mon, 4 Nov 2024 10:40:41 +0800 Subject: [PATCH] fix: #298 --- internal/deployer/local.go | 3 +++ internal/deployer/ssh.go | 21 ++++++++++++--------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/internal/deployer/local.go b/internal/deployer/local.go index eedec98b..7562e2f6 100644 --- a/internal/deployer/local.go +++ b/internal/deployer/local.go @@ -105,6 +105,9 @@ func (d *LocalDeployer) Deploy(ctx context.Context) error { } d.infos = append(d.infos, toStr("保存证书成功", nil)) + + default: + return errors.New("unsupported format") } // 执行命令 diff --git a/internal/deployer/ssh.go b/internal/deployer/ssh.go index a50fcab6..9031c445 100644 --- a/internal/deployer/ssh.go +++ b/internal/deployer/ssh.go @@ -4,6 +4,7 @@ import ( "bytes" "context" "encoding/json" + "errors" "fmt" "os" "path/filepath" @@ -13,7 +14,6 @@ import ( "golang.org/x/crypto/ssh" "github.com/usual2970/certimate/internal/domain" - "github.com/usual2970/certimate/internal/pkg/utils/fs" ) type SSHDeployer struct { @@ -105,11 +105,14 @@ func (d *SSHDeployer) Deploy(ctx context.Context) error { return err } - if err := fs.WriteFile(d.option.DeployConfig.GetConfigAsString("certPath"), jksData); err != nil { + if err := d.writeSftpFile(client, d.option.DeployConfig.GetConfigAsString("certPath"), jksData); err != nil { return err } - d.infos = append(d.infos, toStr("保存证书成功", nil)) + d.infos = append(d.infos, toStr("SSH 上传证书成功", nil)) + + default: + return errors.New("unsupported format") } // 执行命令 @@ -156,8 +159,8 @@ func (d *SSHDeployer) createSshClient(access *domain.SSHAccess) (*ssh.Client, er }) } -func (d *SSHDeployer) sshExecCommand(client *ssh.Client, command string) (string, string, error) { - session, err := client.NewSession() +func (d *SSHDeployer) sshExecCommand(sshCli *ssh.Client, command string) (string, string, error) { + session, err := sshCli.NewSession() if err != nil { return "", "", xerrors.Wrap(err, "failed to create ssh session") } @@ -175,12 +178,12 @@ func (d *SSHDeployer) sshExecCommand(client *ssh.Client, command string) (string return stdoutBuf.String(), stderrBuf.String(), nil } -func (d *SSHDeployer) writeSftpFileString(client *ssh.Client, path string, content string) error { - return d.writeSftpFile(client, path, []byte(content)) +func (d *SSHDeployer) writeSftpFileString(sshCli *ssh.Client, path string, content string) error { + return d.writeSftpFile(sshCli, path, []byte(content)) } -func (d *SSHDeployer) writeSftpFile(client *ssh.Client, path string, data []byte) error { - sftpCli, err := sftp.NewClient(client) +func (d *SSHDeployer) writeSftpFile(sshCli *ssh.Client, path string, data []byte) error { + sftpCli, err := sftp.NewClient() if err != nil { return xerrors.Wrap(err, "failed to create sftp client") }