From 526c48450bcd37b3ccded9b448f17de8140bdc6e Mon Sep 17 00:00:00 2001 From: xiaojunnuo Date: Sat, 26 Oct 2024 23:24:26 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=90=AF=E5=8A=A8?= =?UTF-8?q?=E6=97=B6=E8=87=AA=E7=AD=BE=E8=AF=81=E4=B9=A6=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E4=BF=9D=E5=AD=98=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core/acme-client/src/agents.js | 13 +++---------- packages/core/basic/src/utils/util.request.ts | 19 ++++++++----------- .../src/views/sys/settings/index.vue | 1 + .../modules/auto/https/self-certificate.ts | 9 +++++++++ 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/packages/core/acme-client/src/agents.js b/packages/core/acme-client/src/agents.js index ca182059..ab536d98 100644 --- a/packages/core/acme-client/src/agents.js +++ b/packages/core/acme-client/src/agents.js @@ -8,7 +8,7 @@ function createAgent(opts = {}) { let httpAgent; let httpsAgent; - const httpProxy = process.env.HTTP_PROXY || process.env.http_proxy; + const httpProxy = opts.httpProxy || process.env.HTTP_PROXY || process.env.http_proxy; if (httpProxy) { log(`acme use httpProxy:${httpProxy}`); httpAgent = new HttpProxyAgent(httpProxy, opts); @@ -16,7 +16,7 @@ function createAgent(opts = {}) { else { httpAgent = new nodeHttp.Agent(opts); } - const httpsProxy = process.env.HTTPS_PROXY || process.env.https_proxy; + const httpsProxy = opts.httpsProxy || process.env.HTTPS_PROXY || process.env.https_proxy; if (httpsProxy) { log(`acme use httpsProxy:${httpsProxy}`); httpsAgent = new HttpsProxyAgent(httpsProxy, opts); @@ -38,14 +38,7 @@ function getGlobalAgents() { function setGlobalProxy(opts) { log('acme setGlobalProxy:', opts); - if (opts.httpProxy) { - process.env.HTTP_PROXY = opts.httpProxy; - } - if (opts.httpsProxy) { - process.env.HTTPS_PROXY = opts.httpsProxy; - } - - defaultAgents = createAgent(); + defaultAgents = createAgent(opts); } class HttpError extends Error { diff --git a/packages/core/basic/src/utils/util.request.ts b/packages/core/basic/src/utils/util.request.ts index 9810e7f7..227bfbfb 100644 --- a/packages/core/basic/src/utils/util.request.ts +++ b/packages/core/basic/src/utils/util.request.ts @@ -61,14 +61,7 @@ let defaultAgents = createAgent(); export function setGlobalProxy(opts: { httpProxy?: string; httpsProxy?: string }) { logger.info('setGlobalProxy:', opts); - if (opts.httpProxy) { - process.env.HTTP_PROXY = opts.httpProxy; - } - if (opts.httpsProxy) { - process.env.HTTPS_PROXY = opts.httpsProxy; - } - - defaultAgents = createAgent(); + defaultAgents = createAgent(opts); } export function getGlobalAgents() { @@ -192,9 +185,13 @@ export type HttpClient = { request(config: HttpRequestConfig): Promise>; }; -export function createAgent(opts: nodeHttp.AgentOptions = {}) { +export type CreateAgentOptions = { + httpProxy?: string; + httpsProxy?: string; +} & nodeHttp.AgentOptions; +export function createAgent(opts: CreateAgentOptions = {}) { let httpAgent, httpsAgent; - const httpProxy = process.env.HTTP_PROXY || process.env.http_proxy; + const httpProxy = opts.httpProxy || process.env.HTTP_PROXY || process.env.http_proxy; if (httpProxy) { logger.info('use httpProxy:', httpProxy); httpAgent = new HttpProxyAgent(httpProxy, opts as any); @@ -202,7 +199,7 @@ export function createAgent(opts: nodeHttp.AgentOptions = {}) { } else { httpAgent = new nodeHttp.Agent(opts); } - const httpsProxy = process.env.HTTPS_PROXY || process.env.https_proxy; + const httpsProxy = opts.httpsProxy || process.env.HTTPS_PROXY || process.env.https_proxy; if (httpsProxy) { logger.info('use httpsProxy:', httpsProxy); httpsAgent = new HttpsProxyAgent(httpsProxy, opts as any); diff --git a/packages/ui/certd-client/src/views/sys/settings/index.vue b/packages/ui/certd-client/src/views/sys/settings/index.vue index 144af2e6..f7cddd96 100644 --- a/packages/ui/certd-client/src/views/sys/settings/index.vue +++ b/packages/ui/certd-client/src/views/sys/settings/index.vue @@ -57,6 +57,7 @@ defineOptions({ const formState = reactive>({ public: { registerEnabled: false, + limitUserPipelineCount: 10, managerOtherUserPipeline: false, icpNo: "" }, diff --git a/packages/ui/certd-server/src/modules/auto/https/self-certificate.ts b/packages/ui/certd-server/src/modules/auto/https/self-certificate.ts index 038f6e1b..c2d93e55 100644 --- a/packages/ui/certd-server/src/modules/auto/https/self-certificate.ts +++ b/packages/ui/certd-server/src/modules/auto/https/self-certificate.ts @@ -2,6 +2,7 @@ import { logger } from '@certd/pipeline'; import fs from 'fs'; // @ts-ignore import forge from 'node-forge'; +import path from 'path'; export function createSelfCertificate(opts: { crtPath: string; keyPath: string }) { // 生成密钥对 @@ -32,6 +33,14 @@ export function createSelfCertificate(opts: { crtPath: string; keyPath: string } logger.info('生成自签名证书成功'); logger.info(`自签证书保存路径: ${opts.crtPath}`); logger.info(`自签私钥保存路径: ${opts.keyPath}`); + const crtDir = path.dirname(opts.crtPath); + if (!fs.existsSync(crtDir)) { + fs.mkdirSync(crtDir, { recursive: true }); + } + const keyDir = path.dirname(opts.keyPath); + if (!fs.existsSync(keyDir)) { + fs.mkdirSync(keyDir, { recursive: true }); + } fs.writeFileSync(opts.crtPath, pemCert); fs.writeFileSync(opts.keyPath, pemKey);