diff --git a/internal/deployer/aliyun_cdn.go b/internal/deployer/aliyun_cdn.go index e1a59ba3..c7087c28 100644 --- a/internal/deployer/aliyun_cdn.go +++ b/internal/deployer/aliyun_cdn.go @@ -20,7 +20,7 @@ type AliyunCDNDeployer struct { infos []string } -func NewAliyunCdnDeployer(option *DeployerOption) (*AliyunCDNDeployer, error) { +func NewAliyunCDNDeployer(option *DeployerOption) (*AliyunCDNDeployer, error) { access := &domain.AliyunAccess{} json.Unmarshal([]byte(option.Access), access) diff --git a/internal/deployer/aliyun_esa.go b/internal/deployer/aliyun_esa.go index 6d83c2c5..f18d0b53 100644 --- a/internal/deployer/aliyun_esa.go +++ b/internal/deployer/aliyun_esa.go @@ -25,7 +25,7 @@ type AliyunESADeployer struct { infos []string } -func NewAliyunEsaDeployer(option *DeployerOption) (*AliyunESADeployer, error) { +func NewAliyunESADeployer(option *DeployerOption) (*AliyunESADeployer, error) { access := &domain.AliyunAccess{} json.Unmarshal([]byte(option.Access), access) diff --git a/internal/deployer/aliyun_oss.go b/internal/deployer/aliyun_oss.go index 56e3a401..9e946545 100644 --- a/internal/deployer/aliyun_oss.go +++ b/internal/deployer/aliyun_oss.go @@ -16,7 +16,7 @@ type AliyunOSSDeployer struct { infos []string } -func NewAliyunOssDeployer(option *DeployerOption) (Deployer, error) { +func NewAliyunOSSDeployer(option *DeployerOption) (Deployer, error) { access := &domain.AliyunAccess{} json.Unmarshal([]byte(option.Access), access) diff --git a/internal/deployer/deployer.go b/internal/deployer/deployer.go index 85452c52..9385778c 100644 --- a/internal/deployer/deployer.go +++ b/internal/deployer/deployer.go @@ -97,11 +97,11 @@ func getWithDeployConfig(record *models.Record, cert *applicant.Certificate, dep switch deployConfig.Type { case targetAliyunOSS: - return NewAliyunOssDeployer(option) + return NewAliyunOSSDeployer(option) case targetAliyunCDN: - return NewAliyunCdnDeployer(option) + return NewAliyunCDNDeployer(option) case targetAliyunESA: - return NewAliyunEsaDeployer(option) + return NewAliyunESADeployer(option) case targetTencentCDN: return NewTencentCDNDeployer(option) case targetQiniuCdn: diff --git a/internal/deployer/k8s_secret.go b/internal/deployer/k8s_secret.go index 9672ee2c..d2400df6 100644 --- a/internal/deployer/k8s_secret.go +++ b/internal/deployer/k8s_secret.go @@ -8,11 +8,9 @@ import ( k8sMetaV1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes" "k8s.io/client-go/tools/clientcmd" -) -type KubernetesAccess struct { - KubeConfig string `json:"kubeConfig"` -} + "certimate/internal/domain" +) type K8sSecretDeployer struct { option *DeployerOption @@ -35,7 +33,7 @@ func (d *K8sSecretDeployer) GetInfo() []string { } func (d *K8sSecretDeployer) Deploy(ctx context.Context) error { - access := &KubernetesAccess{} + access := &domain.KubernetesAccess{} if err := json.Unmarshal([]byte(d.option.Access), access); err != nil { return err } @@ -86,7 +84,7 @@ func (d *K8sSecretDeployer) Deploy(ctx context.Context) error { return nil } -func (d *K8sSecretDeployer) createClient(access *KubernetesAccess) (*kubernetes.Clientset, error) { +func (d *K8sSecretDeployer) createClient(access *domain.KubernetesAccess) (*kubernetes.Clientset, error) { kubeConfig, err := clientcmd.Load([]byte(access.KubeConfig)) if err != nil { return nil, err diff --git a/internal/deployer/local.go b/internal/deployer/local.go index bf0ec5b6..44794594 100644 --- a/internal/deployer/local.go +++ b/internal/deployer/local.go @@ -8,9 +8,9 @@ import ( "os/exec" "path/filepath" "runtime" -) -type LocalAccess struct{} + "certimate/internal/domain" +) type LocalDeployer struct { option *DeployerOption @@ -33,7 +33,7 @@ func (d *LocalDeployer) GetInfo() []string { } func (d *LocalDeployer) Deploy(ctx context.Context) error { - access := &LocalAccess{} + access := &domain.LocalAccess{} if err := json.Unmarshal([]byte(d.option.Access), access); err != nil { return err } diff --git a/internal/deployer/ssh.go b/internal/deployer/ssh.go index 14df1aea..049baf69 100644 --- a/internal/deployer/ssh.go +++ b/internal/deployer/ssh.go @@ -10,16 +10,9 @@ import ( "github.com/pkg/sftp" sshPkg "golang.org/x/crypto/ssh" -) -type SSHAccess struct { - Host string `json:"host"` - Port string `json:"port"` - Username string `json:"username"` - Password string `json:"password"` - Key string `json:"key"` - KeyPassphrase string `json:"keyPassphrase"` -} + "certimate/internal/domain" +) type SSHDeployer struct { option *DeployerOption @@ -42,7 +35,7 @@ func (d *SSHDeployer) GetInfo() []string { } func (d *SSHDeployer) Deploy(ctx context.Context) error { - access := &SSHAccess{} + access := &domain.SSHAccess{} if err := json.Unmarshal([]byte(d.option.Access), access); err != nil { return err } @@ -130,7 +123,7 @@ func (d *SSHDeployer) upload(client *sshPkg.Client, content, path string) error return nil } -func (d *SSHDeployer) createClient(access *SSHAccess) (*sshPkg.Client, error) { +func (d *SSHDeployer) createClient(access *domain.SSHAccess) (*sshPkg.Client, error) { var authMethod sshPkg.AuthMethod if access.Key != "" { diff --git a/internal/deployer/webhook.go b/internal/deployer/webhook.go index be2a5b34..d553c59e 100644 --- a/internal/deployer/webhook.go +++ b/internal/deployer/webhook.go @@ -7,13 +7,10 @@ import ( "fmt" "net/http" + "certimate/internal/domain" xhttp "certimate/internal/utils/http" ) -type WebhookAccess struct { - Url string `json:"url"` -} - type WebhookDeployer struct { option *DeployerOption infos []string @@ -42,7 +39,7 @@ type webhookData struct { } func (d *WebhookDeployer) Deploy(ctx context.Context) error { - access := &WebhookAccess{} + access := &domain.WebhookAccess{} if err := json.Unmarshal([]byte(d.option.Access), access); err != nil { return fmt.Errorf("failed to parse hook access config: %w", err) } diff --git a/internal/domain/access.go b/internal/domain/access.go index 970dd922..ebd9191a 100644 --- a/internal/domain/access.go +++ b/internal/domain/access.go @@ -40,3 +40,22 @@ type GodaddyAccess struct { ApiKey string `json:"apiKey"` ApiSecret string `json:"apiSecret"` } + +type LocalAccess struct{} + +type SSHAccess struct { + Host string `json:"host"` + Port string `json:"port"` + Username string `json:"username"` + Password string `json:"password"` + Key string `json:"key"` + KeyPassphrase string `json:"keyPassphrase"` +} + +type WebhookAccess struct { + Url string `json:"url"` +} + +type KubernetesAccess struct { + KubeConfig string `json:"kubeConfig"` +}