refactor: clean code
This commit is contained in:
@@ -21,8 +21,8 @@ func NewACMEHttpReqApplicant(option *ApplyOption) Applicant {
|
||||
}
|
||||
|
||||
func (a *acmeHttpReqApplicant) Apply() (*Certificate, error) {
|
||||
access := &domain.HttpreqAccess{}
|
||||
json.Unmarshal([]byte(a.option.Access), access)
|
||||
access := &domain.ACMEHttpReqAccessConfig{}
|
||||
json.Unmarshal([]byte(a.option.AccessConfig), access)
|
||||
|
||||
config := httpreq.NewDefaultConfig()
|
||||
endpoint, _ := url.Parse(access.Endpoint)
|
||||
|
||||
@@ -20,8 +20,8 @@ func NewAliyunApplicant(option *ApplyOption) Applicant {
|
||||
}
|
||||
|
||||
func (a *aliyunApplicant) Apply() (*Certificate, error) {
|
||||
access := &domain.AliyunAccess{}
|
||||
json.Unmarshal([]byte(a.option.Access), access)
|
||||
access := &domain.AliyunAccessConfig{}
|
||||
json.Unmarshal([]byte(a.option.AccessConfig), access)
|
||||
|
||||
config := alidns.NewDefaultConfig()
|
||||
config.APIKey = access.AccessKeyId
|
||||
|
||||
@@ -26,26 +26,6 @@ import (
|
||||
"github.com/usual2970/certimate/internal/repository"
|
||||
)
|
||||
|
||||
/*
|
||||
提供商类型常量值。
|
||||
|
||||
注意:如果追加新的常量值,请保持以 ASCII 排序。
|
||||
NOTICE: If you add new constant, please keep ASCII order.
|
||||
*/
|
||||
const (
|
||||
configTypeACMEHttpReq = "acmehttpreq"
|
||||
configTypeAliyun = "aliyun"
|
||||
configTypeAWS = "aws"
|
||||
configTypeCloudflare = "cloudflare"
|
||||
configTypeGoDaddy = "godaddy"
|
||||
configTypeHuaweiCloud = "huaweicloud"
|
||||
configTypeNameDotCom = "namedotcom"
|
||||
configTypeNameSilo = "namesilo"
|
||||
configTypePowerDNS = "powerdns"
|
||||
configTypeTencentCloud = "tencentcloud"
|
||||
configTypeVolcEngine = "volcengine"
|
||||
)
|
||||
|
||||
const defaultSSLProvider = "letsencrypt"
|
||||
const (
|
||||
sslProviderLetsencrypt = "letsencrypt"
|
||||
@@ -78,8 +58,8 @@ type Certificate struct {
|
||||
|
||||
type ApplyOption struct {
|
||||
Email string `json:"email"`
|
||||
Domain string `json:"domain"`
|
||||
Access string `json:"access"`
|
||||
Domain string `json:"subjectAltNames"`
|
||||
AccessConfig string `json:"accessConfig"`
|
||||
KeyAlgorithm string `json:"keyAlgorithm"`
|
||||
Nameservers string `json:"nameservers"`
|
||||
PropagationTimeout int64 `json:"propagationTimeout"`
|
||||
@@ -165,14 +145,14 @@ func Get(record *models.Record) (Applicant, error) {
|
||||
option := &ApplyOption{
|
||||
Email: applyConfig.Email,
|
||||
Domain: record.GetString("domain"),
|
||||
Access: access.GetString("config"),
|
||||
AccessConfig: access.GetString("config"),
|
||||
KeyAlgorithm: applyConfig.KeyAlgorithm,
|
||||
Nameservers: applyConfig.Nameservers,
|
||||
PropagationTimeout: applyConfig.PropagationTimeout,
|
||||
DisableFollowCNAME: applyConfig.DisableFollowCNAME,
|
||||
}
|
||||
|
||||
return GetWithTypeOption(access.GetString("configType"), option)
|
||||
return GetWithTypeOption(domain.AccessProviderType(access.GetString("configType")), option)
|
||||
}
|
||||
|
||||
func GetWithApplyNode(node *domain.WorkflowNode) (Applicant, error) {
|
||||
@@ -187,46 +167,46 @@ func GetWithApplyNode(node *domain.WorkflowNode) (Applicant, error) {
|
||||
applyConfig := &ApplyOption{
|
||||
Email: node.GetConfigString("email"),
|
||||
Domain: node.GetConfigString("domain"),
|
||||
Access: access.Config,
|
||||
AccessConfig: access.Config,
|
||||
KeyAlgorithm: node.GetConfigString("keyAlgorithm"),
|
||||
Nameservers: node.GetConfigString("nameservers"),
|
||||
PropagationTimeout: node.GetConfigInt64("propagationTimeout"),
|
||||
DisableFollowCNAME: node.GetConfigBool("disableFollowCNAME"),
|
||||
}
|
||||
|
||||
return GetWithTypeOption(access.ConfigType, applyConfig)
|
||||
return GetWithTypeOption(domain.AccessProviderType(access.ConfigType), applyConfig)
|
||||
}
|
||||
|
||||
func GetWithTypeOption(t string, option *ApplyOption) (Applicant, error) {
|
||||
func GetWithTypeOption(providerType domain.AccessProviderType, option *ApplyOption) (Applicant, error) {
|
||||
/*
|
||||
注意:如果追加新的常量值,请保持以 ASCII 排序。
|
||||
NOTICE: If you add new constant, please keep ASCII order.
|
||||
*/
|
||||
switch t {
|
||||
case configTypeACMEHttpReq:
|
||||
switch providerType {
|
||||
case domain.ACCESS_PROVIDER_ACMEHTTPREQ:
|
||||
return NewACMEHttpReqApplicant(option), nil
|
||||
case configTypeAliyun:
|
||||
case domain.ACCESS_PROVIDER_ALIYUN:
|
||||
return NewAliyunApplicant(option), nil
|
||||
case configTypeAWS:
|
||||
case domain.ACCESS_PROVIDER_AWS:
|
||||
return NewAWSApplicant(option), nil
|
||||
case configTypeCloudflare:
|
||||
case domain.ACCESS_PROVIDER_CLOUDFLARE:
|
||||
return NewCloudflareApplicant(option), nil
|
||||
case configTypeGoDaddy:
|
||||
case domain.ACCESS_PROVIDER_GODADDY:
|
||||
return NewGoDaddyApplicant(option), nil
|
||||
case configTypeHuaweiCloud:
|
||||
case domain.ACCESS_PROVIDER_HUAWEICLOUD:
|
||||
return NewHuaweiCloudApplicant(option), nil
|
||||
case configTypeNameDotCom:
|
||||
case domain.ACCESS_PROVIDER_NAMEDOTCOM:
|
||||
return NewNameDotComApplicant(option), nil
|
||||
case configTypeNameSilo:
|
||||
case domain.ACCESS_PROVIDER_NAMESILO:
|
||||
return NewNamesiloApplicant(option), nil
|
||||
case configTypePowerDNS:
|
||||
case domain.ACCESS_PROVIDER_POWERDNS:
|
||||
return NewPowerDNSApplicant(option), nil
|
||||
case configTypeTencentCloud:
|
||||
case domain.ACCESS_PROVIDER_TENCENTCLOUD:
|
||||
return NewTencentCloudApplicant(option), nil
|
||||
case configTypeVolcEngine:
|
||||
case domain.ACCESS_PROVIDER_VOLCENGINE:
|
||||
return NewVolcEngineApplicant(option), nil
|
||||
default:
|
||||
return nil, fmt.Errorf("unsupported applicant type: %s", t)
|
||||
return nil, fmt.Errorf("unsupported applicant provider type: %s", providerType)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,8 +20,8 @@ func NewAWSApplicant(option *ApplyOption) Applicant {
|
||||
}
|
||||
|
||||
func (a *awsApplicant) Apply() (*Certificate, error) {
|
||||
access := &domain.AwsAccess{}
|
||||
json.Unmarshal([]byte(a.option.Access), access)
|
||||
access := &domain.AWSAccessConfig{}
|
||||
json.Unmarshal([]byte(a.option.AccessConfig), access)
|
||||
|
||||
config := route53.NewDefaultConfig()
|
||||
config.AccessKeyID = access.AccessKeyId
|
||||
|
||||
@@ -20,8 +20,8 @@ func NewCloudflareApplicant(option *ApplyOption) Applicant {
|
||||
}
|
||||
|
||||
func (a *cloudflareApplicant) Apply() (*Certificate, error) {
|
||||
access := &domain.CloudflareAccess{}
|
||||
json.Unmarshal([]byte(a.option.Access), access)
|
||||
access := &domain.CloudflareAccessConfig{}
|
||||
json.Unmarshal([]byte(a.option.AccessConfig), access)
|
||||
|
||||
config := cloudflare.NewDefaultConfig()
|
||||
config.AuthToken = access.DnsApiToken
|
||||
|
||||
@@ -20,8 +20,8 @@ func NewGoDaddyApplicant(option *ApplyOption) Applicant {
|
||||
}
|
||||
|
||||
func (a *godaddyApplicant) Apply() (*Certificate, error) {
|
||||
access := &domain.GodaddyAccess{}
|
||||
json.Unmarshal([]byte(a.option.Access), access)
|
||||
access := &domain.GoDaddyAccessConfig{}
|
||||
json.Unmarshal([]byte(a.option.AccessConfig), access)
|
||||
|
||||
config := godaddy.NewDefaultConfig()
|
||||
config.APIKey = access.ApiKey
|
||||
|
||||
@@ -20,8 +20,8 @@ func NewHuaweiCloudApplicant(option *ApplyOption) Applicant {
|
||||
}
|
||||
|
||||
func (a *huaweicloudApplicant) Apply() (*Certificate, error) {
|
||||
access := &domain.HuaweiCloudAccess{}
|
||||
json.Unmarshal([]byte(a.option.Access), access)
|
||||
access := &domain.HuaweiCloudAccessConfig{}
|
||||
json.Unmarshal([]byte(a.option.AccessConfig), access)
|
||||
|
||||
region := access.Region
|
||||
if region == "" {
|
||||
|
||||
@@ -19,8 +19,8 @@ func NewNameDotComApplicant(option *ApplyOption) Applicant {
|
||||
}
|
||||
|
||||
func (a *nameDotComApplicant) Apply() (*Certificate, error) {
|
||||
access := &domain.NameDotComAccess{}
|
||||
json.Unmarshal([]byte(a.option.Access), access)
|
||||
access := &domain.NameDotComAccessConfig{}
|
||||
json.Unmarshal([]byte(a.option.AccessConfig), access)
|
||||
|
||||
config := namedotcom.NewDefaultConfig()
|
||||
config.Username = access.Username
|
||||
|
||||
@@ -20,8 +20,8 @@ func NewNamesiloApplicant(option *ApplyOption) Applicant {
|
||||
}
|
||||
|
||||
func (a *namesiloApplicant) Apply() (*Certificate, error) {
|
||||
access := &domain.NameSiloAccess{}
|
||||
json.Unmarshal([]byte(a.option.Access), access)
|
||||
access := &domain.NameSiloAccessConfig{}
|
||||
json.Unmarshal([]byte(a.option.AccessConfig), access)
|
||||
|
||||
config := namesilo.NewDefaultConfig()
|
||||
config.APIKey = access.ApiKey
|
||||
|
||||
@@ -21,8 +21,8 @@ func NewPowerDNSApplicant(option *ApplyOption) Applicant {
|
||||
}
|
||||
|
||||
func (a *powerdnsApplicant) Apply() (*Certificate, error) {
|
||||
access := &domain.PdnsAccess{}
|
||||
json.Unmarshal([]byte(a.option.Access), access)
|
||||
access := &domain.PowerDNSAccessConfig{}
|
||||
json.Unmarshal([]byte(a.option.AccessConfig), access)
|
||||
|
||||
config := pdns.NewDefaultConfig()
|
||||
host, _ := url.Parse(access.ApiUrl)
|
||||
|
||||
@@ -20,8 +20,8 @@ func NewTencentCloudApplicant(option *ApplyOption) Applicant {
|
||||
}
|
||||
|
||||
func (a *tencentcloudApplicant) Apply() (*Certificate, error) {
|
||||
access := &domain.TencentAccess{}
|
||||
json.Unmarshal([]byte(a.option.Access), access)
|
||||
access := &domain.TencentCloudAccessConfig{}
|
||||
json.Unmarshal([]byte(a.option.AccessConfig), access)
|
||||
|
||||
config := tencentcloud.NewDefaultConfig()
|
||||
config.SecretID = access.SecretId
|
||||
|
||||
@@ -19,8 +19,8 @@ func NewVolcEngineApplicant(option *ApplyOption) Applicant {
|
||||
}
|
||||
|
||||
func (a *volcengineApplicant) Apply() (*Certificate, error) {
|
||||
access := &domain.VolcEngineAccess{}
|
||||
json.Unmarshal([]byte(a.option.Access), access)
|
||||
access := &domain.VolcEngineAccessConfig{}
|
||||
json.Unmarshal([]byte(a.option.AccessConfig), access)
|
||||
|
||||
config := volcengine.NewDefaultConfig()
|
||||
config.AccessKey = access.AccessKeyId
|
||||
|
||||
Reference in New Issue
Block a user