@cnbcool/cnb-api-generate 2.21.4 → 2.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/client/index.ts +4 -0
- package/client/utils/apply-ssl-no-verify.ts +52 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -91,6 +91,7 @@ npx csg
|
|
|
91
91
|
- `CNB_API_ENDPOINT`:可选,自定义 API 地址(默认 `https://api.cnb.cool`)
|
|
92
92
|
- `CNB_TOKEN`:OpenAPI 令牌
|
|
93
93
|
- `CNB_WEB_ENDPOINT`:与 `CNB_API_ENDPOINT` 对应的根域名(默认 `https://cnb.cool`)
|
|
94
|
+
- `CNB_SSL_NO_VERIFY`:设为 `true` 时跳过 HTTPS 证书校验,适用于自签证书或私有化部署;仅作用于 cnb 自身请求,`git` 的 clone/push 需另配 `http.sslVerify=false`
|
|
94
95
|
|
|
95
96
|
## skills list 命令
|
|
96
97
|
|
package/client/index.ts
CHANGED
|
@@ -8,6 +8,10 @@ import { registerLoginCommand } from './lib/login';
|
|
|
8
8
|
import { registerLogoutCommand } from './lib/logout';
|
|
9
9
|
import { registerStatusCommand } from './lib/status';
|
|
10
10
|
import { registerGitCredentialCommand } from './lib/git-credential';
|
|
11
|
+
import { applySslNoVerify } from './utils/apply-ssl-no-verify';
|
|
12
|
+
|
|
13
|
+
// 证书校验开关必须在任何网络请求之前生效
|
|
14
|
+
applySslNoVerify();
|
|
11
15
|
|
|
12
16
|
// ============================================================
|
|
13
17
|
// Commander 程序定义
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CNB_SSL_NO_VERIFY=true 时跳过 HTTPS 证书校验(自签证书 / 内网私有化部署场景)。
|
|
3
|
+
*
|
|
4
|
+
* 做法是设置 NODE_TLS_REJECT_UNAUTHORIZED='0':Node 自带的 fetch(undici)、
|
|
5
|
+
* https 模块以及 Git 调用的所有 TLS 连接都会遵循它。
|
|
6
|
+
* 未设置、为其它值或读取异常时一律不跳过校验,保持安全默认。
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const INSECURE_WARNING = 'insecure';
|
|
10
|
+
let inited = false;
|
|
11
|
+
|
|
12
|
+
/** 环境变量是否要求跳过证书校验(仅 'true' 视为开启,大小写不敏感) */
|
|
13
|
+
export function isSslNoVerifyEnabled(
|
|
14
|
+
env: NodeJS.ProcessEnv = process.env,
|
|
15
|
+
): boolean {
|
|
16
|
+
try {
|
|
17
|
+
return String(env?.CNB_SSL_NO_VERIFY ?? '').trim().toLowerCase() === 'true';
|
|
18
|
+
} catch {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Node 在 NODE_TLS_REJECT_UNAUTHORIZED='0' 下会给出一条全局 insecure 警告,
|
|
25
|
+
* 用户显式开启时这条警告只是噪音,过滤掉它,其余警告照常输出。
|
|
26
|
+
*/
|
|
27
|
+
function muteInsecureWarning() {
|
|
28
|
+
const origin = process.emitWarning;
|
|
29
|
+
if (typeof origin !== 'function') return;
|
|
30
|
+
process.emitWarning = function emitWarning(warning: any, ...rest: any[]) {
|
|
31
|
+
try {
|
|
32
|
+
const text = typeof warning === 'string' ? warning : warning?.message || '';
|
|
33
|
+
const type = typeof rest[0] === 'string' ? rest[0] : rest[0]?.type || warning?.name || '';
|
|
34
|
+
const name = String(warning?.name || type || '');
|
|
35
|
+
if (/NODE_TLS_REJECT_UNAUTHORIZED/.test(text) || name.toLowerCase().includes(INSECURE_WARNING)) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
} catch {
|
|
39
|
+
// 判断失败就按普通警告处理
|
|
40
|
+
}
|
|
41
|
+
return origin.call(process, warning, ...rest);
|
|
42
|
+
} as typeof process.emitWarning;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** 在进程启动时调用一次;先于任何网络请求生效 */
|
|
46
|
+
export function applySslNoVerify() {
|
|
47
|
+
if (inited) return;
|
|
48
|
+
inited = true;
|
|
49
|
+
if (!isSslNoVerifyEnabled()) return;
|
|
50
|
+
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
|
|
51
|
+
muteInsecureWarning();
|
|
52
|
+
}
|