edgeone-cli 1.0.13 → 1.0.14
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/dist/api/client.js +1 -210
- package/dist/commands/config.js +1 -312
- package/dist/commands/edgeone.js +1 -414
- package/dist/constants/index.js +1 -60
- package/dist/index.js +1 -37
- package/dist/repl/config-menu.js +1 -264
- package/dist/repl/index.js +1 -95
- package/dist/repl/prefetch-menu.js +1 -192
- package/dist/repl/purge-menu.js +1 -228
- package/dist/repl/ui.js +1 -29
- package/dist/repl/zone-menu.js +1 -219
- package/dist/types/index.js +1 -5
- package/dist/utils/crypto.js +1 -85
- package/dist/utils/date.js +1 -52
- package/dist/utils/display.js +1 -72
- package/dist/utils/signature.js +1 -49
- package/package.json +1 -1
package/dist/utils/display.js
CHANGED
|
@@ -1,72 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* 遮罩字符串(用于隐藏敏感信息)
|
|
3
|
-
* @param str 原始字符串
|
|
4
|
-
* @param showLength 开头和结尾显示的字符数
|
|
5
|
-
* @returns 遮罩后的字符串
|
|
6
|
-
*/
|
|
7
|
-
export function maskString(str, showLength = 4) {
|
|
8
|
-
if (!str)
|
|
9
|
-
return "N/A";
|
|
10
|
-
if (str.length <= showLength * 2)
|
|
11
|
-
return str;
|
|
12
|
-
return str.slice(0, showLength) + "****" + str.slice(-showLength);
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* 截断过长的文本
|
|
16
|
-
* @param text 原始文本
|
|
17
|
-
* @param maxLength 最大长度
|
|
18
|
-
* @returns 截断后的文本
|
|
19
|
-
*/
|
|
20
|
-
export function truncateText(text, maxLength) {
|
|
21
|
-
if (!text)
|
|
22
|
-
return "";
|
|
23
|
-
if (text.length <= maxLength)
|
|
24
|
-
return text;
|
|
25
|
-
return text.slice(0, maxLength - 3) + "...";
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* 创建标准化的表格配置
|
|
29
|
-
* @param heads 表头数组
|
|
30
|
-
* @param colWidths 列宽数组
|
|
31
|
-
* @returns cli-table3 配置对象
|
|
32
|
-
*/
|
|
33
|
-
export function createTableConfig(heads, colWidths) {
|
|
34
|
-
return {
|
|
35
|
-
head: heads,
|
|
36
|
-
colWidths: colWidths,
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* 获取任务状态的显示符号
|
|
41
|
-
* @param status 任务状态
|
|
42
|
-
* @returns 状态符号字符串
|
|
43
|
-
*/
|
|
44
|
-
export function getStatusSymbol(status) {
|
|
45
|
-
switch (status) {
|
|
46
|
-
case "success":
|
|
47
|
-
return "✓";
|
|
48
|
-
case "processing":
|
|
49
|
-
case "pending":
|
|
50
|
-
return "⏳";
|
|
51
|
-
case "failed":
|
|
52
|
-
default:
|
|
53
|
-
return "✗";
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* 获取任务类型的中文名称
|
|
58
|
-
* @param type 任务类型
|
|
59
|
-
* @returns 中文名称
|
|
60
|
-
*/
|
|
61
|
-
export function getPurgeTypeName(type) {
|
|
62
|
-
switch (type) {
|
|
63
|
-
case "purge_url":
|
|
64
|
-
return "URL";
|
|
65
|
-
case "purge_prefix":
|
|
66
|
-
return "目录";
|
|
67
|
-
case "purge_all":
|
|
68
|
-
return "全部";
|
|
69
|
-
default:
|
|
70
|
-
return type;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
1
|
+
export function maskString(str,showLength=4){return str?str.length<=2*showLength?str:str.slice(0,showLength)+"****"+str.slice(-showLength):"N/A"}export function truncateText(text,maxLength){return text?text.length<=maxLength?text:text.slice(0,maxLength-3)+"...":""}export function createTableConfig(heads,colWidths){return{head:heads,colWidths}}export function getStatusSymbol(status){switch(status){case"success":return"✓";case"processing":case"pending":return"⏳";default:return"✗"}}export function getPurgeTypeName(type){switch(type){case"purge_url":return"URL";case"purge_prefix":return"目录";case"purge_all":return"全部";default:return type}}
|
package/dist/utils/signature.js
CHANGED
|
@@ -1,49 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* TC3-HMAC-SHA256 签名工具
|
|
3
|
-
*/
|
|
4
|
-
import crypto from 'crypto';
|
|
5
|
-
/**
|
|
6
|
-
* 计算 TC3-HMAC-SHA256 签名
|
|
7
|
-
*/
|
|
8
|
-
export function calculateSignature(options) {
|
|
9
|
-
const { secretId, secretKey, endpoint, action, requestBody, timestamp } = options;
|
|
10
|
-
// 确保 endpoint 有效,防止 Invalid URL 错误
|
|
11
|
-
const validEndpoint = endpoint || "teo.tencentcloudapi.com";
|
|
12
|
-
const host = new URL(`https://${validEndpoint}`).host;
|
|
13
|
-
// 第一步:拼接规范请求串 CanonicalRequest
|
|
14
|
-
const HTTPRequestMethod = 'POST';
|
|
15
|
-
const CanonicalURI = '/';
|
|
16
|
-
const CanonicalQueryString = '';
|
|
17
|
-
// CanonicalHeaders 按照小写 key 的 ASCII 升序排列
|
|
18
|
-
const CanonicalHeaders = `content-type:application/json; charset=utf-8\n` +
|
|
19
|
-
`host:${host}\n` +
|
|
20
|
-
`x-tc-action:${action.toLowerCase()}\n`;
|
|
21
|
-
const SignedHeaders = 'content-type;host;x-tc-action';
|
|
22
|
-
const HashedRequestPayload = crypto.createHash('sha256').update(requestBody).digest('hex').toLowerCase();
|
|
23
|
-
const CanonicalRequest = HTTPRequestMethod + '\n' +
|
|
24
|
-
CanonicalURI + '\n' +
|
|
25
|
-
CanonicalQueryString + '\n' +
|
|
26
|
-
CanonicalHeaders + '\n' +
|
|
27
|
-
SignedHeaders + '\n' +
|
|
28
|
-
HashedRequestPayload;
|
|
29
|
-
// 第二步:拼接待签名字符串 StringToSign
|
|
30
|
-
const Algorithm = 'TC3-HMAC-SHA256';
|
|
31
|
-
// 将时间戳转换为 UTC 日期格式 YYYY-MM-DD
|
|
32
|
-
const dateStr = new Date(parseInt(timestamp) * 1000).toISOString().slice(0, 10);
|
|
33
|
-
const CredentialScope = `${dateStr}/teo/tc3_request`;
|
|
34
|
-
const HashedCanonicalRequest = crypto.createHash('sha256').update(CanonicalRequest).digest('hex').toLowerCase();
|
|
35
|
-
const StringToSign = Algorithm + '\n' +
|
|
36
|
-
timestamp + '\n' +
|
|
37
|
-
CredentialScope + '\n' +
|
|
38
|
-
HashedCanonicalRequest;
|
|
39
|
-
// 第三步:计算签名 Signature
|
|
40
|
-
// 派生签名密钥
|
|
41
|
-
const secretDate = crypto.createHmac('sha256', 'TC3' + secretKey).update(dateStr).digest();
|
|
42
|
-
const secretService = crypto.createHmac('sha256', secretDate).update('teo').digest();
|
|
43
|
-
const secretSigning = crypto.createHmac('sha256', secretService).update('tc3_request').digest();
|
|
44
|
-
// 计算签名
|
|
45
|
-
const signature = crypto.createHmac('sha256', secretSigning).update(StringToSign).digest('hex');
|
|
46
|
-
// 第四步:拼接 Authorization 值
|
|
47
|
-
const authorization = `${Algorithm} Credential=${secretId}/${CredentialScope}, SignedHeaders=${SignedHeaders}, Signature=${signature}`;
|
|
48
|
-
return authorization;
|
|
49
|
-
}
|
|
1
|
+
import crypto from"crypto";export function calculateSignature(options){const{secretId,secretKey,endpoint,action,requestBody,timestamp}=options,CanonicalRequest="POST\n/\n\n"+`content-type:application/json; charset=utf-8\nhost:${new URL(`https://${endpoint||"teo.tencentcloudapi.com"}`).host}\nx-tc-action:${action.toLowerCase()}\n`+"\ncontent-type;host;x-tc-action\n"+crypto.createHash("sha256").update(requestBody).digest("hex").toLowerCase(),dateStr=new Date(1e3*parseInt(timestamp)).toISOString().slice(0,10),CredentialScope=`${dateStr}/teo/tc3_request`,StringToSign="TC3-HMAC-SHA256\n"+timestamp+"\n"+CredentialScope+"\n"+crypto.createHash("sha256").update(CanonicalRequest).digest("hex").toLowerCase(),secretDate=crypto.createHmac("sha256","TC3"+secretKey).update(dateStr).digest(),secretService=crypto.createHmac("sha256",secretDate).update("teo").digest(),secretSigning=crypto.createHmac("sha256",secretService).update("tc3_request").digest();return`TC3-HMAC-SHA256 Credential=${secretId}/${CredentialScope}, SignedHeaders=content-type;host;x-tc-action, Signature=${crypto.createHmac("sha256",secretSigning).update(StringToSign).digest("hex")}`}
|