From 09e4b24445ca1f0ce8b554b047375ad910f4c19d Mon Sep 17 00:00:00 2001 From: yoan <536464346@qq.com> Date: Thu, 21 Nov 2024 13:17:39 +0800 Subject: [PATCH] certificate display --- internal/domain/workflow_run_log.go | 11 ++ .../workflow/node-processor/apply_node.go | 3 +- .../node-processor/workflow_processor.go | 2 +- internal/workflow/service.go | 11 +- .../certificate/CertificateDetail.tsx | 63 ++++++++ ui/src/components/workflow/WorkflowLog.tsx | 7 +- .../components/workflow/WorkflowLogDetail.tsx | 70 ++++----- ui/src/domain/certificate.ts | 21 +++ ui/src/domain/workflow.ts | 1 - ui/src/lib/time.ts | 8 + ui/src/pages/certificate/index.tsx | 141 ++++++++++++++++++ ui/src/pages/workflow/WorkflowDetail.tsx | 3 +- ui/src/repository/certificate.ts | 28 ++++ ui/src/repository/workflow.ts | 1 - ui/src/router.tsx | 6 + 15 files changed, 331 insertions(+), 45 deletions(-) create mode 100644 ui/src/components/certificate/CertificateDetail.tsx create mode 100644 ui/src/domain/certificate.ts create mode 100644 ui/src/pages/certificate/index.tsx create mode 100644 ui/src/repository/certificate.ts diff --git a/internal/domain/workflow_run_log.go b/internal/domain/workflow_run_log.go index fa77a9c9..91a40963 100644 --- a/internal/domain/workflow_run_log.go +++ b/internal/domain/workflow_run_log.go @@ -20,3 +20,14 @@ type WorkflowRunLog struct { Succeed bool `json:"succeed"` Error string `json:"error"` } + +type RunLogs []RunLog + +func (r RunLogs) Error() string { + for _, log := range r { + if log.Error != "" { + return log.Error + } + } + return "" +} diff --git a/internal/workflow/node-processor/apply_node.go b/internal/workflow/node-processor/apply_node.go index 8411f575..44257d4c 100644 --- a/internal/workflow/node-processor/apply_node.go +++ b/internal/workflow/node-processor/apply_node.go @@ -2,6 +2,7 @@ package nodeprocessor import ( "context" + "strings" "time" "github.com/usual2970/certimate/internal/applicant" @@ -95,7 +96,7 @@ func (a *applyNode) Run(ctx context.Context) error { } certificateRecord := &domain.Certificate{ - SAN: cert.Subject.CommonName, + SAN: strings.Join(cert.DNSNames, ";"), Certificate: certificate.Certificate, PrivateKey: certificate.PrivateKey, IssuerCertificate: certificate.IssuerCertificate, diff --git a/internal/workflow/node-processor/workflow_processor.go b/internal/workflow/node-processor/workflow_processor.go index 4602254f..96cfc7f4 100644 --- a/internal/workflow/node-processor/workflow_processor.go +++ b/internal/workflow/node-processor/workflow_processor.go @@ -33,7 +33,7 @@ func (w *workflowProcessor) runNode(ctx context.Context, node *domain.WorkflowNo if current.Type == domain.WorkflowNodeTypeBranch { for _, branch := range current.Branches { if err := w.runNode(ctx, &branch); err != nil { - continue + return err } } } diff --git a/internal/workflow/service.go b/internal/workflow/service.go index 446381d2..629cd841 100644 --- a/internal/workflow/service.go +++ b/internal/workflow/service.go @@ -57,11 +57,18 @@ func (s *WorkflowService) Run(ctx context.Context, req *domain.WorkflowRunReq) e } // 保存执行日志 - + logs := processor.Log(ctx) + runLogs := domain.RunLogs(logs) + runErr := runLogs.Error() + succeed := true + if runErr != "" { + succeed = false + } log := &domain.WorkflowRunLog{ Workflow: workflow.Id, Log: processor.Log(ctx), - Succeed: true, + Error: runErr, + Succeed: succeed, } if err := s.repo.SaveRunLog(ctx, log); err != nil { app.GetApp().Logger().Error("failed to save run log", "err", err) diff --git a/ui/src/components/certificate/CertificateDetail.tsx b/ui/src/components/certificate/CertificateDetail.tsx new file mode 100644 index 00000000..ff270489 --- /dev/null +++ b/ui/src/components/certificate/CertificateDetail.tsx @@ -0,0 +1,63 @@ +import { Sheet, SheetContent, SheetHeader, SheetTitle } from "../ui/sheet"; + +import { Certificate } from "@/domain/certificate"; +import { Textarea } from "../ui/textarea"; +import { Button } from "../ui/button"; +import { Label } from "../ui/label"; +import { CustomFile, saveFiles2ZIP } from "@/lib/file"; + +type WorkflowLogDetailProps = { + open: boolean; + onOpenChange: (open: boolean) => void; + certificate?: Certificate; +}; +const CertificateDetail = ({ open, onOpenChange, certificate }: WorkflowLogDetailProps) => { + const handleDownloadClick = async () => { + const zipName = `${certificate?.id}-${certificate?.san}.zip`; + const files: CustomFile[] = [ + { + name: `${certificate?.san}.pem`, + content: certificate?.certificate ? certificate?.certificate : "", + }, + { + name: `${certificate?.san}.key`, + content: certificate?.privateKey ? certificate?.privateKey : "", + }, + ]; + + await saveFiles2ZIP(zipName, files); + }; + + return ( + + + + + + +
+
+ +
+
+ +