From 42a56b581d754c3e5f9838179d19ab0d004ef2eb Mon Sep 17 00:00:00 2001 From: xiaojunnuo Date: Tue, 27 Aug 2024 13:46:19 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E6=8E=88=E6=9D=83=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=8A=A0=E5=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 原本已经添加的授权配置,再次编辑保存即变成加密配置 --- packages/core/acme-client/src/auto.js | 5 +- packages/core/acme-client/src/crypto/index.js | 1 - packages/core/pipeline/src/access/api.ts | 1 + .../plugin-cert/src/access/eab-access.ts | 2 + .../src/plugin/cert-plugin/acme.ts | 24 +++- .../src/plugin/cert-plugin/index.ts | 4 +- packages/ui/certd-client/package.json | 1 + .../src/components/cron-editor/index.vue | 80 +++++++++++++ .../ui/certd-client/src/components/index.ts | 5 + .../ui/certd-client/src/style/common.less | 7 +- .../views/certd/pipeline/certd-form/crud.tsx | 5 +- .../src/views/certd/pipeline/crud.tsx | 2 +- .../pipeline/component/trigger-form/index.vue | 12 +- .../migration-pg/v10008__access_encrypt.sql | 1 + .../db/migration/v10007__access_text.sql | 0 .../db/migration/v10008__access_encrypt.sql | 2 + .../certd-server/src/config/config.default.ts | 5 +- packages/ui/certd-server/src/config/keys.ts | 31 ----- .../certd-server/src/middleware/authority.ts | 16 ++- .../src/modules/auto/auto-init-site.ts | 18 ++- .../modules/login/service/login-service.ts | 11 +- .../pipeline/controller/access-controller.ts | 12 +- .../src/modules/pipeline/entity/access.ts | 5 +- .../pipeline/service/access-service.ts | 108 ++++++++++++++++-- .../pipeline/service/dns-provider-service.ts | 4 +- .../pipeline/service/encrypt-service.ts | 44 +++++++ .../src/modules/system/service/models.ts | 2 + .../plugin-aliyun/access/aliyun-access.ts | 1 + .../src/plugins/plugin-cloudflare/access.ts | 1 + .../src/plugins/plugin-demo/access.ts | 1 + .../plugins/plugin-host/access/ssh-access.ts | 3 + .../plugin-huawei/access/huawei-access.ts | 1 + .../plugins/plugin-other/access/k8s-access.ts | 1 + .../plugin-tencent/access/dnspod-access.ts | 1 + .../plugin-tencent/access/tencent-access.ts | 1 + 35 files changed, 338 insertions(+), 80 deletions(-) create mode 100644 packages/ui/certd-client/src/components/cron-editor/index.vue create mode 100644 packages/ui/certd-server/db/migration-pg/v10008__access_encrypt.sql create mode 100644 packages/ui/certd-server/db/migration/v10007__access_text.sql create mode 100644 packages/ui/certd-server/db/migration/v10008__access_encrypt.sql delete mode 100644 packages/ui/certd-server/src/config/keys.ts create mode 100644 packages/ui/certd-server/src/modules/pipeline/service/encrypt-service.ts diff --git a/packages/core/acme-client/src/auto.js b/packages/core/acme-client/src/auto.js index ed59fba1..749f7a93 100644 --- a/packages/core/acme-client/src/auto.js +++ b/packages/core/acme-client/src/auto.js @@ -255,9 +255,8 @@ module.exports = async (client, userOpts) => { return await client.getCertificate(finalized, opts.preferredChain); } catch (e) { - log('证书申请失败'); - log(e); - throw new Error(`证书申请失败:${e.message}`); + log(`证书申请失败${e.message}`); + throw e; } finally { log(`清理challenge痕迹,length:${clearTasks.length}`); diff --git a/packages/core/acme-client/src/crypto/index.js b/packages/core/acme-client/src/crypto/index.js index f0c3c367..53599f5d 100644 --- a/packages/core/acme-client/src/crypto/index.js +++ b/packages/core/acme-client/src/crypto/index.js @@ -290,7 +290,6 @@ exports.readCsrDomains = (csrPem) => { if (Buffer.isBuffer(csrPem)) { csrPem = csrPem.toString(); } - const dec = x509.PemConverter.decodeFirst(csrPem); const csr = new x509.Pkcs10CertificateRequest(dec); return parseDomains(csr); diff --git a/packages/core/pipeline/src/access/api.ts b/packages/core/pipeline/src/access/api.ts index 2540bcba..5343b30d 100644 --- a/packages/core/pipeline/src/access/api.ts +++ b/packages/core/pipeline/src/access/api.ts @@ -4,6 +4,7 @@ import { FormItemProps } from "../dt/index.js"; export type AccessInputDefine = FormItemProps & { title: string; required?: boolean; + encrypt?: boolean; }; export type AccessDefine = Registrable & { input?: { diff --git a/packages/plugins/plugin-cert/src/access/eab-access.ts b/packages/plugins/plugin-cert/src/access/eab-access.ts index 6a82097c..241bca1c 100644 --- a/packages/plugins/plugin-cert/src/access/eab-access.ts +++ b/packages/plugins/plugin-cert/src/access/eab-access.ts @@ -13,6 +13,7 @@ export class EabAccess { }, helper: "EAB KID", required: true, + encrypt: true, }) kid = ""; @AccessInput({ @@ -22,6 +23,7 @@ export class EabAccess { }, helper: "EAB HMAC Key", required: true, + encrypt: true, }) hmacKey = ""; } diff --git a/packages/plugins/plugin-cert/src/plugin/cert-plugin/acme.ts b/packages/plugins/plugin-cert/src/plugin/cert-plugin/acme.ts index b941474f..169bed72 100644 --- a/packages/plugins/plugin-cert/src/plugin/cert-plugin/acme.ts +++ b/packages/plugins/plugin-cert/src/plugin/cert-plugin/acme.ts @@ -7,7 +7,7 @@ import { IContext } from "@certd/pipeline"; import { IDnsProvider } from "../../dns-provider/index.js"; import psl from "psl"; import { ClientExternalAccountBindingOptions, UrlMapping } from "@certd/acme-client"; - +import { utils } from "@certd/pipeline"; export type CertInfo = { crt: string; key: string; @@ -90,6 +90,13 @@ export class AcmeService { } if (this.options.useMappingProxy) { urlMapping.enabled = true; + } else { + //测试directory是否可以访问 + const isOk = await this.testDirectory(directoryUrl); + if (!isOk) { + this.logger.info("测试访问失败,自动使用代理"); + urlMapping.enabled = true; + } } const client = new acme.Client({ directoryUrl: directoryUrl, @@ -295,4 +302,19 @@ export class AcmeService { altNames, }; } + + private async testDirectory(directoryUrl: string) { + try { + await utils.http({ + url: directoryUrl, + method: "GET", + timeout: 5000, + }); + } catch (e) { + this.logger.error(`${directoryUrl},测试访问失败`, e); + return false; + } + this.logger.info(`${directoryUrl},测试访问成功`); + return true; + } } diff --git a/packages/plugins/plugin-cert/src/plugin/cert-plugin/index.ts b/packages/plugins/plugin-cert/src/plugin/cert-plugin/index.ts index d9b5d5e0..3fc62c39 100644 --- a/packages/plugins/plugin-cert/src/plugin/cert-plugin/index.ts +++ b/packages/plugins/plugin-cert/src/plugin/cert-plugin/index.ts @@ -80,7 +80,8 @@ export class CertApplyPlugin extends CertApplyBasePlugin { name: "pi-dns-provider-selector", }, required: true, - helper: "请选择dns解析提供商", + helper: + "请选择dns解析提供商,您的域名是在哪里注册的,或者域名的dns解析服务器属于哪个平台\n如果这里没有您的dns解析提供商,您可以将域名解析服务器设置成上面的任意一个提供商", }) dnsProviderType!: string; @@ -108,7 +109,6 @@ export class CertApplyPlugin extends CertApplyBasePlugin { name: "a-switch", vModel: "checked", }, - maybeNeed: true, helper: "如果acme-v02.api.letsencrypt.org或dv.acme-v02.api.pki.goog被墙无法访问,请尝试开启此选项", }) useProxy = false; diff --git a/packages/ui/certd-client/package.json b/packages/ui/certd-client/package.json index 4c7fbaf9..0564f810 100644 --- a/packages/ui/certd-client/package.json +++ b/packages/ui/certd-client/package.json @@ -30,6 +30,7 @@ "@fast-crud/ui-interface": "^1.21.2", "@iconify/vue": "^4.1.1", "@soerenmartius/vue3-clipboard": "^0.1.2", + "@vue-js-cron/light": "^4.0.5", "ant-design-vue": "^4.1.2", "axios": "^1.7.2", "axios-mock-adapter": "^1.22.0", diff --git a/packages/ui/certd-client/src/components/cron-editor/index.vue b/packages/ui/certd-client/src/components/cron-editor/index.vue new file mode 100644 index 00000000..a9ea6236 --- /dev/null +++ b/packages/ui/certd-client/src/components/cron-editor/index.vue @@ -0,0 +1,80 @@ + + + + diff --git a/packages/ui/certd-client/src/components/index.ts b/packages/ui/certd-client/src/components/index.ts index 1a522c5f..07e3fce0 100644 --- a/packages/ui/certd-client/src/components/index.ts +++ b/packages/ui/certd-client/src/components/index.ts @@ -5,6 +5,9 @@ import PiOutputSelector from "../views/certd/pipeline/pipeline/component/output- import PiEditable from "./editable.vue"; import VipButton from "./vip-button/index.vue"; import { CheckCircleOutlined, InfoCircleOutlined, UndoOutlined } from "@ant-design/icons-vue"; +import CronEditor from "./cron-editor/index.vue"; +import { CronLight } from "@vue-js-cron/light"; +import "@vue-js-cron/light/dist/light.css"; export default { install(app: any) { app.component("PiContainer", PiContainer); @@ -13,6 +16,8 @@ export default { app.component("PiOutputSelector", PiOutputSelector); app.component("PiDnsProviderSelector", PiDnsProviderSelector); app.component("VipButton", VipButton); + app.component("CronLight", CronLight); + app.component("CronEditor", CronEditor); app.component("CheckCircleOutlined", CheckCircleOutlined); app.component("InfoCircleOutlined", InfoCircleOutlined); diff --git a/packages/ui/certd-client/src/style/common.less b/packages/ui/certd-client/src/style/common.less index decf1d22..2f78e516 100644 --- a/packages/ui/certd-client/src/style/common.less +++ b/packages/ui/certd-client/src/style/common.less @@ -64,7 +64,9 @@ h1, h2, h3, h4, h5, h6 { flex: 1; } - +.mb-2{ + margin-bottom:2px; +} .ml-5{ margin-left:5px; } @@ -84,6 +86,9 @@ h1, h2, h3, h4, h5, h6 { .mr-15{ margin-right: 15px; } +.mt-5{ + margin-top:5px; +} .mt-10{ margin-top:10px; } diff --git a/packages/ui/certd-client/src/views/certd/pipeline/certd-form/crud.tsx b/packages/ui/certd-client/src/views/certd/pipeline/certd-form/crud.tsx index 77e7f105..57455431 100644 --- a/packages/ui/certd-client/src/views/certd/pipeline/certd-form/crud.tsx +++ b/packages/ui/certd-client/src/views/certd/pipeline/certd-form/crud.tsx @@ -39,7 +39,8 @@ export default function (certPluginGroup: PluginGroup, formWrapperRef: any): Cre form: { wrapper: { width: "1150px", - saveRemind: false + saveRemind: false, + title: "创建证书申请流水线" } }, columns: { @@ -73,6 +74,8 @@ export default function (certPluginGroup: PluginGroup, formWrapperRef: any): Cre type: "text", form: { component: { + name: "cron-editor", + vModel: "modelValue", placeholder: "0 0 4 * * *" }, helper: "请输入cron表达式, 例如:0 0 4 * * *,每天凌晨4点触发", diff --git a/packages/ui/certd-client/src/views/certd/pipeline/crud.tsx b/packages/ui/certd-client/src/views/certd/pipeline/crud.tsx index 27393487..f1127c43 100644 --- a/packages/ui/certd-client/src/views/certd/pipeline/crud.tsx +++ b/packages/ui/certd-client/src/views/certd/pipeline/crud.tsx @@ -112,7 +112,7 @@ export default function ({ crudExpose, context: { certdFormRef } }: CreateCrudOp }, addCertd: { order: 1, - text: "添加证书流水线", + text: "创建证书流水线", type: "primary", click() { addCertdPipeline(); diff --git a/packages/ui/certd-client/src/views/certd/pipeline/pipeline/component/trigger-form/index.vue b/packages/ui/certd-client/src/views/certd/pipeline/pipeline/component/trigger-form/index.vue index eba102b3..99c5bff7 100644 --- a/packages/ui/certd-client/src/views/certd/pipeline/pipeline/component/trigger-form/index.vue +++ b/packages/ui/certd-client/src/views/certd/pipeline/pipeline/component/trigger-form/index.vue @@ -15,13 +15,7 @@