feat: implement more Deployer

This commit is contained in:
Fu Diwei
2024-11-20 21:02:29 +08:00
parent a59184ae5f
commit 643a666853
23 changed files with 1778 additions and 17 deletions

View File

@@ -18,10 +18,10 @@ import (
type SshDeployerConfig struct {
// SSH 主机。
// 值时默认为 "localhost"。
// 值时默认为 "localhost"。
SshHost string `json:"sshHost,omitempty"`
// SSH 端口。
// 值时默认为 22。
// 值时默认为 22。
SshPort int32 `json:"sshPort,omitempty"`
// SSH 登录用户名。
SshUsername string `json:"sshUsername,omitempty"`
@@ -36,7 +36,6 @@ type SshDeployerConfig struct {
// 后置命令。
PostCommand string `json:"postCommand,omitempty"`
// 输出证书格式。
// 空值时默认为 [OUTPUT_FORMAT_PEM]。
OutputFormat OutputFormatType `json:"outputFormat,omitempty"`
// 输出证书文件路径。
OutputCertPath string `json:"outputCertPath,omitempty"`
@@ -61,6 +60,8 @@ type SshDeployer struct {
logger deployer.Logger
}
var _ deployer.Deployer = (*SshDeployer)(nil)
func New(config *SshDeployerConfig) (*SshDeployer, error) {
return NewWithLogger(config, deployer.NewNilLogger())
}
@@ -109,7 +110,7 @@ func (d *SshDeployer) Deploy(ctx context.Context, certPem string, privkeyPem str
// 上传证书和私钥文件
switch d.config.OutputFormat {
case "", OUTPUT_FORMAT_PEM:
case OUTPUT_FORMAT_PEM:
if err := writeSftpFileString(client, d.config.OutputCertPath, certPem); err != nil {
return nil, xerrors.Wrap(err, "failed to upload certificate file")
}

View File

@@ -8,7 +8,7 @@ import (
"strings"
"testing"
dSsh "github.com/usual2970/certimate/internal/pkg/core/deployer/providers/ssh"
dpSsh "github.com/usual2970/certimate/internal/pkg/core/deployer/providers/ssh"
)
var (
@@ -64,7 +64,7 @@ func Test(t *testing.T) {
fmt.Sprintf("OUTPUTKEYPATH: %v", fOutputKeyPath),
}, "\n"))
deployer, err := dSsh.New(&dSsh.SshDeployerConfig{
deployer, err := dpSsh.New(&dpSsh.SshDeployerConfig{
SshHost: fSshHost,
SshPort: int32(fSshPort),
SshUsername: fSshUsername,