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

@@ -17,14 +17,13 @@ import (
type LocalDeployerConfig struct {
// Shell 执行环境。
// 值时默认根据操作系统决定。
// 值时默认根据操作系统决定。
ShellEnv ShellEnvType `json:"shellEnv,omitempty"`
// 前置命令。
PreCommand string `json:"preCommand,omitempty"`
// 后置命令。
PostCommand string `json:"postCommand,omitempty"`
// 输出证书格式。
// 空值时默认为 [OUTPUT_FORMAT_PEM]。
OutputFormat OutputFormatType `json:"outputFormat,omitempty"`
// 输出证书文件路径。
OutputCertPath string `json:"outputCertPath,omitempty"`
@@ -49,6 +48,8 @@ type LocalDeployer struct {
logger deployer.Logger
}
var _ deployer.Deployer = (*LocalDeployer)(nil)
func New(config *LocalDeployerConfig) (*LocalDeployer, error) {
return NewWithLogger(config, deployer.NewNilLogger())
}
@@ -81,7 +82,7 @@ func (d *LocalDeployer) Deploy(ctx context.Context, certPem string, privkeyPem s
// 写入证书和私钥文件
switch d.config.OutputFormat {
case "", OUTPUT_FORMAT_PEM:
case OUTPUT_FORMAT_PEM:
if err := fs.WriteFileString(d.config.OutputCertPath, certPem); err != nil {
return nil, xerrors.Wrap(err, "failed to save certificate file")
}

View File

@@ -8,7 +8,7 @@ import (
"strings"
"testing"
dLocal "github.com/usual2970/certimate/internal/pkg/core/deployer/providers/local"
dpLocal "github.com/usual2970/certimate/internal/pkg/core/deployer/providers/local"
)
var (
@@ -60,7 +60,7 @@ func Test(t *testing.T) {
fmt.Sprintf("OUTPUTKEYPATH: %v", fOutputKeyPath),
}, "\n"))
deployer, err := dLocal.New(&dLocal.LocalDeployerConfig{
deployer, err := dpLocal.New(&dpLocal.LocalDeployerConfig{
OutputCertPath: fOutputCertPath,
OutputKeyPath: fOutputKeyPath,
})
@@ -108,8 +108,8 @@ func Test(t *testing.T) {
fmt.Sprintf("PFXPASSWORD: %v", fPfxPassword),
}, "\n"))
deployer, err := dLocal.New(&dLocal.LocalDeployerConfig{
OutputFormat: dLocal.OUTPUT_FORMAT_PFX,
deployer, err := dpLocal.New(&dpLocal.LocalDeployerConfig{
OutputFormat: dpLocal.OUTPUT_FORMAT_PFX,
OutputCertPath: fOutputCertPath,
OutputKeyPath: fOutputKeyPath,
PfxPassword: fPfxPassword,
@@ -151,8 +151,8 @@ func Test(t *testing.T) {
fmt.Sprintf("JKSSTOREPASS: %v", fJksStorepass),
}, "\n"))
deployer, err := dLocal.New(&dLocal.LocalDeployerConfig{
OutputFormat: dLocal.OUTPUT_FORMAT_JKS,
deployer, err := dpLocal.New(&dpLocal.LocalDeployerConfig{
OutputFormat: dpLocal.OUTPUT_FORMAT_JKS,
OutputCertPath: fOutputCertPath,
OutputKeyPath: fOutputKeyPath,
JksAlias: fJksAlias,