main
Fu Diwei 2024-10-19 10:02:31 +08:00
parent 4382474449
commit 6225969d4c
9 changed files with 38 additions and 31 deletions

View File

@ -20,7 +20,7 @@ type AliyunCDNDeployer struct {
infos []string infos []string
} }
func NewAliyunCdnDeployer(option *DeployerOption) (*AliyunCDNDeployer, error) { func NewAliyunCDNDeployer(option *DeployerOption) (*AliyunCDNDeployer, error) {
access := &domain.AliyunAccess{} access := &domain.AliyunAccess{}
json.Unmarshal([]byte(option.Access), access) json.Unmarshal([]byte(option.Access), access)

View File

@ -25,7 +25,7 @@ type AliyunESADeployer struct {
infos []string infos []string
} }
func NewAliyunEsaDeployer(option *DeployerOption) (*AliyunESADeployer, error) { func NewAliyunESADeployer(option *DeployerOption) (*AliyunESADeployer, error) {
access := &domain.AliyunAccess{} access := &domain.AliyunAccess{}
json.Unmarshal([]byte(option.Access), access) json.Unmarshal([]byte(option.Access), access)

View File

@ -16,7 +16,7 @@ type AliyunOSSDeployer struct {
infos []string infos []string
} }
func NewAliyunOssDeployer(option *DeployerOption) (Deployer, error) { func NewAliyunOSSDeployer(option *DeployerOption) (Deployer, error) {
access := &domain.AliyunAccess{} access := &domain.AliyunAccess{}
json.Unmarshal([]byte(option.Access), access) json.Unmarshal([]byte(option.Access), access)

View File

@ -97,11 +97,11 @@ func getWithDeployConfig(record *models.Record, cert *applicant.Certificate, dep
switch deployConfig.Type { switch deployConfig.Type {
case targetAliyunOSS: case targetAliyunOSS:
return NewAliyunOssDeployer(option) return NewAliyunOSSDeployer(option)
case targetAliyunCDN: case targetAliyunCDN:
return NewAliyunCdnDeployer(option) return NewAliyunCDNDeployer(option)
case targetAliyunESA: case targetAliyunESA:
return NewAliyunEsaDeployer(option) return NewAliyunESADeployer(option)
case targetTencentCDN: case targetTencentCDN:
return NewTencentCDNDeployer(option) return NewTencentCDNDeployer(option)
case targetQiniuCdn: case targetQiniuCdn:

View File

@ -8,11 +8,9 @@ import (
k8sMetaV1 "k8s.io/apimachinery/pkg/apis/meta/v1" k8sMetaV1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes" "k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd" "k8s.io/client-go/tools/clientcmd"
)
type KubernetesAccess struct { "certimate/internal/domain"
KubeConfig string `json:"kubeConfig"` )
}
type K8sSecretDeployer struct { type K8sSecretDeployer struct {
option *DeployerOption option *DeployerOption
@ -35,7 +33,7 @@ func (d *K8sSecretDeployer) GetInfo() []string {
} }
func (d *K8sSecretDeployer) Deploy(ctx context.Context) error { func (d *K8sSecretDeployer) Deploy(ctx context.Context) error {
access := &KubernetesAccess{} access := &domain.KubernetesAccess{}
if err := json.Unmarshal([]byte(d.option.Access), access); err != nil { if err := json.Unmarshal([]byte(d.option.Access), access); err != nil {
return err return err
} }
@ -86,7 +84,7 @@ func (d *K8sSecretDeployer) Deploy(ctx context.Context) error {
return nil 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)) kubeConfig, err := clientcmd.Load([]byte(access.KubeConfig))
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -8,9 +8,9 @@ import (
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"runtime" "runtime"
)
type LocalAccess struct{} "certimate/internal/domain"
)
type LocalDeployer struct { type LocalDeployer struct {
option *DeployerOption option *DeployerOption
@ -33,7 +33,7 @@ func (d *LocalDeployer) GetInfo() []string {
} }
func (d *LocalDeployer) Deploy(ctx context.Context) error { func (d *LocalDeployer) Deploy(ctx context.Context) error {
access := &LocalAccess{} access := &domain.LocalAccess{}
if err := json.Unmarshal([]byte(d.option.Access), access); err != nil { if err := json.Unmarshal([]byte(d.option.Access), access); err != nil {
return err return err
} }

View File

@ -10,16 +10,9 @@ import (
"github.com/pkg/sftp" "github.com/pkg/sftp"
sshPkg "golang.org/x/crypto/ssh" sshPkg "golang.org/x/crypto/ssh"
)
type SSHAccess struct { "certimate/internal/domain"
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 SSHDeployer struct { type SSHDeployer struct {
option *DeployerOption option *DeployerOption
@ -42,7 +35,7 @@ func (d *SSHDeployer) GetInfo() []string {
} }
func (d *SSHDeployer) Deploy(ctx context.Context) error { func (d *SSHDeployer) Deploy(ctx context.Context) error {
access := &SSHAccess{} access := &domain.SSHAccess{}
if err := json.Unmarshal([]byte(d.option.Access), access); err != nil { if err := json.Unmarshal([]byte(d.option.Access), access); err != nil {
return err return err
} }
@ -130,7 +123,7 @@ func (d *SSHDeployer) upload(client *sshPkg.Client, content, path string) error
return nil 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 var authMethod sshPkg.AuthMethod
if access.Key != "" { if access.Key != "" {

View File

@ -7,13 +7,10 @@ import (
"fmt" "fmt"
"net/http" "net/http"
"certimate/internal/domain"
xhttp "certimate/internal/utils/http" xhttp "certimate/internal/utils/http"
) )
type WebhookAccess struct {
Url string `json:"url"`
}
type WebhookDeployer struct { type WebhookDeployer struct {
option *DeployerOption option *DeployerOption
infos []string infos []string
@ -42,7 +39,7 @@ type webhookData struct {
} }
func (d *WebhookDeployer) Deploy(ctx context.Context) error { func (d *WebhookDeployer) Deploy(ctx context.Context) error {
access := &WebhookAccess{} access := &domain.WebhookAccess{}
if err := json.Unmarshal([]byte(d.option.Access), access); err != nil { if err := json.Unmarshal([]byte(d.option.Access), access); err != nil {
return fmt.Errorf("failed to parse hook access config: %w", err) return fmt.Errorf("failed to parse hook access config: %w", err)
} }

View File

@ -40,3 +40,22 @@ type GodaddyAccess struct {
ApiKey string `json:"apiKey"` ApiKey string `json:"apiKey"`
ApiSecret string `json:"apiSecret"` 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"`
}