mirror of
https://github.com/usual2970/certimate.git
synced 2025-07-25 23:08:34 +00:00
feat: rename san
to subjectAltNames
, workflow
to workflowId
, nodeId
to workflowNodeId
, output
to workflowOutputId
, log
to logs
, succeed
to succeeded
This commit is contained in:
@@ -17,6 +17,8 @@ type applyNode struct {
|
||||
*Logger
|
||||
}
|
||||
|
||||
var validityDuration = time.Hour * 24 * 10
|
||||
|
||||
func NewApplyNode(node *domain.WorkflowNode) *applyNode {
|
||||
return &applyNode{
|
||||
node: node,
|
||||
@@ -46,14 +48,14 @@ func (a *applyNode) Run(ctx context.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if output != nil && output.Succeed {
|
||||
if output != nil && output.Succeeded {
|
||||
cert, err := a.outputRepo.GetCertificate(ctx, a.node.Id)
|
||||
if err != nil {
|
||||
a.AddOutput(ctx, a.node.Name, "获取证书失败", err.Error())
|
||||
return err
|
||||
}
|
||||
|
||||
if time.Until(cert.ExpireAt) > domain.ValidityDuration {
|
||||
if time.Until(cert.ExpireAt) > validityDuration {
|
||||
a.AddOutput(ctx, a.node.Name, "已申请过证书,且证书在有效期内")
|
||||
return nil
|
||||
}
|
||||
@@ -81,28 +83,30 @@ func (a *applyNode) Run(ctx context.Context) error {
|
||||
outputId = output.Id
|
||||
}
|
||||
output = &domain.WorkflowOutput{
|
||||
Workflow: GetWorkflowId(ctx),
|
||||
NodeId: a.node.Id,
|
||||
Node: a.node,
|
||||
Succeed: true,
|
||||
Output: a.node.Output,
|
||||
Meta: domain.Meta{Id: outputId},
|
||||
Meta: domain.Meta{Id: outputId},
|
||||
WorkflowId: GetWorkflowId(ctx),
|
||||
NodeId: a.node.Id,
|
||||
Node: a.node,
|
||||
Succeeded: true,
|
||||
Outputs: a.node.Output,
|
||||
}
|
||||
|
||||
cert, err := x509.ParseCertificateFromPEM(certificate.Certificate)
|
||||
certX509, err := x509.ParseCertificateFromPEM(certificate.Certificate)
|
||||
if err != nil {
|
||||
a.AddOutput(ctx, a.node.Name, "解析证书失败", err.Error())
|
||||
return err
|
||||
}
|
||||
|
||||
certificateRecord := &domain.Certificate{
|
||||
SubjectAltNames: strings.Join(cert.DNSNames, ";"),
|
||||
Source: string(domain.CERTIFICATE_SOURCE_WORKFLOW),
|
||||
SubjectAltNames: strings.Join(certX509.DNSNames, ";"),
|
||||
Certificate: certificate.Certificate,
|
||||
PrivateKey: certificate.PrivateKey,
|
||||
IssuerCertificate: certificate.IssuerCertificate,
|
||||
CertUrl: certificate.CertUrl,
|
||||
CertStableUrl: certificate.CertStableUrl,
|
||||
ExpireAt: cert.NotAfter,
|
||||
AcmeCertUrl: certificate.CertUrl,
|
||||
AcmeCertStableUrl: certificate.CertStableUrl,
|
||||
EffectAt: certX509.NotBefore,
|
||||
ExpireAt: certX509.NotAfter,
|
||||
WorkflowId: GetWorkflowId(ctx),
|
||||
WorkflowNodeId: a.node.Id,
|
||||
}
|
||||
|
@@ -71,8 +71,8 @@ func (d *deployNode) Run(ctx context.Context) error {
|
||||
AccessConfig: access.Config,
|
||||
AccessRecord: access,
|
||||
Certificate: applicant.Certificate{
|
||||
CertUrl: cert.CertUrl,
|
||||
CertStableUrl: cert.CertStableUrl,
|
||||
CertUrl: cert.AcmeCertUrl,
|
||||
CertStableUrl: cert.AcmeCertStableUrl,
|
||||
PrivateKey: cert.PrivateKey,
|
||||
Certificate: cert.Certificate,
|
||||
IssuerCertificate: cert.IssuerCertificate,
|
||||
@@ -105,11 +105,11 @@ func (d *deployNode) Run(ctx context.Context) error {
|
||||
outputId = output.Id
|
||||
}
|
||||
output = &domain.WorkflowOutput{
|
||||
Workflow: GetWorkflowId(ctx),
|
||||
NodeId: d.node.Id,
|
||||
Node: d.node,
|
||||
Succeed: true,
|
||||
Meta: domain.Meta{Id: outputId},
|
||||
Meta: domain.Meta{Id: outputId},
|
||||
WorkflowId: GetWorkflowId(ctx),
|
||||
NodeId: d.node.Id,
|
||||
Node: d.node,
|
||||
Succeeded: true,
|
||||
}
|
||||
|
||||
if err := d.outputRepo.Save(ctx, output, nil, nil); err != nil {
|
||||
@@ -123,5 +123,5 @@ func (d *deployNode) Run(ctx context.Context) error {
|
||||
}
|
||||
|
||||
func (d *deployNode) deployed(output *domain.WorkflowOutput) bool {
|
||||
return output != nil && output.Succeed
|
||||
return output != nil && output.Succeeded
|
||||
}
|
||||
|
@@ -21,6 +21,7 @@ type Logger struct {
|
||||
func NewLogger(node *domain.WorkflowNode) *Logger {
|
||||
return &Logger{
|
||||
log: &domain.RunLog{
|
||||
NodeId: node.Id,
|
||||
NodeName: node.Name,
|
||||
Outputs: make([]domain.RunLogOutput, 0),
|
||||
},
|
||||
|
Reference in New Issue
Block a user