mirror of
https://github.com/usual2970/certimate.git
synced 2025-10-05 22:14:53 +00:00
feat: rename access
to providerAccessId
This commit is contained in:
@@ -18,7 +18,6 @@ import (
|
||||
"github.com/go-acme/lego/v4/challenge/dns01"
|
||||
"github.com/go-acme/lego/v4/lego"
|
||||
"github.com/go-acme/lego/v4/registration"
|
||||
"github.com/pocketbase/pocketbase/models"
|
||||
|
||||
"github.com/usual2970/certimate/internal/app"
|
||||
"github.com/usual2970/certimate/internal/domain"
|
||||
@@ -57,12 +56,12 @@ type Certificate struct {
|
||||
}
|
||||
|
||||
type ApplyOption struct {
|
||||
Email string `json:"email"`
|
||||
SubjectAltNames string `json:"subjectAltNames"`
|
||||
Email string `json:"email"`
|
||||
AccessConfig string `json:"accessConfig"`
|
||||
KeyAlgorithm string `json:"keyAlgorithm"`
|
||||
Nameservers string `json:"nameservers"`
|
||||
PropagationTimeout int64 `json:"propagationTimeout"`
|
||||
PropagationTimeout int32 `json:"propagationTimeout"`
|
||||
DisableFollowCNAME bool `json:"disableFollowCNAME"`
|
||||
}
|
||||
|
||||
@@ -125,41 +124,11 @@ type Applicant interface {
|
||||
Apply() (*Certificate, error)
|
||||
}
|
||||
|
||||
func Get(record *models.Record) (Applicant, error) {
|
||||
if record.GetString("applyConfig") == "" {
|
||||
return nil, errors.New("applyConfig is empty")
|
||||
}
|
||||
|
||||
applyConfig := &domain.ApplyConfig{}
|
||||
record.UnmarshalJSONField("applyConfig", applyConfig)
|
||||
|
||||
access, err := app.GetApp().Dao().FindRecordById("access", applyConfig.Access)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("access record not found: %w", err)
|
||||
}
|
||||
|
||||
if applyConfig.Email == "" {
|
||||
applyConfig.Email = defaultEmail
|
||||
}
|
||||
|
||||
option := &ApplyOption{
|
||||
Email: applyConfig.Email,
|
||||
SubjectAltNames: record.GetString("domain"),
|
||||
AccessConfig: access.GetString("config"),
|
||||
KeyAlgorithm: applyConfig.KeyAlgorithm,
|
||||
Nameservers: applyConfig.Nameservers,
|
||||
PropagationTimeout: applyConfig.PropagationTimeout,
|
||||
DisableFollowCNAME: applyConfig.DisableFollowCNAME,
|
||||
}
|
||||
|
||||
return GetWithTypeOption(domain.AccessProviderType(access.GetString("provider")), option)
|
||||
}
|
||||
|
||||
func GetWithApplyNode(node *domain.WorkflowNode) (Applicant, error) {
|
||||
// 获取授权配置
|
||||
accessRepo := repository.NewAccessRepository()
|
||||
|
||||
access, err := accessRepo.GetById(context.Background(), node.GetConfigString("access"))
|
||||
access, err := accessRepo.GetById(context.Background(), node.GetConfigString("providerAccessId"))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("access record not found: %w", err)
|
||||
}
|
||||
@@ -170,7 +139,7 @@ func GetWithApplyNode(node *domain.WorkflowNode) (Applicant, error) {
|
||||
AccessConfig: access.Config,
|
||||
KeyAlgorithm: node.GetConfigString("keyAlgorithm"),
|
||||
Nameservers: node.GetConfigString("nameservers"),
|
||||
PropagationTimeout: node.GetConfigInt64("propagationTimeout"),
|
||||
PropagationTimeout: node.GetConfigInt32("propagationTimeout"),
|
||||
DisableFollowCNAME: node.GetConfigBool("disableFollowCNAME"),
|
||||
}
|
||||
|
||||
|
@@ -49,7 +49,7 @@ const (
|
||||
type DeployerOption struct {
|
||||
DomainId string `json:"domainId"`
|
||||
Domain string `json:"domain"`
|
||||
Access string `json:"access"`
|
||||
AccessConfig string `json:"accessConfig"`
|
||||
AccessRecord *domain.Access `json:"-"`
|
||||
DeployConfig domain.DeployConfig `json:"deployConfig"`
|
||||
Certificate applicant.Certificate `json:"certificate"`
|
||||
@@ -97,7 +97,7 @@ func GetWithTypeAndOption(deployType string, option *DeployerOption) (Deployer,
|
||||
|
||||
func newWithDeployConfig(record *models.Record, cert *applicant.Certificate, deployConfig domain.DeployConfig) (Deployer, error) {
|
||||
accessRepo := repository.NewAccessRepository()
|
||||
access, err := accessRepo.GetById(context.Background(), deployConfig.Access)
|
||||
access, err := accessRepo.GetById(context.Background(), deployConfig.ProviderAccessId)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("获取access失败:%w", err)
|
||||
}
|
||||
@@ -105,7 +105,7 @@ func newWithDeployConfig(record *models.Record, cert *applicant.Certificate, dep
|
||||
option := &DeployerOption{
|
||||
DomainId: record.Id,
|
||||
Domain: record.GetString("domain"),
|
||||
Access: access.Config,
|
||||
AccessConfig: access.Config,
|
||||
AccessRecord: access,
|
||||
DeployConfig: deployConfig,
|
||||
}
|
||||
@@ -118,11 +118,11 @@ func newWithDeployConfig(record *models.Record, cert *applicant.Certificate, dep
|
||||
}
|
||||
}
|
||||
|
||||
return newWithTypeAndOption(deployConfig.Type, option)
|
||||
return newWithTypeAndOption(deployConfig.Provider, option)
|
||||
}
|
||||
|
||||
func newWithTypeAndOption(deployType string, option *DeployerOption) (Deployer, error) {
|
||||
deployer, logger, err := createDeployer(deployType, option.AccessRecord.Config, option.DeployConfig.Config)
|
||||
deployer, logger, err := createDeployer(deployType, option.AccessRecord.Config, option.DeployConfig.NodeConfig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@@ -3,17 +3,17 @@ package domain
|
||||
// Deprecated: TODO: 即将废弃
|
||||
type ApplyConfig struct {
|
||||
Email string `json:"email"`
|
||||
Access string `json:"access"`
|
||||
ProviderAccessId string `json:"providerAccessId"`
|
||||
KeyAlgorithm string `json:"keyAlgorithm"`
|
||||
Nameservers string `json:"nameservers"`
|
||||
PropagationTimeout int64 `json:"propagationTimeout"`
|
||||
PropagationTimeout int32 `json:"propagationTimeout"`
|
||||
DisableFollowCNAME bool `json:"disableFollowCNAME"`
|
||||
}
|
||||
|
||||
// Deprecated: TODO: 即将废弃
|
||||
type DeployConfig struct {
|
||||
Id string `json:"id"`
|
||||
Access string `json:"access"`
|
||||
Type string `json:"type"`
|
||||
Config map[string]any `json:"config"`
|
||||
NodeId string `json:"nodeId"`
|
||||
NodeConfig map[string]any `json:"nodeConfig"`
|
||||
Provider string `json:"provider"`
|
||||
ProviderAccessId string `json:"providerAccessId"`
|
||||
}
|
||||
|
@@ -1,8 +1,7 @@
|
||||
package domain
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"github.com/usual2970/certimate/internal/pkg/utils/maps"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -47,33 +46,19 @@ type WorkflowNode struct {
|
||||
}
|
||||
|
||||
func (n *WorkflowNode) GetConfigString(key string) string {
|
||||
if v, ok := n.Config[key]; ok {
|
||||
if s, ok := v.(string); ok {
|
||||
return s
|
||||
}
|
||||
}
|
||||
return ""
|
||||
return maps.GetValueAsString(n.Config, key)
|
||||
}
|
||||
|
||||
func (n *WorkflowNode) GetConfigBool(key string) bool {
|
||||
if v, ok := n.Config[key]; ok {
|
||||
if b, ok := v.(bool); ok {
|
||||
return b
|
||||
}
|
||||
}
|
||||
return false
|
||||
return maps.GetValueAsBool(n.Config, key)
|
||||
}
|
||||
|
||||
func (n *WorkflowNode) GetConfigInt32(key string) int32 {
|
||||
return maps.GetValueAsInt32(n.Config, key)
|
||||
}
|
||||
|
||||
func (n *WorkflowNode) GetConfigInt64(key string) int64 {
|
||||
// 先转成字符串,再转成 int64
|
||||
if v, ok := n.Config[key]; ok {
|
||||
temp := fmt.Sprintf("%v", v)
|
||||
if i, err := strconv.ParseInt(temp, 10, 64); err == nil {
|
||||
return i
|
||||
}
|
||||
}
|
||||
|
||||
return 0
|
||||
return maps.GetValueAsInt64(n.Config, key)
|
||||
}
|
||||
|
||||
type WorkflowNodeIO struct {
|
||||
|
@@ -54,13 +54,6 @@ func NewWithLogger(config *WebhookDeployerConfig, logger logger.Logger) (*Webhoo
|
||||
}, nil
|
||||
}
|
||||
|
||||
type webhookData struct {
|
||||
SubjectAltNames string `json:"subjectAltNames"`
|
||||
Certificate string `json:"certificate"`
|
||||
PrivateKey string `json:"privateKey"`
|
||||
Variables map[string]string `json:"variables"`
|
||||
}
|
||||
|
||||
func (d *WebhookDeployer) Deploy(ctx context.Context, certPem string, privkeyPem string) (*deployer.DeployResult, error) {
|
||||
certX509, err := x509.ParseCertificateFromPEM(certPem)
|
||||
if err != nil {
|
||||
|
@@ -118,6 +118,12 @@ func GetValueOrDefaultAsInt64(dict map[string]any, key string, defaultValue int6
|
||||
}
|
||||
}
|
||||
|
||||
if result, ok := value.(int32); ok {
|
||||
if result != 0 {
|
||||
return int64(result)
|
||||
}
|
||||
}
|
||||
|
||||
// 兼容字符串类型的值
|
||||
if str, ok := value.(string); ok {
|
||||
if result, err := strconv.ParseInt(str, 10, 64); err == nil {
|
||||
|
@@ -59,15 +59,16 @@ func (d *deployNode) Run(ctx context.Context) error {
|
||||
}
|
||||
|
||||
accessRepo := repository.NewAccessRepository()
|
||||
access, err := accessRepo.GetById(context.Background(), d.node.GetConfigString("access"))
|
||||
access, err := accessRepo.GetById(context.Background(), d.node.GetConfigString("providerAccessId"))
|
||||
if err != nil {
|
||||
d.AddOutput(ctx, d.node.Name, "获取授权配置失败", err.Error())
|
||||
return err
|
||||
}
|
||||
|
||||
option := &deployer.DeployerOption{
|
||||
DomainId: d.node.Id,
|
||||
Domain: cert.SAN,
|
||||
Access: access.Config,
|
||||
AccessConfig: access.Config,
|
||||
AccessRecord: access,
|
||||
Certificate: applicant.Certificate{
|
||||
CertUrl: cert.CertUrl,
|
||||
@@ -77,10 +78,10 @@ func (d *deployNode) Run(ctx context.Context) error {
|
||||
IssuerCertificate: cert.IssuerCertificate,
|
||||
},
|
||||
DeployConfig: domain.DeployConfig{
|
||||
Id: d.node.Id,
|
||||
Access: access.Id,
|
||||
Type: d.node.GetConfigString("provider"),
|
||||
Config: d.node.Config,
|
||||
NodeId: d.node.Id,
|
||||
NodeConfig: d.node.Config,
|
||||
Provider: d.node.GetConfigString("provider"),
|
||||
ProviderAccessId: access.Id,
|
||||
},
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user