mirror of
https://github.com/usual2970/certimate.git
synced 2025-06-26 14:19:55 +00:00
fix: couldn't skip certificate not found error
This commit is contained in:
parent
8cf1ffd38b
commit
9c4831fa3f
@ -50,17 +50,14 @@ func (a *applyNode) Run(ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if output != nil && output.Succeeded {
|
if output != nil && output.Succeeded {
|
||||||
cert, err := a.outputRepo.GetCertificateByNodeId(ctx, a.node.Id)
|
lastCertificate, _ := a.outputRepo.GetCertificateByNodeId(ctx, a.node.Id)
|
||||||
if err != nil {
|
if lastCertificate != nil {
|
||||||
a.AddOutput(ctx, a.node.Name, "获取证书失败", err.Error())
|
if time.Until(lastCertificate.ExpireAt) > validityDuration {
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if time.Until(cert.ExpireAt) > validityDuration {
|
|
||||||
a.AddOutput(ctx, a.node.Name, "已申请过证书,且证书在有效期内")
|
a.AddOutput(ctx, a.node.Name, "已申请过证书,且证书在有效期内")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 获取Applicant
|
// 获取Applicant
|
||||||
applicant, err := applicant.GetWithApplyNode(a.node)
|
applicant, err := applicant.GetWithApplyNode(a.node)
|
||||||
@ -70,7 +67,7 @@ func (a *applyNode) Run(ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 申请
|
// 申请
|
||||||
certificate, err := applicant.Apply()
|
applyResult, err := applicant.Apply()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
a.AddOutput(ctx, a.node.Name, "申请失败", err.Error())
|
a.AddOutput(ctx, a.node.Name, "申请失败", err.Error())
|
||||||
return err
|
return err
|
||||||
@ -92,29 +89,29 @@ func (a *applyNode) Run(ctx context.Context) error {
|
|||||||
Outputs: a.node.Outputs,
|
Outputs: a.node.Outputs,
|
||||||
}
|
}
|
||||||
|
|
||||||
certX509, err := x509.ParseCertificateFromPEM(certificate.Certificate)
|
certX509, err := x509.ParseCertificateFromPEM(applyResult.Certificate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
a.AddOutput(ctx, a.node.Name, "解析证书失败", err.Error())
|
a.AddOutput(ctx, a.node.Name, "解析证书失败", err.Error())
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
certificateRecord := &domain.Certificate{
|
certificate := &domain.Certificate{
|
||||||
Source: domain.CertificateSourceTypeWorkflow,
|
Source: domain.CertificateSourceTypeWorkflow,
|
||||||
SubjectAltNames: strings.Join(certX509.DNSNames, ";"),
|
SubjectAltNames: strings.Join(certX509.DNSNames, ";"),
|
||||||
Certificate: certificate.Certificate,
|
Certificate: applyResult.Certificate,
|
||||||
PrivateKey: certificate.PrivateKey,
|
PrivateKey: applyResult.PrivateKey,
|
||||||
IssuerCertificate: certificate.IssuerCertificate,
|
IssuerCertificate: applyResult.IssuerCertificate,
|
||||||
ACMECertUrl: certificate.CertUrl,
|
ACMECertUrl: applyResult.CertUrl,
|
||||||
ACMECertStableUrl: certificate.CertStableUrl,
|
ACMECertStableUrl: applyResult.CertStableUrl,
|
||||||
EffectAt: certX509.NotBefore,
|
EffectAt: certX509.NotBefore,
|
||||||
ExpireAt: certX509.NotAfter,
|
ExpireAt: certX509.NotAfter,
|
||||||
WorkflowId: GetWorkflowId(ctx),
|
WorkflowId: GetWorkflowId(ctx),
|
||||||
WorkflowNodeId: a.node.Id,
|
WorkflowNodeId: a.node.Id,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := a.outputRepo.Save(ctx, output, certificateRecord, func(id string) error {
|
if err := a.outputRepo.Save(ctx, output, certificate, func(id string) error {
|
||||||
if certificateRecord != nil {
|
if certificate != nil {
|
||||||
certificateRecord.WorkflowOutputId = id
|
certificate.WorkflowOutputId = id
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user