From 17a9beb5142a4bb8aa09c8193eb7306e5d335525 Mon Sep 17 00:00:00 2001 From: xiaojunnuo Date: Mon, 30 Sep 2024 18:00:51 +0800 Subject: [PATCH] chore: --- packages/core/pipeline/src/core/handler.ts | 6 +- packages/core/pipeline/src/plugin/api.ts | 22 ++++++- .../core/pipeline/src/utils/util.request.ts | 1 + .../src/plugin/cert-plugin/cert-reader.ts | 7 +++ .../plugins/common/cert-domains-getter.vue | 61 +++++++++++++++++++ .../plugins/common/remote-select.vue | 26 +++++++- .../src/components/plugins/index.ts | 2 + .../src/components/plugins/lib/index.ts | 4 +- .../ui/certd-server/.env.development.yaml | 14 +++++ packages/ui/certd-server/package.json | 2 +- .../pipeline/controller/handle-controller.ts | 13 ++-- .../pipeline/service/access-service.ts | 13 ++-- 12 files changed, 149 insertions(+), 22 deletions(-) create mode 100644 packages/ui/certd-client/src/components/plugins/common/cert-domains-getter.vue diff --git a/packages/core/pipeline/src/core/handler.ts b/packages/core/pipeline/src/core/handler.ts index bd2b39b2..77ff241f 100644 --- a/packages/core/pipeline/src/core/handler.ts +++ b/packages/core/pipeline/src/core/handler.ts @@ -27,7 +27,10 @@ export class AccessRequestHandler { throw new Error("action is required"); } - const methodName = `on${_.upperFirst(req.action)}`; + let methodName = req.action; + if (!req.action.startsWith("on")) { + methodName = `on${_.upperFirst(req.action)}`; + } // @ts-ignore const method = this[methodName]; @@ -38,4 +41,3 @@ export class AccessRequestHandler { throw new Error(`action ${req.action} not found`); } } - diff --git a/packages/core/pipeline/src/plugin/api.ts b/packages/core/pipeline/src/plugin/api.ts index 9ea94a0b..0ea297d0 100644 --- a/packages/core/pipeline/src/plugin/api.ts +++ b/packages/core/pipeline/src/plugin/api.ts @@ -4,7 +4,7 @@ import { FileStore } from "../core/file-store.js"; import { Logger } from "log4js"; import { IAccessService } from "../access/index.js"; import { IEmailService } from "../service/index.js"; -import { IContext, PluginRequestHandleReq } from "../core/index.js"; +import { IContext, PluginRequestHandleReq, RunnableCollection } from "../core/index.js"; import { ILogger, logger, utils } from "../utils/index.js"; import { HttpClient } from "../utils/util.request"; import dayjs from "dayjs"; @@ -165,7 +165,10 @@ export abstract class AbstractTaskPlugin implements ITaskPlugin { throw new Error("action is required"); } - const methodName = `on${_.upperFirst(req.action)}`; + let methodName = req.action; + if (!req.action.startsWith("on")) { + methodName = `on${_.upperFirst(req.action)}`; + } // @ts-ignore const method = this[methodName]; @@ -179,6 +182,21 @@ export abstract class AbstractTaskPlugin implements ITaskPlugin { isAdmin() { return this.ctx.user.role === "admin"; } + + getStepFromPipeline(stepId: string) { + let found: any = null; + RunnableCollection.each(this.ctx.pipeline.stages, (step) => { + if (step.id === stepId) { + found = step; + return; + } + }); + return found; + } + + getStepIdFromRefInput(ref = ".") { + return ref.split(".")[1]; + } } export type OutputVO = { diff --git a/packages/core/pipeline/src/utils/util.request.ts b/packages/core/pipeline/src/utils/util.request.ts index 735eadb2..205fe2ed 100644 --- a/packages/core/pipeline/src/utils/util.request.ts +++ b/packages/core/pipeline/src/utils/util.request.ts @@ -139,6 +139,7 @@ export const http = createAxiosService({ logger }) as HttpClient; export type HttpClientResponse = any; export type HttpRequestConfig = { skipSslVerify?: boolean; + skipCheckRes?: boolean; } & AxiosRequestConfig; export type HttpClient = { request(config: HttpRequestConfig): Promise>; 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 bb6d92bf..d16f6550 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 @@ -65,6 +65,13 @@ export class CertReader { return { detail, expires }; } + getAllDomains() { + const { detail } = this.getCrtDetail(); + const domains = [detail.domains.commonName]; + domains.push(...detail.domains.altNames); + return domains; + } + saveToFile(type: "crt" | "key" | "pfx" | "der" | "ic", filepath?: string) { if (!this.cert[type]) { return; diff --git a/packages/ui/certd-client/src/components/plugins/common/cert-domains-getter.vue b/packages/ui/certd-client/src/components/plugins/common/cert-domains-getter.vue new file mode 100644 index 00000000..fa27feaa --- /dev/null +++ b/packages/ui/certd-client/src/components/plugins/common/cert-domains-getter.vue @@ -0,0 +1,61 @@ + + + + + diff --git a/packages/ui/certd-client/src/components/plugins/common/remote-select.vue b/packages/ui/certd-client/src/components/plugins/common/remote-select.vue index 071f3bc7..6634e09a 100644 --- a/packages/ui/certd-client/src/components/plugins/common/remote-select.vue +++ b/packages/ui/certd-client/src/components/plugins/common/remote-select.vue @@ -22,6 +22,19 @@ const getOptions = async () => { }); }; +const filterOption = (input: string, option: any) => { + return option.label.toLowerCase().indexOf(input.toLowerCase()) >= 0 || String(option.value).toLowerCase().indexOf(input.toLowerCase()); +}; + +let isFirst = true; +async function onClick() { + if (!isFirst) { + return; + } + isFirst = false; + optionsRef.value = await getOptions(); +} + watch( () => { const values = []; @@ -35,13 +48,20 @@ watch( }, async () => { optionsRef.value = await getOptions(); - }, - { immediate: true } + } ); diff --git a/packages/ui/certd-client/src/components/plugins/index.ts b/packages/ui/certd-client/src/components/plugins/index.ts index e093a786..104d3dae 100644 --- a/packages/ui/certd-client/src/components/plugins/index.ts +++ b/packages/ui/certd-client/src/components/plugins/index.ts @@ -1,8 +1,10 @@ import SynologyIdDeviceGetter from "./synology/device-id-getter.vue"; import RemoteSelect from "./common/remote-select.vue"; +import CertDomainsGetter from "./common/cert-domains-getter.vue"; export default { install(app: any) { app.component("SynologyDeviceIdGetter", SynologyIdDeviceGetter); app.component("RemoteSelect", RemoteSelect); + app.component("CertDomainsGetter", CertDomainsGetter); } }; diff --git a/packages/ui/certd-client/src/components/plugins/lib/index.ts b/packages/ui/certd-client/src/components/plugins/lib/index.ts index 1a5b2ad5..5b6c4759 100644 --- a/packages/ui/certd-client/src/components/plugins/lib/index.ts +++ b/packages/ui/certd-client/src/components/plugins/lib/index.ts @@ -7,10 +7,10 @@ export type ComponentPropsType = { value?: any; }; export type RequestHandleReq = { - type: strin; + type: string; typeName: string; action: string; - data: any; + data?: any; input: T; }; diff --git a/packages/ui/certd-server/.env.development.yaml b/packages/ui/certd-server/.env.development.yaml index 992ae443..ca3756b3 100644 --- a/packages/ui/certd-server/.env.development.yaml +++ b/packages/ui/certd-server/.env.development.yaml @@ -4,6 +4,20 @@ # server: # baseUrl: 'http://127.0.0.1:11007' +#flyway: +# scriptDir: './db/migration-pg' + +#typeorm: +# dataSource: +# default: +# type: postgres +# host: localhost +# port: 5433 +# username: postgres +# password: root +# database: postgres + + plus: server: baseUrls: ['https://api.ai.handsfree.work', 'https://api.ai.docmirror.cn'] diff --git a/packages/ui/certd-server/package.json b/packages/ui/certd-server/package.json index 1e05d7d9..85db04a6 100644 --- a/packages/ui/certd-server/package.json +++ b/packages/ui/certd-server/package.json @@ -16,7 +16,7 @@ "build": "mwtsc --cleanOutDir --skipLibCheck", "build-on-docker": "node ./before-build.js && npm run build", "up-mw-deps": "npx midway-version -u -w", - "heap": "clinic heapprofiler -- node ./bootstrap.js", + "heap": "clinic heapprofiler -- node ./bootstrap.js", "flame": "clinic flame -- node ./bootstrap.js" }, "dependencies": { diff --git a/packages/ui/certd-server/src/modules/pipeline/controller/handle-controller.ts b/packages/ui/certd-server/src/modules/pipeline/controller/handle-controller.ts index 7f91920a..2aff4601 100644 --- a/packages/ui/certd-server/src/modules/pipeline/controller/handle-controller.ts +++ b/packages/ui/certd-server/src/modules/pipeline/controller/handle-controller.ts @@ -37,22 +37,19 @@ export class HandleController extends BaseController { //@ts-ignore const access = new accessCls(); - let isNew = true; + let inputAccess = body.input.access; if (body.input.id > 0) { const oldEntity = await this.accessService.info(body.input.id); - if (!oldEntity) { - isNew = false; - const param = { + if (oldEntity) { + const param: any = { type: body.typeName, setting: JSON.stringify(body.input.access), }; this.accessService.encryptSetting(param, oldEntity); - body.input.access = JSON.parse(param.setting); + inputAccess = this.accessService.decryptAccessEntity(param); } } - if (isNew) { - mergeUtils.merge(access, body.input.access); - } + mergeUtils.merge(access, inputAccess); const ctx: AccessRequestHandleContext = { http: http, diff --git a/packages/ui/certd-server/src/modules/pipeline/service/access-service.ts b/packages/ui/certd-server/src/modules/pipeline/service/access-service.ts index 36ba8060..7c11a154 100644 --- a/packages/ui/certd-server/src/modules/pipeline/service/access-service.ts +++ b/packages/ui/certd-server/src/modules/pipeline/service/access-service.ts @@ -108,6 +108,14 @@ export class AccessService extends BaseService implements IAccessS throw new Error(`该授权配置不存在,请确认是否已被删除:id=${id}`); } // const access = accessRegistry.get(entity.type); + const setting = this.decryptAccessEntity(entity); + return { + id: entity.id, + ...setting, + }; + } + + decryptAccessEntity(entity: AccessEntity): any { let setting = {}; if (entity.encryptSetting && entity.encryptSetting !== '{}') { setting = JSON.parse(entity.encryptSetting); @@ -123,10 +131,7 @@ export class AccessService extends BaseService implements IAccessS } else if (entity.setting) { setting = JSON.parse(entity.setting); } - return { - id: entity.id, - ...setting, - }; + return setting; } getDefineList() {