From 2085bcceb61c3723c9bdfec4c4cc0917631ff5e5 Mon Sep 17 00:00:00 2001 From: xiaojunnuo Date: Thu, 28 Aug 2025 22:39:11 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20openapi=E8=BF=94=E5=9B=9E=E8=AF=81?= =?UTF-8?q?=E4=B9=A6=E6=97=B6=E6=8C=91=E9=80=89=E5=8C=B9=E9=85=8D=E8=8C=83?= =?UTF-8?q?=E5=9B=B4=E6=9C=80=E5=B0=8F=E7=9A=84=E9=82=A3=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=EF=BC=9B=E5=A2=9E=E5=8A=A0format=E5=8F=82=E6=95=B0=EF=BC=8C?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=BF=94=E5=9B=9E=E5=80=BCp7b=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=EF=BC=8C=E5=A2=9E=E5=8A=A0detail=E8=BF=94=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/plugin/cert-plugin/cert-reader.ts | 22 ++++++++- .../certd-client/src/views/sys/plugin/api.ts | 2 +- .../src/views/sys/plugin/use-config.tsx | 6 +-- .../controller/openapi/v1/cert-controller.ts | 2 + .../monitor/facade/cert-info-facade.ts | 45 ++++++++++++++----- .../monitor/service/cert-info-service.ts | 11 ++++- 6 files changed, 70 insertions(+), 18 deletions(-) diff --git a/packages/plugins/plugin-cert/src/plugin/cert-plugin/cert-reader.ts b/packages/plugins/plugin-cert/src/plugin/cert-plugin/cert-reader.ts index 318aa0c4..df31264f 100644 --- a/packages/plugins/plugin-cert/src/plugin/cert-plugin/cert-reader.ts +++ b/packages/plugins/plugin-cert/src/plugin/cert-plugin/cert-reader.ts @@ -21,6 +21,15 @@ export type CertReaderHandleContext = { }; export type CertReaderHandle = (ctx: CertReaderHandleContext) => Promise; export type HandleOpts = { logger: ILogger; handle: CertReaderHandle }; + +const formats = { + pem: ["crt", "key", "ic"], + one: ["one"], + pfx: ["pfx"], + der: ["der"], + jks: ["jks"], + p7b: ["p7b", "key"], +}; export class CertReader { cert: CertInfo; @@ -74,8 +83,17 @@ export class CertReader { return arr[0] + endStr; } - toCertInfo(): CertInfo { - return this.cert; + toCertInfo(format?: string): CertInfo { + if (!format) { + return this.cert; + } + + const formatArr = formats[format]; + const res: any = {}; + formatArr.forEach((key: string) => { + res[key] = this.cert[key]; + }); + return res; } getCrtDetail(crt: string = this.cert.crt) { diff --git a/packages/ui/certd-client/src/views/sys/plugin/api.ts b/packages/ui/certd-client/src/views/sys/plugin/api.ts index a773fc9b..f51155db 100644 --- a/packages/ui/certd-client/src/views/sys/plugin/api.ts +++ b/packages/ui/certd-client/src/views/sys/plugin/api.ts @@ -119,7 +119,7 @@ export async function SaveCommPluginConfigs(data: CommPluginConfig): Promise { +export async function savePluginSetting(req: { name: string; sysSetting: any }): Promise { return await request({ url: apiPrefix + "/saveSetting", method: "post", diff --git a/packages/ui/certd-client/src/views/sys/plugin/use-config.tsx b/packages/ui/certd-client/src/views/sys/plugin/use-config.tsx index 7fee1abf..1f48cb54 100644 --- a/packages/ui/certd-client/src/views/sys/plugin/use-config.tsx +++ b/packages/ui/certd-client/src/views/sys/plugin/use-config.tsx @@ -1,17 +1,17 @@ import * as api from "/@/views/sys/plugin/api"; import { useFormWrapper } from "@fast-crud/fast-crud"; import { useI18n } from "/@/locales"; -import { Modal, notification } from "ant-design-vue"; +import { notification } from "ant-design-vue"; import ConfigEditor from "./config-editor.vue"; -import { useModal } from "/@/use/use-modal"; import { ref } from "vue"; import { usePluginStore } from "/@/store/plugin"; + export function usePluginConfig() { const { openCrudFormDialog } = useFormWrapper(); const { t } = useI18n(); const pluginStore = usePluginStore(); - const modal = useModal(); + // @ts-ignore async function openConfigDialog({ row, crudExpose }) { const configEditorRef = ref(); function createCrudOptions() { diff --git a/packages/ui/certd-server/src/controller/openapi/v1/cert-controller.ts b/packages/ui/certd-server/src/controller/openapi/v1/cert-controller.ts index da78766d..3a3a5402 100644 --- a/packages/ui/certd-server/src/controller/openapi/v1/cert-controller.ts +++ b/packages/ui/certd-server/src/controller/openapi/v1/cert-controller.ts @@ -10,6 +10,7 @@ export type CertGetReq = { domains?: string; certId: number; autoApply?:boolean; + format?:string; //默认是所有,pem,der,p12,pfx,jks,one,p7b }; /** @@ -38,6 +39,7 @@ export class OpenCertController extends BaseOpenController { domains: req.domains, certId: req.certId, autoApply: req.autoApply??false, + format: req.format }); return this.ok(res); } diff --git a/packages/ui/certd-server/src/modules/monitor/facade/cert-info-facade.ts b/packages/ui/certd-server/src/modules/monitor/facade/cert-info-facade.ts index b571cad4..0c3d8d15 100644 --- a/packages/ui/certd-server/src/modules/monitor/facade/cert-info-facade.ts +++ b/packages/ui/certd-server/src/modules/monitor/facade/cert-info-facade.ts @@ -27,7 +27,7 @@ export class CertInfoFacade { @Inject() userSettingsService : UserSettingsService - async getCertInfo(req: { domains?: string; certId?: number; userId: number,autoApply?:boolean }) { + async getCertInfo(req: { domains?: string; certId?: number; userId: number,autoApply?:boolean,format?:string }) { const { domains, certId, userId } = req; if (certId) { return await this.certInfoService.getCertInfoById({ id: certId, userId }); @@ -41,7 +41,7 @@ export class CertInfoFacade { const domainArr = domains.split(','); const matchedList = await this.certInfoService.getMatchCertList({domains:domainArr,userId}) - let matched: CertInfoEntity = null + if (matchedList.length === 0 ) { if(req.autoApply === true){ //自动申请,先创建自动申请流水线 @@ -54,13 +54,7 @@ export class CertInfoFacade { }); } } - matched = null; - for (const item of matchedList) { - if (item.expiresTime>0 && item.expiresTime > new Date().getTime()) { - matched = item; - break - } - } + let matched = this.getMinixMatched(matchedList); if (!matched) { if(req.autoApply === true){ //如果没有找到有效期内的证书,则自动触发一次申请 @@ -75,7 +69,38 @@ export class CertInfoFacade { } } - return await this.certInfoService.getCertInfoById({ id: matched.id, userId: userId }); + return await this.certInfoService.getCertInfoById({ id: matched.id, userId: userId,format:req.format }); + + + + } + + public getMinixMatched(matchedList: CertInfoEntity[]) { + let matched: CertInfoEntity = null; + for (const item of matchedList) { + if (item.expiresTime > 0 && item.expiresTime > new Date().getTime()) { + if (matched) { + //如果前面已经有match的值,判断范围是否比上一个小 + const currentStars = `-${item.domains}`.split("*"); + const matchedStars = `-${matched.domains}`.split("*"); + + const currentLength = item.domains.split(","); + const matchedLength = matched.domains.split(","); + if (currentStars.length < matchedStars.length) { + //如果*的数量比上一个少,则替换为当前 + matched = item; + } else if (currentStars.length == matchedStars.length) { + //如果*的数量相同,则比较域名数量 + if (currentLength.length < matchedLength.length) { + matched = item; + } + } + } else { + matched = item; + } + } + } + return matched; } async createAutoPipeline(req:{domains:string[],userId:number}){ diff --git a/packages/ui/certd-server/src/modules/monitor/service/cert-info-service.ts b/packages/ui/certd-server/src/modules/monitor/service/cert-info-service.ts index 8129af30..8bb2e8ac 100644 --- a/packages/ui/certd-server/src/modules/monitor/service/cert-info-service.ts +++ b/packages/ui/certd-server/src/modules/monitor/service/cert-info-service.ts @@ -113,7 +113,7 @@ export class CertInfoService extends BaseService { }); } - async getCertInfoById(req: { id: number; userId: number }) { + async getCertInfoById(req: { id: number; userId: number,format?:string }) { const entity = await this.info(req.id); if (!entity || entity.userId !== req.userId) { throw new CodeException(Constants.res.openCertNotFound); @@ -124,7 +124,14 @@ export class CertInfoService extends BaseService { } const certInfo = JSON.parse(entity.certInfo) as CertInfo; const certReader = new CertReader(certInfo); - return certReader.toCertInfo(); + return { + ...certReader.toCertInfo(req.format), + detail: { + id: entity.id, + domains: entity.domains.split(','), + notAfter: certReader.expires, + }, + }; } async updateCertByPipelineId(pipelineId: number, cert: CertInfo,file?:string,fromType = 'pipeline') {