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
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
|
||||
/*
|
||||
提供商部署目标常量值。
|
||||
短横线前的部分始终等于提供商类型。
|
||||
|
||||
注意:如果追加新的常量值,请保持以 ASCII 排序。
|
||||
NOTICE: If you add new constant, please keep ASCII order.
|
||||
@@ -140,7 +141,7 @@ type proxyDeployer struct {
|
||||
}
|
||||
|
||||
func (d *proxyDeployer) GetID() string {
|
||||
return fmt.Sprintf("%s-%s", d.option.AccessRecord.GetString("name"), d.option.AccessRecord.Id)
|
||||
return fmt.Sprintf("%s-%s", d.option.AccessRecord.Name, d.option.AccessRecord.Id)
|
||||
}
|
||||
|
||||
func (d *proxyDeployer) GetInfos() []string {
|
||||
|
||||
@@ -43,7 +43,7 @@ func createDeployer(target string, accessConfig string, deployConfig map[string]
|
||||
switch target {
|
||||
case targetAliyunALB, targetAliyunCDN, targetAliyunCLB, targetAliyunDCDN, targetAliyunNLB, targetAliyunOSS:
|
||||
{
|
||||
access := &domain.AliyunAccess{}
|
||||
access := &domain.AliyunAccessConfig{}
|
||||
if err := json.Unmarshal([]byte(accessConfig), access); err != nil {
|
||||
return nil, nil, fmt.Errorf("failed to unmarshal access config: %w", err)
|
||||
}
|
||||
@@ -115,7 +115,7 @@ func createDeployer(target string, accessConfig string, deployConfig map[string]
|
||||
|
||||
case targetBaiduCloudCDN:
|
||||
{
|
||||
access := &domain.BaiduCloudAccess{}
|
||||
access := &domain.BaiduCloudAccessConfig{}
|
||||
if err := json.Unmarshal([]byte(accessConfig), access); err != nil {
|
||||
return nil, nil, fmt.Errorf("failed to unmarshal access config: %w", err)
|
||||
}
|
||||
@@ -130,7 +130,7 @@ func createDeployer(target string, accessConfig string, deployConfig map[string]
|
||||
|
||||
case targetBytePlusCDN:
|
||||
{
|
||||
access := &domain.ByteplusAccess{}
|
||||
access := &domain.BytePlusAccessConfig{}
|
||||
if err := json.Unmarshal([]byte(accessConfig), access); err != nil {
|
||||
return nil, nil, fmt.Errorf("failed to unmarshal access config: %w", err)
|
||||
}
|
||||
@@ -145,7 +145,7 @@ func createDeployer(target string, accessConfig string, deployConfig map[string]
|
||||
|
||||
case targetDogeCloudCDN:
|
||||
{
|
||||
access := &domain.DogeCloudAccess{}
|
||||
access := &domain.DogeCloudAccessConfig{}
|
||||
if err := json.Unmarshal([]byte(accessConfig), access); err != nil {
|
||||
return nil, nil, fmt.Errorf("failed to unmarshal access config: %w", err)
|
||||
}
|
||||
@@ -160,7 +160,7 @@ func createDeployer(target string, accessConfig string, deployConfig map[string]
|
||||
|
||||
case targetHuaweiCloudCDN, targetHuaweiCloudELB:
|
||||
{
|
||||
access := &domain.HuaweiCloudAccess{}
|
||||
access := &domain.HuaweiCloudAccessConfig{}
|
||||
if err := json.Unmarshal([]byte(accessConfig), access); err != nil {
|
||||
return nil, nil, fmt.Errorf("failed to unmarshal access config: %w", err)
|
||||
}
|
||||
@@ -211,7 +211,7 @@ func createDeployer(target string, accessConfig string, deployConfig map[string]
|
||||
|
||||
case targetK8sSecret:
|
||||
{
|
||||
access := &domain.KubernetesAccess{}
|
||||
access := &domain.KubernetesAccessConfig{}
|
||||
if err := json.Unmarshal([]byte(accessConfig), access); err != nil {
|
||||
return nil, nil, fmt.Errorf("failed to unmarshal access config: %w", err)
|
||||
}
|
||||
@@ -228,7 +228,7 @@ func createDeployer(target string, accessConfig string, deployConfig map[string]
|
||||
|
||||
case targetQiniuCDN:
|
||||
{
|
||||
access := &domain.QiniuAccess{}
|
||||
access := &domain.QiniuAccessConfig{}
|
||||
if err := json.Unmarshal([]byte(accessConfig), access); err != nil {
|
||||
return nil, nil, fmt.Errorf("failed to unmarshal access config: %w", err)
|
||||
}
|
||||
@@ -243,7 +243,7 @@ func createDeployer(target string, accessConfig string, deployConfig map[string]
|
||||
|
||||
case targetSSH:
|
||||
{
|
||||
access := &domain.SSHAccess{}
|
||||
access := &domain.SSHAccessConfig{}
|
||||
if err := json.Unmarshal([]byte(accessConfig), access); err != nil {
|
||||
return nil, nil, fmt.Errorf("failed to unmarshal access config: %w", err)
|
||||
}
|
||||
@@ -271,7 +271,7 @@ func createDeployer(target string, accessConfig string, deployConfig map[string]
|
||||
|
||||
case targetTencentCloudCDN, targetTencentCloudCLB, targetTencentCloudCOS, targetTencentCloudECDN, targetTencentCloudEO:
|
||||
{
|
||||
access := &domain.TencentAccess{}
|
||||
access := &domain.TencentCloudAccessConfig{}
|
||||
if err := json.Unmarshal([]byte(accessConfig), access); err != nil {
|
||||
return nil, nil, fmt.Errorf("failed to unmarshal access config: %w", err)
|
||||
}
|
||||
@@ -331,7 +331,7 @@ func createDeployer(target string, accessConfig string, deployConfig map[string]
|
||||
|
||||
case targetVolcEngineCDN, targetVolcEngineLive:
|
||||
{
|
||||
access := &domain.VolcEngineAccess{}
|
||||
access := &domain.VolcEngineAccessConfig{}
|
||||
if err := json.Unmarshal([]byte(accessConfig), access); err != nil {
|
||||
return nil, nil, fmt.Errorf("failed to unmarshal access config: %w", err)
|
||||
}
|
||||
@@ -339,16 +339,16 @@ func createDeployer(target string, accessConfig string, deployConfig map[string]
|
||||
switch target {
|
||||
case targetVolcEngineCDN:
|
||||
deployer, err := providerVolcEngineCDN.NewWithLogger(&providerVolcEngineCDN.VolcEngineCDNDeployerConfig{
|
||||
AccessKey: access.AccessKey,
|
||||
SecretKey: access.SecretKey,
|
||||
AccessKey: access.AccessKeyId,
|
||||
SecretKey: access.SecretAccessKey,
|
||||
Domain: maps.GetValueAsString(deployConfig, "domain"),
|
||||
}, logger)
|
||||
return deployer, logger, err
|
||||
|
||||
case targetVolcEngineLive:
|
||||
deployer, err := providerVolcEngineLive.NewWithLogger(&providerVolcEngineLive.VolcEngineLiveDeployerConfig{
|
||||
AccessKey: access.AccessKey,
|
||||
SecretKey: access.SecretKey,
|
||||
AccessKey: access.AccessKeyId,
|
||||
SecretKey: access.SecretAccessKey,
|
||||
Domain: maps.GetValueAsString(deployConfig, "domain"),
|
||||
}, logger)
|
||||
return deployer, logger, err
|
||||
@@ -360,7 +360,7 @@ func createDeployer(target string, accessConfig string, deployConfig map[string]
|
||||
|
||||
case targetWebhook:
|
||||
{
|
||||
access := &domain.WebhookAccess{}
|
||||
access := &domain.WebhookAccessConfig{}
|
||||
if err := json.Unmarshal([]byte(accessConfig), access); err != nil {
|
||||
return nil, nil, fmt.Errorf("failed to unmarshal access config: %w", err)
|
||||
}
|
||||
|
||||
@@ -4,109 +4,118 @@ import "time"
|
||||
|
||||
type Access struct {
|
||||
Meta
|
||||
Name string `json:"name"`
|
||||
Config string `json:"config"`
|
||||
ConfigType string `json:"configType"`
|
||||
Deleted time.Time `json:"deleted"`
|
||||
Usage string `json:"usage"`
|
||||
Name string `json:"name" db:"name"`
|
||||
ConfigType string `json:"configType" db:"configType"`
|
||||
Config string `json:"config" db:"config"`
|
||||
Usage string `json:"usage" db:"usage"`
|
||||
DeletedAt time.Time `json:"deleted" db:"deleted"`
|
||||
}
|
||||
|
||||
// 兼容一下原 pocketbase 的 record
|
||||
func (a *Access) GetString(key string) string {
|
||||
switch key {
|
||||
case "name":
|
||||
return a.Name
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
type AccessProviderType string
|
||||
|
||||
type AliyunAccess struct {
|
||||
AccessKeyId string `json:"accessKeyId"`
|
||||
AccessKeySecret string `json:"accessKeySecret"`
|
||||
}
|
||||
/*
|
||||
提供商类型常量值。
|
||||
|
||||
type ByteplusAccess struct {
|
||||
AccessKey string `json:"accessKey"`
|
||||
SecretKey string `json:"secretKey"`
|
||||
}
|
||||
注意:如果追加新的常量值,请保持以 ASCII 排序。
|
||||
NOTICE: If you add new constant, please keep ASCII order.
|
||||
*/
|
||||
const (
|
||||
ACCESS_PROVIDER_ACMEHTTPREQ = AccessProviderType("acmehttpreq")
|
||||
ACCESS_PROVIDER_ALIYUN = AccessProviderType("aliyun")
|
||||
ACCESS_PROVIDER_AWS = AccessProviderType("aws")
|
||||
ACCESS_PROVIDER_BAIDUCLOUD = AccessProviderType("baiducloud")
|
||||
ACCESS_PROVIDER_BYTEPLUS = AccessProviderType("byteplus")
|
||||
ACCESS_PROVIDER_CLOUDFLARE = AccessProviderType("cloudflare")
|
||||
ACCESS_PROVIDER_DOGECLOUD = AccessProviderType("dogecloud")
|
||||
ACCESS_PROVIDER_GODADDY = AccessProviderType("godaddy")
|
||||
ACCESS_PROVIDER_HUAWEICLOUD = AccessProviderType("huaweicloud")
|
||||
ACCESS_PROVIDER_KUBERNETES = AccessProviderType("k8s")
|
||||
ACCESS_PROVIDER_LOCAL = AccessProviderType("local")
|
||||
ACCESS_PROVIDER_NAMEDOTCOM = AccessProviderType("namedotcom")
|
||||
ACCESS_PROVIDER_NAMESILO = AccessProviderType("namesilo")
|
||||
ACCESS_PROVIDER_POWERDNS = AccessProviderType("powerdns")
|
||||
ACCESS_PROVIDER_QINIU = AccessProviderType("qiniu")
|
||||
ACCESS_PROVIDER_SSH = AccessProviderType("ssh")
|
||||
ACCESS_PROVIDER_TENCENTCLOUD = AccessProviderType("tencentcloud")
|
||||
ACCESS_PROVIDER_VOLCENGINE = AccessProviderType("volcengine")
|
||||
ACCESS_PROVIDER_WEBHOOK = AccessProviderType("webhook")
|
||||
)
|
||||
|
||||
type TencentAccess struct {
|
||||
SecretId string `json:"secretId"`
|
||||
SecretKey string `json:"secretKey"`
|
||||
}
|
||||
|
||||
type HuaweiCloudAccess struct {
|
||||
AccessKeyId string `json:"accessKeyId"`
|
||||
SecretAccessKey string `json:"secretAccessKey"`
|
||||
Region string `json:"region"`
|
||||
}
|
||||
|
||||
type BaiduCloudAccess struct {
|
||||
AccessKeyId string `json:"accessKeyId"`
|
||||
SecretAccessKey string `json:"secretAccessKey"`
|
||||
}
|
||||
|
||||
type AwsAccess struct {
|
||||
AccessKeyId string `json:"accessKeyId"`
|
||||
SecretAccessKey string `json:"secretAccessKey"`
|
||||
Region string `json:"region"`
|
||||
HostedZoneId string `json:"hostedZoneId"`
|
||||
}
|
||||
|
||||
type CloudflareAccess struct {
|
||||
DnsApiToken string `json:"dnsApiToken"`
|
||||
}
|
||||
|
||||
type QiniuAccess struct {
|
||||
AccessKey string `json:"accessKey"`
|
||||
SecretKey string `json:"secretKey"`
|
||||
}
|
||||
|
||||
type DogeCloudAccess struct {
|
||||
AccessKey string `json:"accessKey"`
|
||||
SecretKey string `json:"secretKey"`
|
||||
}
|
||||
|
||||
type NameSiloAccess struct {
|
||||
ApiKey string `json:"apiKey"`
|
||||
}
|
||||
|
||||
type GodaddyAccess struct {
|
||||
ApiKey string `json:"apiKey"`
|
||||
ApiSecret string `json:"apiSecret"`
|
||||
}
|
||||
|
||||
type NameDotComAccess struct {
|
||||
Username string `json:"username"`
|
||||
ApiToken string `json:"apiToken"`
|
||||
}
|
||||
|
||||
type PdnsAccess struct {
|
||||
ApiUrl string `json:"apiUrl"`
|
||||
ApiKey string `json:"apiKey"`
|
||||
}
|
||||
|
||||
type VolcEngineAccess struct {
|
||||
AccessKey string `json:"accessKey"`
|
||||
SecretKey string `json:"secretKey"`
|
||||
|
||||
// Deprecated: Use [AccessKey] and [SecretKey] instead in the future
|
||||
AccessKeyId string `json:"accessKeyId"`
|
||||
// Deprecated: Use [AccessKey] and [SecretKey] instead in the future
|
||||
SecretAccessKey string `json:"secretAccessKey"`
|
||||
}
|
||||
|
||||
type HttpreqAccess struct {
|
||||
type ACMEHttpReqAccessConfig struct {
|
||||
Endpoint string `json:"endpoint"`
|
||||
Mode string `json:"mode"`
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
}
|
||||
|
||||
type LocalAccess struct{}
|
||||
type AliyunAccessConfig struct {
|
||||
AccessKeyId string `json:"accessKeyId"`
|
||||
AccessKeySecret string `json:"accessKeySecret"`
|
||||
}
|
||||
|
||||
type SSHAccess struct {
|
||||
type AWSAccessConfig struct {
|
||||
AccessKeyId string `json:"accessKeyId"`
|
||||
SecretAccessKey string `json:"secretAccessKey"`
|
||||
Region string `json:"region"`
|
||||
HostedZoneId string `json:"hostedZoneId"`
|
||||
}
|
||||
|
||||
type BaiduCloudAccessConfig struct {
|
||||
AccessKeyId string `json:"accessKeyId"`
|
||||
SecretAccessKey string `json:"secretAccessKey"`
|
||||
}
|
||||
|
||||
type BytePlusAccessConfig struct {
|
||||
AccessKey string `json:"accessKey"`
|
||||
SecretKey string `json:"secretKey"`
|
||||
}
|
||||
|
||||
type CloudflareAccessConfig struct {
|
||||
DnsApiToken string `json:"dnsApiToken"`
|
||||
}
|
||||
|
||||
type DogeCloudAccessConfig struct {
|
||||
AccessKey string `json:"accessKey"`
|
||||
SecretKey string `json:"secretKey"`
|
||||
}
|
||||
|
||||
type GoDaddyAccessConfig struct {
|
||||
ApiKey string `json:"apiKey"`
|
||||
ApiSecret string `json:"apiSecret"`
|
||||
}
|
||||
|
||||
type HuaweiCloudAccessConfig struct {
|
||||
AccessKeyId string `json:"accessKeyId"`
|
||||
SecretAccessKey string `json:"secretAccessKey"`
|
||||
Region string `json:"region"`
|
||||
}
|
||||
|
||||
type LocalAccessConfig struct{}
|
||||
|
||||
type KubernetesAccessConfig struct {
|
||||
KubeConfig string `json:"kubeConfig"`
|
||||
}
|
||||
|
||||
type NameDotComAccessConfig struct {
|
||||
Username string `json:"username"`
|
||||
ApiToken string `json:"apiToken"`
|
||||
}
|
||||
|
||||
type NameSiloAccessConfig struct {
|
||||
ApiKey string `json:"apiKey"`
|
||||
}
|
||||
|
||||
type PowerDNSAccessConfig struct {
|
||||
ApiUrl string `json:"apiUrl"`
|
||||
ApiKey string `json:"apiKey"`
|
||||
}
|
||||
|
||||
type QiniuAccessConfig struct {
|
||||
AccessKey string `json:"accessKey"`
|
||||
SecretKey string `json:"secretKey"`
|
||||
}
|
||||
|
||||
type SSHAccessConfig struct {
|
||||
Host string `json:"host"`
|
||||
Port string `json:"port"`
|
||||
Username string `json:"username"`
|
||||
@@ -115,10 +124,16 @@ type SSHAccess struct {
|
||||
KeyPassphrase string `json:"keyPassphrase"`
|
||||
}
|
||||
|
||||
type WebhookAccess struct {
|
||||
Url string `json:"url"`
|
||||
type TencentCloudAccessConfig struct {
|
||||
SecretId string `json:"secretId"`
|
||||
SecretKey string `json:"secretKey"`
|
||||
}
|
||||
|
||||
type KubernetesAccess struct {
|
||||
KubeConfig string `json:"kubeConfig"`
|
||||
type VolcEngineAccessConfig struct {
|
||||
AccessKeyId string `json:"accessKeyId"`
|
||||
SecretAccessKey string `json:"secretAccessKey"`
|
||||
}
|
||||
|
||||
type WebhookAccessConfig struct {
|
||||
Url string `json:"url"`
|
||||
}
|
||||
|
||||
@@ -1,17 +1,13 @@
|
||||
package domain
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/go-acme/lego/v4/registration"
|
||||
)
|
||||
|
||||
type AcmeAccount struct {
|
||||
Id string
|
||||
Ca string
|
||||
Email string
|
||||
Resource *registration.Resource
|
||||
Key string
|
||||
Created time.Time
|
||||
Updated time.Time
|
||||
Meta
|
||||
CA string `json:"ca" db:"ca"`
|
||||
Email string `json:"email" db:"email"`
|
||||
Resource *registration.Resource `json:"resource" db:"resource"`
|
||||
Key string `json:"key" db:"key"`
|
||||
}
|
||||
|
||||
@@ -12,13 +12,13 @@ type Certificate struct {
|
||||
IssuerCertificate string `json:"issuerCertificate" db:"issuerCertificate"`
|
||||
CertUrl string `json:"certUrl" db:"certUrl"`
|
||||
CertStableUrl string `json:"certStableUrl" db:"certStableUrl"`
|
||||
Output string `json:"output" db:"output"`
|
||||
Workflow string `json:"workflow" db:"workflow"`
|
||||
ExpireAt time.Time `json:"ExpireAt" db:"expireAt"`
|
||||
NodeId string `json:"nodeId" db:"nodeId"`
|
||||
WorkflowId string `json:"workflow" db:"workflow"`
|
||||
WorkflowNodeId string `json:"nodeId" db:"nodeId"`
|
||||
WorkflowOutputId string `json:"output" db:"output"`
|
||||
ExpireAt time.Time `json:"expireAt" db:"expireAt"`
|
||||
}
|
||||
|
||||
type MetaData struct {
|
||||
type CertificateMeta struct {
|
||||
Version string `json:"version"`
|
||||
SerialNumber string `json:"serialNumber"`
|
||||
Validity CertificateValidity `json:"validity"`
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
package domain
|
||||
|
||||
import "time"
|
||||
|
||||
type Meta struct {
|
||||
Id string `json:"id" db:"id"`
|
||||
Created time.Time `json:"created" db:"created"`
|
||||
Updated time.Time `json:"updated" db:"updated"`
|
||||
}
|
||||
@@ -1,12 +1,6 @@
|
||||
package domain
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
|
||||
"github.com/usual2970/certimate/internal/pkg/utils/maps"
|
||||
)
|
||||
|
||||
// Deprecated: TODO: 即将废弃
|
||||
type ApplyConfig struct {
|
||||
Email string `json:"email"`
|
||||
Access string `json:"access"`
|
||||
@@ -16,6 +10,7 @@ type ApplyConfig struct {
|
||||
DisableFollowCNAME bool `json:"disableFollowCNAME"`
|
||||
}
|
||||
|
||||
// Deprecated: TODO: 即将废弃
|
||||
type DeployConfig struct {
|
||||
Id string `json:"id"`
|
||||
Access string `json:"access"`
|
||||
@@ -23,121 +18,7 @@ type DeployConfig struct {
|
||||
Config map[string]any `json:"config"`
|
||||
}
|
||||
|
||||
// Deprecated: 以字符串形式获取配置项。
|
||||
//
|
||||
// 入参:
|
||||
// - key: 配置项的键。
|
||||
//
|
||||
// 出参:
|
||||
// - 配置项的值。如果配置项不存在或者类型不是字符串,则返回空字符串。
|
||||
func (dc *DeployConfig) GetConfigAsString(key string) string {
|
||||
return maps.GetValueAsString(dc.Config, key)
|
||||
}
|
||||
|
||||
// Deprecated: 以字符串形式获取配置项。
|
||||
//
|
||||
// 入参:
|
||||
// - key: 配置项的键。
|
||||
// - defaultValue: 默认值。
|
||||
//
|
||||
// 出参:
|
||||
// - 配置项的值。如果配置项不存在、类型不是字符串或者值为零值,则返回默认值。
|
||||
func (dc *DeployConfig) GetConfigOrDefaultAsString(key string, defaultValue string) string {
|
||||
return maps.GetValueOrDefaultAsString(dc.Config, key, defaultValue)
|
||||
}
|
||||
|
||||
// Deprecated: 以 32 位整数形式获取配置项。
|
||||
//
|
||||
// 入参:
|
||||
// - key: 配置项的键。
|
||||
//
|
||||
// 出参:
|
||||
// - 配置项的值。如果配置项不存在或者类型不是 32 位整数,则返回 0。
|
||||
func (dc *DeployConfig) GetConfigAsInt32(key string) int32 {
|
||||
return maps.GetValueAsInt32(dc.Config, key)
|
||||
}
|
||||
|
||||
// Deprecated: 以 32 位整数形式获取配置项。
|
||||
//
|
||||
// 入参:
|
||||
// - key: 配置项的键。
|
||||
// - defaultValue: 默认值。
|
||||
//
|
||||
// 出参:
|
||||
// - 配置项的值。如果配置项不存在、类型不是 32 位整数或者值为零值,则返回默认值。
|
||||
func (dc *DeployConfig) GetConfigOrDefaultAsInt32(key string, defaultValue int32) int32 {
|
||||
return maps.GetValueOrDefaultAsInt32(dc.Config, key, defaultValue)
|
||||
}
|
||||
|
||||
// Deprecated: 以布尔形式获取配置项。
|
||||
//
|
||||
// 入参:
|
||||
// - key: 配置项的键。
|
||||
//
|
||||
// 出参:
|
||||
// - 配置项的值。如果配置项不存在或者类型不是布尔,则返回 false。
|
||||
func (dc *DeployConfig) GetConfigAsBool(key string) bool {
|
||||
return maps.GetValueAsBool(dc.Config, key)
|
||||
}
|
||||
|
||||
// Deprecated: 以布尔形式获取配置项。
|
||||
//
|
||||
// 入参:
|
||||
// - key: 配置项的键。
|
||||
// - defaultValue: 默认值。
|
||||
//
|
||||
// 出参:
|
||||
// - 配置项的值。如果配置项不存在或者类型不是布尔,则返回默认值。
|
||||
func (dc *DeployConfig) GetConfigOrDefaultAsBool(key string, defaultValue bool) bool {
|
||||
return maps.GetValueOrDefaultAsBool(dc.Config, key, defaultValue)
|
||||
}
|
||||
|
||||
// Deprecated: 以变量字典形式获取配置项。
|
||||
//
|
||||
// 出参:
|
||||
// - 变量字典。
|
||||
func (dc *DeployConfig) GetConfigAsVariables() map[string]string {
|
||||
rs := make(map[string]string)
|
||||
|
||||
if dc.Config != nil {
|
||||
value, ok := dc.Config["variables"]
|
||||
if !ok {
|
||||
return rs
|
||||
}
|
||||
|
||||
kvs := make([]KV, 0)
|
||||
bts, _ := json.Marshal(value)
|
||||
if err := json.Unmarshal(bts, &kvs); err != nil {
|
||||
return rs
|
||||
}
|
||||
|
||||
for _, kv := range kvs {
|
||||
rs[kv.Key] = kv.Value
|
||||
}
|
||||
}
|
||||
|
||||
return rs
|
||||
}
|
||||
|
||||
// Deprecated: GetDomain returns the domain from the deploy config,
|
||||
// if the domain is a wildcard domain, and wildcard is true, return the wildcard domain
|
||||
func (dc *DeployConfig) GetDomain(wildcard ...bool) string {
|
||||
val := dc.GetConfigAsString("domain")
|
||||
if val == "" {
|
||||
return ""
|
||||
}
|
||||
|
||||
if !strings.HasPrefix(val, "*") {
|
||||
return val
|
||||
}
|
||||
|
||||
if len(wildcard) > 0 && wildcard[0] {
|
||||
return val
|
||||
}
|
||||
|
||||
return strings.TrimPrefix(val, "*")
|
||||
}
|
||||
|
||||
// Deprecated: TODO: 即将废弃
|
||||
type KV struct {
|
||||
Key string `json:"key"`
|
||||
Value string `json:"value"`
|
||||
|
||||
9
internal/domain/meta.go
Normal file
9
internal/domain/meta.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package domain
|
||||
|
||||
import "time"
|
||||
|
||||
type Meta struct {
|
||||
Id string `json:"id" db:"id"`
|
||||
CreatedAt time.Time `json:"created" db:"created"`
|
||||
UpdatedAt time.Time `json:"updated" db:"updated"`
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package domain
|
||||
|
||||
type NotifyChannelType string
|
||||
|
||||
/*
|
||||
消息通知渠道常量值。
|
||||
|
||||
@@ -7,14 +9,14 @@ package domain
|
||||
NOTICE: If you add new constant, please keep ASCII order.
|
||||
*/
|
||||
const (
|
||||
NotifyChannelBark = "bark"
|
||||
NotifyChannelDingtalk = "dingtalk"
|
||||
NotifyChannelEmail = "email"
|
||||
NotifyChannelLark = "lark"
|
||||
NotifyChannelServerChan = "serverchan"
|
||||
NotifyChannelTelegram = "telegram"
|
||||
NotifyChannelWebhook = "webhook"
|
||||
NotifyChannelWeCom = "wecom"
|
||||
NOTIFY_CHANNEL_BARK = NotifyChannelType("bark")
|
||||
NOTIFY_CHANNEL_DINGTALK = NotifyChannelType("dingtalk")
|
||||
NOTIFY_CHANNEL_EMAIL = NotifyChannelType("email")
|
||||
NOTIFY_CHANNEL_LARK = NotifyChannelType("lark")
|
||||
NOTIFY_CHANNEL_SERVERCHAN = NotifyChannelType("serverchan")
|
||||
NOTIFY_CHANNEL_TELEGRAM = NotifyChannelType("telegram")
|
||||
NOTIFY_CHANNEL_WEBHOOK = NotifyChannelType("webhook")
|
||||
NOTIFY_CHANNEL_WECOM = NotifyChannelType("wecom")
|
||||
)
|
||||
|
||||
type NotifyTestPushReq struct {
|
||||
|
||||
@@ -3,21 +3,18 @@ package domain
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Setting struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Content string `json:"content"`
|
||||
Created time.Time `json:"created"`
|
||||
Updated time.Time `json:"updated"`
|
||||
type Settings struct {
|
||||
Meta
|
||||
Name string `json:"name" db:"name"`
|
||||
Content string `json:"content" db:"content"`
|
||||
}
|
||||
|
||||
type ChannelsConfig map[string]map[string]any
|
||||
type NotifyChannelsConfig map[string]map[string]any
|
||||
|
||||
func (s *Setting) GetChannelContent(channel string) (map[string]any, error) {
|
||||
conf := &ChannelsConfig{}
|
||||
func (s *Settings) GetChannelContent(channel string) (map[string]any, error) {
|
||||
conf := &NotifyChannelsConfig{}
|
||||
if err := json.Unmarshal([]byte(s.Content), conf); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -16,25 +16,25 @@ import (
|
||||
"github.com/usual2970/certimate/internal/pkg/utils/maps"
|
||||
)
|
||||
|
||||
func createNotifier(channel string, channelConfig map[string]any) (notifier.Notifier, error) {
|
||||
func createNotifier(channel domain.NotifyChannelType, channelConfig map[string]any) (notifier.Notifier, error) {
|
||||
/*
|
||||
注意:如果追加新的常量值,请保持以 ASCII 排序。
|
||||
NOTICE: If you add new constant, please keep ASCII order.
|
||||
*/
|
||||
switch channel {
|
||||
case domain.NotifyChannelBark:
|
||||
case domain.NOTIFY_CHANNEL_BARK:
|
||||
return providerBark.New(&providerBark.BarkNotifierConfig{
|
||||
DeviceKey: maps.GetValueAsString(channelConfig, "deviceKey"),
|
||||
ServerUrl: maps.GetValueAsString(channelConfig, "serverUrl"),
|
||||
})
|
||||
|
||||
case domain.NotifyChannelDingtalk:
|
||||
case domain.NOTIFY_CHANNEL_DINGTALK:
|
||||
return providerDingTalk.New(&providerDingTalk.DingTalkNotifierConfig{
|
||||
AccessToken: maps.GetValueAsString(channelConfig, "accessToken"),
|
||||
Secret: maps.GetValueAsString(channelConfig, "secret"),
|
||||
})
|
||||
|
||||
case domain.NotifyChannelEmail:
|
||||
case domain.NOTIFY_CHANNEL_EMAIL:
|
||||
return providerEmail.New(&providerEmail.EmailNotifierConfig{
|
||||
SmtpHost: maps.GetValueAsString(channelConfig, "smtpHost"),
|
||||
SmtpPort: maps.GetValueAsInt32(channelConfig, "smtpPort"),
|
||||
@@ -45,28 +45,28 @@ func createNotifier(channel string, channelConfig map[string]any) (notifier.Noti
|
||||
ReceiverAddress: maps.GetValueAsString(channelConfig, "receiverAddress"),
|
||||
})
|
||||
|
||||
case domain.NotifyChannelLark:
|
||||
case domain.NOTIFY_CHANNEL_LARK:
|
||||
return providerLark.New(&providerLark.LarkNotifierConfig{
|
||||
WebhookUrl: maps.GetValueAsString(channelConfig, "webhookUrl"),
|
||||
})
|
||||
|
||||
case domain.NotifyChannelServerChan:
|
||||
case domain.NOTIFY_CHANNEL_SERVERCHAN:
|
||||
return providerServerChan.New(&providerServerChan.ServerChanNotifierConfig{
|
||||
Url: maps.GetValueAsString(channelConfig, "url"),
|
||||
})
|
||||
|
||||
case domain.NotifyChannelTelegram:
|
||||
case domain.NOTIFY_CHANNEL_TELEGRAM:
|
||||
return providerTelegram.New(&providerTelegram.TelegramNotifierConfig{
|
||||
ApiToken: maps.GetValueAsString(channelConfig, "apiToken"),
|
||||
ChatId: maps.GetValueAsInt64(channelConfig, "chatId"),
|
||||
})
|
||||
|
||||
case domain.NotifyChannelWebhook:
|
||||
case domain.NOTIFY_CHANNEL_WEBHOOK:
|
||||
return providerWebhook.New(&providerWebhook.WebhookNotifierConfig{
|
||||
Url: maps.GetValueAsString(channelConfig, "url"),
|
||||
})
|
||||
|
||||
case domain.NotifyChannelWeCom:
|
||||
case domain.NOTIFY_CHANNEL_WECOM:
|
||||
return providerWeCom.New(&providerWeCom.WeComNotifierConfig{
|
||||
WebhookUrl: maps.GetValueAsString(channelConfig, "webhookUrl"),
|
||||
})
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"golang.org/x/sync/errgroup"
|
||||
|
||||
"github.com/usual2970/certimate/internal/app"
|
||||
"github.com/usual2970/certimate/internal/domain"
|
||||
"github.com/usual2970/certimate/internal/pkg/core/notifier"
|
||||
"github.com/usual2970/certimate/internal/pkg/utils/maps"
|
||||
)
|
||||
@@ -37,7 +38,7 @@ func SendToAllChannels(subject, message string) error {
|
||||
}
|
||||
|
||||
func SendToChannel(subject, message string, channel string, channelConfig map[string]any) error {
|
||||
notifier, err := createNotifier(channel, channelConfig)
|
||||
notifier, err := createNotifier(domain.NotifyChannelType(channel), channelConfig)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -63,7 +64,7 @@ func getEnabledNotifiers() ([]notifier.Notifier, error) {
|
||||
continue
|
||||
}
|
||||
|
||||
notifier, err := createNotifier(k, v)
|
||||
notifier, err := createNotifier(domain.NotifyChannelType(k), v)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ const (
|
||||
)
|
||||
|
||||
type SettingRepository interface {
|
||||
GetByName(ctx context.Context, name string) (*domain.Setting, error)
|
||||
GetByName(ctx context.Context, name string) (*domain.Settings, error)
|
||||
}
|
||||
|
||||
type NotifyService struct {
|
||||
|
||||
@@ -26,9 +26,9 @@ func (a *AccessRepository) GetById(ctx context.Context, id string) (*domain.Acce
|
||||
|
||||
rs := &domain.Access{
|
||||
Meta: domain.Meta{
|
||||
Id: record.GetId(),
|
||||
Created: record.GetTime("created"),
|
||||
Updated: record.GetTime("updated"),
|
||||
Id: record.GetId(),
|
||||
CreatedAt: record.GetTime("created"),
|
||||
UpdatedAt: record.GetTime("updated"),
|
||||
},
|
||||
Name: record.GetString("name"),
|
||||
Config: record.GetString("config"),
|
||||
|
||||
@@ -47,13 +47,15 @@ func (r *AcmeAccountRepository) GetByCAAndEmail(ca, email string) (*domain.AcmeA
|
||||
}
|
||||
|
||||
return &domain.AcmeAccount{
|
||||
Id: record.GetString("id"),
|
||||
Ca: record.GetString("ca"),
|
||||
Meta: domain.Meta{
|
||||
Id: record.GetString("id"),
|
||||
CreatedAt: record.GetTime("created"),
|
||||
UpdatedAt: record.GetTime("updated"),
|
||||
},
|
||||
CA: record.GetString("ca"),
|
||||
Email: record.GetString("email"),
|
||||
Key: record.GetString("key"),
|
||||
Resource: resource,
|
||||
Created: record.GetTime("created"),
|
||||
Updated: record.GetTime("updated"),
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package repository
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/pocketbase/dbx"
|
||||
"github.com/usual2970/certimate/internal/app"
|
||||
"github.com/usual2970/certimate/internal/domain"
|
||||
)
|
||||
@@ -13,18 +14,20 @@ func NewSettingRepository() *SettingRepository {
|
||||
return &SettingRepository{}
|
||||
}
|
||||
|
||||
func (s *SettingRepository) GetByName(ctx context.Context, name string) (*domain.Setting, error) {
|
||||
resp, err := app.GetApp().Dao().FindFirstRecordByFilter("settings", "name='"+name+"'")
|
||||
func (s *SettingRepository) GetByName(ctx context.Context, name string) (*domain.Settings, error) {
|
||||
resp, err := app.GetApp().Dao().FindFirstRecordByFilter("settings", "name={:name}", dbx.Params{"name": name})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
rs := &domain.Setting{
|
||||
ID: resp.GetString("id"),
|
||||
rs := &domain.Settings{
|
||||
Meta: domain.Meta{
|
||||
Id: resp.GetString("id"),
|
||||
CreatedAt: resp.GetTime("created"),
|
||||
UpdatedAt: resp.GetTime("updated"),
|
||||
},
|
||||
Name: resp.GetString("name"),
|
||||
Content: resp.GetString("content"),
|
||||
Created: resp.GetTime("created"),
|
||||
Updated: resp.GetTime("updated"),
|
||||
}
|
||||
|
||||
return rs, nil
|
||||
|
||||
@@ -77,9 +77,9 @@ func record2Workflow(record *models.Record) (*domain.Workflow, error) {
|
||||
|
||||
workflow := &domain.Workflow{
|
||||
Meta: domain.Meta{
|
||||
Id: record.GetId(),
|
||||
Created: record.GetTime("created"),
|
||||
Updated: record.GetTime("updated"),
|
||||
Id: record.GetId(),
|
||||
CreatedAt: record.GetTime("created"),
|
||||
UpdatedAt: record.GetTime("updated"),
|
||||
},
|
||||
Name: record.GetString("name"),
|
||||
Description: record.GetString("description"),
|
||||
|
||||
@@ -42,9 +42,9 @@ func (w *WorkflowOutputRepository) Get(ctx context.Context, nodeId string) (*dom
|
||||
|
||||
rs := &domain.WorkflowOutput{
|
||||
Meta: domain.Meta{
|
||||
Id: record.GetId(),
|
||||
Created: record.GetCreated().Time(),
|
||||
Updated: record.GetUpdated().Time(),
|
||||
Id: record.GetId(),
|
||||
CreatedAt: record.GetCreated().Time(),
|
||||
UpdatedAt: record.GetUpdated().Time(),
|
||||
},
|
||||
Workflow: record.GetString("workflow"),
|
||||
NodeId: record.GetString("nodeId"),
|
||||
@@ -72,20 +72,20 @@ func (w *WorkflowOutputRepository) GetCertificate(ctx context.Context, nodeId st
|
||||
|
||||
rs := &domain.Certificate{
|
||||
Meta: domain.Meta{
|
||||
Id: record.GetId(),
|
||||
Created: record.GetDateTime("created").Time(),
|
||||
Updated: record.GetDateTime("updated").Time(),
|
||||
Id: record.GetId(),
|
||||
CreatedAt: record.GetDateTime("created").Time(),
|
||||
UpdatedAt: record.GetDateTime("updated").Time(),
|
||||
},
|
||||
Certificate: record.GetString("certificate"),
|
||||
PrivateKey: record.GetString("privateKey"),
|
||||
IssuerCertificate: record.GetString("issuerCertificate"),
|
||||
SAN: record.GetString("san"),
|
||||
Output: record.GetString("output"),
|
||||
WorkflowOutputId: record.GetString("output"),
|
||||
ExpireAt: record.GetDateTime("expireAt").Time(),
|
||||
CertUrl: record.GetString("certUrl"),
|
||||
CertStableUrl: record.GetString("certStableUrl"),
|
||||
Workflow: record.GetString("workflow"),
|
||||
NodeId: record.GetString("nodeId"),
|
||||
WorkflowId: record.GetString("workflow"),
|
||||
WorkflowNodeId: record.GetString("nodeId"),
|
||||
}
|
||||
return rs, nil
|
||||
}
|
||||
@@ -132,12 +132,12 @@ func (w *WorkflowOutputRepository) Save(ctx context.Context, output *domain.Work
|
||||
certRecord.Set("privateKey", certificate.PrivateKey)
|
||||
certRecord.Set("issuerCertificate", certificate.IssuerCertificate)
|
||||
certRecord.Set("san", certificate.SAN)
|
||||
certRecord.Set("output", certificate.Output)
|
||||
certRecord.Set("output", certificate.WorkflowOutputId)
|
||||
certRecord.Set("expireAt", certificate.ExpireAt)
|
||||
certRecord.Set("certUrl", certificate.CertUrl)
|
||||
certRecord.Set("certStableUrl", certificate.CertStableUrl)
|
||||
certRecord.Set("workflow", certificate.Workflow)
|
||||
certRecord.Set("nodeId", certificate.NodeId)
|
||||
certRecord.Set("workflow", certificate.WorkflowId)
|
||||
certRecord.Set("nodeId", certificate.WorkflowNodeId)
|
||||
|
||||
if err := app.GetApp().Dao().SaveRecord(certRecord); err != nil {
|
||||
return err
|
||||
|
||||
@@ -103,13 +103,13 @@ func (a *applyNode) Run(ctx context.Context) error {
|
||||
CertUrl: certificate.CertUrl,
|
||||
CertStableUrl: certificate.CertStableUrl,
|
||||
ExpireAt: cert.NotAfter,
|
||||
Workflow: GetWorkflowId(ctx),
|
||||
NodeId: a.node.Id,
|
||||
WorkflowId: GetWorkflowId(ctx),
|
||||
WorkflowNodeId: a.node.Id,
|
||||
}
|
||||
|
||||
if err := a.outputRepo.Save(ctx, output, certificateRecord, func(id string) error {
|
||||
if certificateRecord != nil {
|
||||
certificateRecord.Output = id
|
||||
certificateRecord.WorkflowOutputId = id
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -53,7 +53,7 @@ func (d *deployNode) Run(ctx context.Context) error {
|
||||
// 部署过但是证书更新了,重新部署
|
||||
// 部署过且证书未更新,直接返回
|
||||
|
||||
if d.deployed(output) && cert.Created.Before(output.Updated) {
|
||||
if d.deployed(output) && cert.CreatedAt.Before(output.UpdatedAt) {
|
||||
d.AddOutput(ctx, d.node.Name, "已部署过且证书未更新")
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
)
|
||||
|
||||
type SettingRepository interface {
|
||||
GetByName(ctx context.Context, name string) (*domain.Setting, error)
|
||||
GetByName(ctx context.Context, name string) (*domain.Settings, error)
|
||||
}
|
||||
type notifyNode struct {
|
||||
node *domain.WorkflowNode
|
||||
|
||||
Reference in New Issue
Block a user