feat: rename domain to subjectAltNames
This commit is contained in:
@@ -54,8 +54,8 @@ type Certificate struct {
|
||||
}
|
||||
|
||||
type ApplyOption struct {
|
||||
Domains string `json:"domains"`
|
||||
ContactEmail string `json:"contactEmail"`
|
||||
SubjectAltNames string `json:"subjectAltNames"`
|
||||
AccessConfig string `json:"accessConfig"`
|
||||
KeyAlgorithm string `json:"keyAlgorithm"`
|
||||
Nameservers string `json:"nameservers"`
|
||||
@@ -132,8 +132,8 @@ func GetWithApplyNode(node *domain.WorkflowNode) (Applicant, error) {
|
||||
}
|
||||
|
||||
applyConfig := &ApplyOption{
|
||||
Domains: node.GetConfigString("domains"),
|
||||
ContactEmail: node.GetConfigString("contactEmail"),
|
||||
SubjectAltNames: node.GetConfigString("subjectAltNames"),
|
||||
AccessConfig: access.Config,
|
||||
KeyAlgorithm: node.GetConfigString("keyAlgorithm"),
|
||||
Nameservers: node.GetConfigString("nameservers"),
|
||||
@@ -243,7 +243,7 @@ func apply(option *ApplyOption, provider challenge.Provider) (*Certificate, erro
|
||||
myUser.Registration = reg
|
||||
}
|
||||
|
||||
domains := strings.Split(option.SubjectAltNames, ";")
|
||||
domains := strings.Split(option.Domains, ";")
|
||||
request := certificate.ObtainRequest{
|
||||
Domains: domains,
|
||||
Bundle: true,
|
||||
|
||||
@@ -83,7 +83,7 @@ func buildMsg(records []domain.Certificate) *domain.NotifyMessage {
|
||||
domains := make([]string, count)
|
||||
|
||||
for i, record := range records {
|
||||
domains[i] = record.SAN
|
||||
domains[i] = record.SubjectAltNames
|
||||
}
|
||||
|
||||
countStr := strconv.Itoa(count)
|
||||
|
||||
@@ -4,13 +4,10 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/pocketbase/pocketbase/models"
|
||||
|
||||
"github.com/usual2970/certimate/internal/applicant"
|
||||
"github.com/usual2970/certimate/internal/domain"
|
||||
"github.com/usual2970/certimate/internal/pkg/core/deployer"
|
||||
"github.com/usual2970/certimate/internal/pkg/core/logger"
|
||||
"github.com/usual2970/certimate/internal/repository"
|
||||
)
|
||||
|
||||
/*
|
||||
@@ -47,8 +44,8 @@ const (
|
||||
)
|
||||
|
||||
type DeployerOption struct {
|
||||
DomainId string `json:"domainId"`
|
||||
Domain string `json:"domain"`
|
||||
NodeId string `json:"nodeId"`
|
||||
Domains string `json:"domains"`
|
||||
AccessConfig string `json:"accessConfig"`
|
||||
AccessRecord *domain.Access `json:"-"`
|
||||
DeployConfig domain.DeployConfig `json:"deployConfig"`
|
||||
@@ -62,66 +59,7 @@ type Deployer interface {
|
||||
GetID() string
|
||||
}
|
||||
|
||||
func Gets(record *models.Record, cert *applicant.Certificate) ([]Deployer, error) {
|
||||
rs := make([]Deployer, 0)
|
||||
if record.GetString("deployConfig") == "" {
|
||||
return rs, nil
|
||||
}
|
||||
|
||||
deployConfigs := make([]domain.DeployConfig, 0)
|
||||
|
||||
err := record.UnmarshalJSONField("deployConfig", &deployConfigs)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("解析部署配置失败: %w", err)
|
||||
}
|
||||
|
||||
if len(deployConfigs) == 0 {
|
||||
return rs, nil
|
||||
}
|
||||
|
||||
for _, deployConfig := range deployConfigs {
|
||||
deployer, err := newWithDeployConfig(record, cert, deployConfig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
rs = append(rs, deployer)
|
||||
}
|
||||
|
||||
return rs, nil
|
||||
}
|
||||
|
||||
func GetWithTypeAndOption(deployType string, option *DeployerOption) (Deployer, error) {
|
||||
return newWithTypeAndOption(deployType, option)
|
||||
}
|
||||
|
||||
func newWithDeployConfig(record *models.Record, cert *applicant.Certificate, deployConfig domain.DeployConfig) (Deployer, error) {
|
||||
accessRepo := repository.NewAccessRepository()
|
||||
access, err := accessRepo.GetById(context.Background(), deployConfig.ProviderAccessId)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("获取access失败:%w", err)
|
||||
}
|
||||
|
||||
option := &DeployerOption{
|
||||
DomainId: record.Id,
|
||||
Domain: record.GetString("domain"),
|
||||
AccessConfig: access.Config,
|
||||
AccessRecord: access,
|
||||
DeployConfig: deployConfig,
|
||||
}
|
||||
if cert != nil {
|
||||
option.Certificate = *cert
|
||||
} else {
|
||||
option.Certificate = applicant.Certificate{
|
||||
Certificate: record.GetString("certificate"),
|
||||
PrivateKey: record.GetString("privateKey"),
|
||||
}
|
||||
}
|
||||
|
||||
return newWithTypeAndOption(deployConfig.Provider, option)
|
||||
}
|
||||
|
||||
func newWithTypeAndOption(deployType string, option *DeployerOption) (Deployer, error) {
|
||||
deployer, logger, err := createDeployer(deployType, option.AccessRecord.Config, option.DeployConfig.NodeConfig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -6,7 +6,7 @@ var ValidityDuration = time.Hour * 24 * 10
|
||||
|
||||
type Certificate struct {
|
||||
Meta
|
||||
SAN string `json:"san" db:"san"`
|
||||
SubjectAltNames string `json:"san" db:"san"`
|
||||
Certificate string `json:"certificate" db:"certificate"`
|
||||
PrivateKey string `json:"privateKey" db:"privateKey"`
|
||||
IssuerCertificate string `json:"issuerCertificate" db:"issuerCertificate"`
|
||||
|
||||
@@ -79,7 +79,7 @@ func (w *WorkflowOutputRepository) GetCertificate(ctx context.Context, nodeId st
|
||||
Certificate: record.GetString("certificate"),
|
||||
PrivateKey: record.GetString("privateKey"),
|
||||
IssuerCertificate: record.GetString("issuerCertificate"),
|
||||
SAN: record.GetString("san"),
|
||||
SubjectAltNames: record.GetString("san"),
|
||||
WorkflowOutputId: record.GetString("output"),
|
||||
ExpireAt: record.GetDateTime("expireAt").Time(),
|
||||
CertUrl: record.GetString("certUrl"),
|
||||
@@ -131,7 +131,7 @@ func (w *WorkflowOutputRepository) Save(ctx context.Context, output *domain.Work
|
||||
certRecord.Set("certificate", certificate.Certificate)
|
||||
certRecord.Set("privateKey", certificate.PrivateKey)
|
||||
certRecord.Set("issuerCertificate", certificate.IssuerCertificate)
|
||||
certRecord.Set("san", certificate.SAN)
|
||||
certRecord.Set("san", certificate.SubjectAltNames)
|
||||
certRecord.Set("output", certificate.WorkflowOutputId)
|
||||
certRecord.Set("expireAt", certificate.ExpireAt)
|
||||
certRecord.Set("certUrl", certificate.CertUrl)
|
||||
|
||||
@@ -96,7 +96,7 @@ func (a *applyNode) Run(ctx context.Context) error {
|
||||
}
|
||||
|
||||
certificateRecord := &domain.Certificate{
|
||||
SAN: strings.Join(cert.DNSNames, ";"),
|
||||
SubjectAltNames: strings.Join(cert.DNSNames, ";"),
|
||||
Certificate: certificate.Certificate,
|
||||
PrivateKey: certificate.PrivateKey,
|
||||
IssuerCertificate: certificate.IssuerCertificate,
|
||||
|
||||
@@ -66,8 +66,8 @@ func (d *deployNode) Run(ctx context.Context) error {
|
||||
}
|
||||
|
||||
option := &deployer.DeployerOption{
|
||||
DomainId: d.node.Id,
|
||||
Domain: cert.SAN,
|
||||
NodeId: d.node.Id,
|
||||
Domains: cert.SubjectAltNames,
|
||||
AccessConfig: access.Config,
|
||||
AccessRecord: access,
|
||||
Certificate: applicant.Certificate{
|
||||
|
||||
Reference in New Issue
Block a user