@cloudbase/cli 1.12.0 → 1.12.1-beta
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/lib/commands/functions/alias/getRoute.js +98 -0
- package/lib/commands/functions/alias/index.js +14 -0
- package/lib/commands/functions/alias/setRoute.js +100 -0
- package/lib/commands/functions/concurrency/delete.js +70 -0
- package/lib/commands/functions/concurrency/index.js +15 -0
- package/lib/commands/functions/concurrency/list.js +81 -0
- package/lib/commands/functions/concurrency/set.js +72 -0
- package/lib/commands/functions/index.js +3 -0
- package/lib/commands/functions/list.js +2 -8
- package/lib/commands/functions/version/index.js +14 -0
- package/lib/commands/functions/version/list.js +96 -0
- package/lib/commands/functions/version/publish.js +70 -0
- package/lib/constant.js +23 -1
- package/lib/function/alias.js +53 -0
- package/lib/function/concurrency.js +69 -0
- package/lib/function/index.js +3 -0
- package/lib/function/version.js +51 -0
- package/package.json +8 -2
- package/src/commands/functions/alias/getRoute.ts +76 -0
- package/src/commands/functions/alias/index.ts +2 -0
- package/src/commands/functions/alias/setRoute.ts +82 -0
- package/src/commands/functions/concurrency/delete.ts +45 -0
- package/src/commands/functions/concurrency/index.ts +3 -0
- package/src/commands/functions/concurrency/list.ts +58 -0
- package/src/commands/functions/concurrency/set.ts +47 -0
- package/src/commands/functions/index.ts +3 -0
- package/src/commands/functions/list.ts +1 -8
- package/src/commands/functions/version/index.ts +2 -0
- package/src/commands/functions/version/list.ts +73 -0
- package/src/commands/functions/version/publish.ts +43 -0
- package/src/constant.ts +24 -0
- package/src/function/alias.ts +43 -0
- package/src/function/concurrency.ts +57 -0
- package/src/function/index.ts +4 -1
- package/src/function/version.ts +39 -0
- package/src/types.ts +95 -0
- package/types/commands/functions/alias/getRoute.d.ts +13 -0
- package/types/commands/functions/alias/index.d.ts +2 -0
- package/types/commands/functions/alias/setRoute.d.ts +13 -0
- package/types/commands/functions/concurrency/delete.d.ts +13 -0
- package/types/commands/functions/concurrency/index.d.ts +3 -0
- package/types/commands/functions/concurrency/list.d.ts +13 -0
- package/types/commands/functions/concurrency/set.d.ts +13 -0
- package/types/commands/functions/index.d.ts +3 -0
- package/types/commands/functions/version/index.d.ts +2 -0
- package/types/commands/functions/version/list.d.ts +13 -0
- package/types/commands/functions/version/publish.d.ts +13 -0
- package/types/constant.d.ts +16 -0
- package/types/function/alias.d.ts +3 -0
- package/types/function/concurrency.d.ts +4 -0
- package/types/function/index.d.ts +3 -0
- package/types/function/version.d.ts +3 -0
- package/types/types.d.ts +82 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
15
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
16
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
17
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
18
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
19
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
20
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.PublishFunctionVersion = void 0;
|
|
25
|
+
const common_1 = require("../../common");
|
|
26
|
+
const utils_1 = require("../../../utils");
|
|
27
|
+
const function_1 = require("../../../function");
|
|
28
|
+
const decorators_1 = require("../../../decorators");
|
|
29
|
+
let PublishFunctionVersion = class PublishFunctionVersion extends common_1.Command {
|
|
30
|
+
get options() {
|
|
31
|
+
return {
|
|
32
|
+
cmd: 'fn',
|
|
33
|
+
childCmd: 'publish-version <name> [description]',
|
|
34
|
+
options: [
|
|
35
|
+
{
|
|
36
|
+
flags: '-e, --envId <envId>',
|
|
37
|
+
desc: '环境 Id'
|
|
38
|
+
}
|
|
39
|
+
],
|
|
40
|
+
desc: '发布函数新版本'
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
execute(ctx, params) {
|
|
44
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
const name = params === null || params === void 0 ? void 0 : params[0];
|
|
46
|
+
const description = params === null || params === void 0 ? void 0 : params[1];
|
|
47
|
+
const { envId } = ctx;
|
|
48
|
+
const loading = (0, utils_1.loadingFactory)();
|
|
49
|
+
loading.start(`发布函数 [${name}] 新版本中...`);
|
|
50
|
+
yield (0, function_1.publishVersion)({
|
|
51
|
+
envId,
|
|
52
|
+
functionName: name,
|
|
53
|
+
description
|
|
54
|
+
});
|
|
55
|
+
loading.succeed(`发布函数 [${name}] 新版本成功!`);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
__decorate([
|
|
60
|
+
(0, decorators_1.InjectParams)(),
|
|
61
|
+
__param(0, (0, decorators_1.CmdContext)()),
|
|
62
|
+
__param(1, (0, decorators_1.ArgsParams)()),
|
|
63
|
+
__metadata("design:type", Function),
|
|
64
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
65
|
+
__metadata("design:returntype", Promise)
|
|
66
|
+
], PublishFunctionVersion.prototype, "execute", null);
|
|
67
|
+
PublishFunctionVersion = __decorate([
|
|
68
|
+
(0, common_1.ICommand)()
|
|
69
|
+
], PublishFunctionVersion);
|
|
70
|
+
exports.PublishFunctionVersion = PublishFunctionVersion;
|
package/lib/constant.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ALL_COMMANDS = exports.STATUS_TEXT = exports.REQUEST_TIMEOUT = exports.DefaultCloudBaseConfig = exports.DefaultFunctionDeployConfig = exports.ConfigItems = void 0;
|
|
3
|
+
exports.ConcurrencyTaskStatus = exports.StatusMap = exports.ALL_COMMANDS = exports.STATUS_TEXT = exports.REQUEST_TIMEOUT = exports.DefaultCloudBaseConfig = exports.DefaultFunctionDeployConfig = exports.ConfigItems = void 0;
|
|
4
4
|
class ConfigItems {
|
|
5
5
|
}
|
|
6
6
|
exports.ConfigItems = ConfigItems;
|
|
@@ -51,6 +51,12 @@ exports.ALL_COMMANDS = [
|
|
|
51
51
|
'fn trigger create',
|
|
52
52
|
'fn trigger delete',
|
|
53
53
|
'fn invoke',
|
|
54
|
+
'fn publish-version',
|
|
55
|
+
'fn list-function-versions',
|
|
56
|
+
'fn put-provisioned-concurrency',
|
|
57
|
+
'fn get-provisioned-concurrency',
|
|
58
|
+
'fn delete-provisioned-concurrency',
|
|
59
|
+
'fn config-route',
|
|
54
60
|
'functions run',
|
|
55
61
|
'storage upload',
|
|
56
62
|
'storage download',
|
|
@@ -77,3 +83,19 @@ exports.ALL_COMMANDS = [
|
|
|
77
83
|
'run standalonegateway turn on',
|
|
78
84
|
'run standalonegateway turn off',
|
|
79
85
|
];
|
|
86
|
+
exports.StatusMap = {
|
|
87
|
+
Active: '部署完成',
|
|
88
|
+
Creating: '创建中',
|
|
89
|
+
CreateFailed: '创建失败',
|
|
90
|
+
Updating: '更新中',
|
|
91
|
+
UpdateFailed: '更新失败',
|
|
92
|
+
Publishing: '函数版本发布中',
|
|
93
|
+
PublishFailed: '函数版本发布失败',
|
|
94
|
+
Deleting: '函数删除中',
|
|
95
|
+
DeleteFailed: '函数删除失败'
|
|
96
|
+
};
|
|
97
|
+
exports.ConcurrencyTaskStatus = {
|
|
98
|
+
Done: '已完成',
|
|
99
|
+
InProgress: '进行中',
|
|
100
|
+
Failed: '失败'
|
|
101
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.getFunctionAliasConfig = exports.setFunctionAliasConfig = void 0;
|
|
13
|
+
const error_1 = require("../error");
|
|
14
|
+
const base_1 = require("./base");
|
|
15
|
+
function setFunctionAliasConfig(options) {
|
|
16
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
const { envId, functionName, name, functionVersion, description, routingConfig } = options;
|
|
18
|
+
const scfService = yield (0, base_1.getFunctionService)(envId);
|
|
19
|
+
try {
|
|
20
|
+
yield scfService.updateFunctionAliasConfig({
|
|
21
|
+
functionName,
|
|
22
|
+
name,
|
|
23
|
+
functionVersion,
|
|
24
|
+
description,
|
|
25
|
+
routingConfig
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
catch (e) {
|
|
29
|
+
throw new error_1.CloudBaseError(`[${functionName}] 设置函数流量配置失败: ${e.message}`, {
|
|
30
|
+
code: e.code
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
exports.setFunctionAliasConfig = setFunctionAliasConfig;
|
|
36
|
+
function getFunctionAliasConfig(options) {
|
|
37
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
+
const { envId, functionName, name } = options;
|
|
39
|
+
const scfService = yield (0, base_1.getFunctionService)(envId);
|
|
40
|
+
try {
|
|
41
|
+
return scfService.getFunctionAlias({
|
|
42
|
+
functionName,
|
|
43
|
+
name
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
catch (e) {
|
|
47
|
+
throw new error_1.CloudBaseError(`[${functionName}] 查询函数别名配置失败: ${e.message}`, {
|
|
48
|
+
code: e.code
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
exports.getFunctionAliasConfig = getFunctionAliasConfig;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.deleteProvisionedConcurrencyConfig = exports.getProvisionedConcurrencyConfig = exports.setProvisionedConcurrencyConfig = void 0;
|
|
13
|
+
const error_1 = require("../error");
|
|
14
|
+
const base_1 = require("./base");
|
|
15
|
+
function setProvisionedConcurrencyConfig(options) {
|
|
16
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
const { envId, functionName, qualifier, versionProvisionedConcurrencyNum } = options;
|
|
18
|
+
const scfService = yield (0, base_1.getFunctionService)(envId);
|
|
19
|
+
try {
|
|
20
|
+
yield scfService.setProvisionedConcurrencyConfig({
|
|
21
|
+
functionName,
|
|
22
|
+
qualifier,
|
|
23
|
+
versionProvisionedConcurrencyNum
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
catch (e) {
|
|
27
|
+
throw new error_1.CloudBaseError(`[${functionName}] 设置函数预置并发失败: ${e.message}`, {
|
|
28
|
+
code: e.code
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
exports.setProvisionedConcurrencyConfig = setProvisionedConcurrencyConfig;
|
|
34
|
+
function getProvisionedConcurrencyConfig(options) {
|
|
35
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
const { envId, functionName, qualifier } = options;
|
|
37
|
+
const scfService = yield (0, base_1.getFunctionService)(envId);
|
|
38
|
+
try {
|
|
39
|
+
return scfService.getProvisionedConcurrencyConfig({
|
|
40
|
+
functionName,
|
|
41
|
+
qualifier,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
catch (e) {
|
|
45
|
+
throw new error_1.CloudBaseError(`[${functionName}] 查看函数预置并发信息失败: ${e.message}`, {
|
|
46
|
+
code: e.code
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
exports.getProvisionedConcurrencyConfig = getProvisionedConcurrencyConfig;
|
|
52
|
+
function deleteProvisionedConcurrencyConfig(options) {
|
|
53
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
const { envId, functionName, qualifier } = options;
|
|
55
|
+
const scfService = yield (0, base_1.getFunctionService)(envId);
|
|
56
|
+
try {
|
|
57
|
+
yield scfService.deleteProvisionedConcurrencyConfig({
|
|
58
|
+
functionName,
|
|
59
|
+
qualifier
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
catch (e) {
|
|
63
|
+
throw new error_1.CloudBaseError(`[${functionName}] 删除函数预置并发失败: ${e.message}`, {
|
|
64
|
+
code: e.code
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
exports.deleteProvisionedConcurrencyConfig = deleteProvisionedConcurrencyConfig;
|
package/lib/function/index.js
CHANGED
|
@@ -18,3 +18,6 @@ __exportStar(require("./delete"), exports);
|
|
|
18
18
|
__exportStar(require("./update"), exports);
|
|
19
19
|
__exportStar(require("./layer"), exports);
|
|
20
20
|
__exportStar(require("./vpc"), exports);
|
|
21
|
+
__exportStar(require("./version"), exports);
|
|
22
|
+
__exportStar(require("./concurrency"), exports);
|
|
23
|
+
__exportStar(require("./alias"), exports);
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.listFunctionVersions = exports.publishVersion = void 0;
|
|
13
|
+
const error_1 = require("../error");
|
|
14
|
+
const base_1 = require("./base");
|
|
15
|
+
function publishVersion(options) {
|
|
16
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
const { envId, functionName, description = '' } = options;
|
|
18
|
+
const scfService = yield (0, base_1.getFunctionService)(envId);
|
|
19
|
+
try {
|
|
20
|
+
yield scfService.publishVersion({
|
|
21
|
+
functionName,
|
|
22
|
+
description
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
catch (e) {
|
|
26
|
+
throw new error_1.CloudBaseError(`[${functionName}] 函数发布新版本失败: ${e.message}`, {
|
|
27
|
+
code: e.code
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
exports.publishVersion = publishVersion;
|
|
33
|
+
function listFunctionVersions(options) {
|
|
34
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
const { envId, functionName, offset = 0, limit = 20 } = options;
|
|
36
|
+
const scfService = yield (0, base_1.getFunctionService)(envId);
|
|
37
|
+
try {
|
|
38
|
+
return scfService.listVersionByFunction({
|
|
39
|
+
functionName,
|
|
40
|
+
offset,
|
|
41
|
+
limit
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
catch (e) {
|
|
45
|
+
throw new error_1.CloudBaseError(`[${functionName}] 查看寒函数版本列表失败: ${e.message}`, {
|
|
46
|
+
code: e.code
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
exports.listFunctionVersions = listFunctionVersions;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudbase/cli",
|
|
3
|
-
"version": "1.12.
|
|
3
|
+
"version": "1.12.1-beta",
|
|
4
4
|
"description": "cli tool for cloudbase",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -21,13 +21,18 @@
|
|
|
21
21
|
"tcb": "bin/tcb.js",
|
|
22
22
|
"cloudbase": "bin/cloudbase.js"
|
|
23
23
|
},
|
|
24
|
+
"husky": {
|
|
25
|
+
"hooks": {
|
|
26
|
+
"pre-commit": "npm run build && git add ."
|
|
27
|
+
}
|
|
28
|
+
},
|
|
24
29
|
"author": "cwuyiqing@gmail.com",
|
|
25
30
|
"license": "ISC",
|
|
26
31
|
"dependencies": {
|
|
27
32
|
"@cloudbase/cloud-api": "^0.4.0",
|
|
28
33
|
"@cloudbase/framework-core": "^1.6.1",
|
|
29
34
|
"@cloudbase/lowcode-cli": "^0.12.2",
|
|
30
|
-
"@cloudbase/manager-node": "3.
|
|
35
|
+
"@cloudbase/manager-node": "3.12.0",
|
|
31
36
|
"@cloudbase/toolbox": "^0.7.2",
|
|
32
37
|
"@sentry/node": "^5.10.2",
|
|
33
38
|
"address": "^1.1.2",
|
|
@@ -67,6 +72,7 @@
|
|
|
67
72
|
"@types/lodash": "^4.14.149",
|
|
68
73
|
"@types/node": "^12.12.38",
|
|
69
74
|
"@types/node-fetch": "^2.5.4",
|
|
75
|
+
"@types/react": "^17.0.37",
|
|
70
76
|
"@types/semver": "^7.3.9",
|
|
71
77
|
"@types/webpack-dev-server": "^3.11.1",
|
|
72
78
|
"@typescript-eslint/eslint-plugin": "^4.8.1",
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
|
|
2
|
+
import { Command, ICommand } from '../../common'
|
|
3
|
+
import { loadingFactory, printHorizontalTable } from '../../../utils'
|
|
4
|
+
import { getFunctionAliasConfig } from '../../../function'
|
|
5
|
+
import { InjectParams, CmdContext, ArgsParams, ArgsOptions } from '../../../decorators'
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
function parseRoutingConfigValue(expression: string) {
|
|
9
|
+
const commaIndex = expression.indexOf(',')
|
|
10
|
+
const valueExpression = expression.substring(commaIndex + 1, expression.length - 1)
|
|
11
|
+
return valueExpression
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
@ICommand()
|
|
15
|
+
export class getFunctionRoutingConfig extends Command {
|
|
16
|
+
get options() {
|
|
17
|
+
return {
|
|
18
|
+
cmd: 'fn',
|
|
19
|
+
childCmd: 'get-route <name>',
|
|
20
|
+
options: [
|
|
21
|
+
{
|
|
22
|
+
flags: '-e, --envId <envId>',
|
|
23
|
+
desc: '环境 Id'
|
|
24
|
+
}
|
|
25
|
+
],
|
|
26
|
+
desc: '查看函数版本流量配置'
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
@InjectParams()
|
|
31
|
+
async execute(@CmdContext() ctx, @ArgsParams() params) {
|
|
32
|
+
const name = params?.[0]
|
|
33
|
+
|
|
34
|
+
const {
|
|
35
|
+
envId
|
|
36
|
+
} = ctx
|
|
37
|
+
|
|
38
|
+
const loading = loadingFactory()
|
|
39
|
+
loading.start(`查询函数 [${name}] 版本流量配置中...`)
|
|
40
|
+
|
|
41
|
+
const aliasRes = await getFunctionAliasConfig({
|
|
42
|
+
envId,
|
|
43
|
+
functionName: name,
|
|
44
|
+
name: '$DEFAULT'
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
const routingConfig = aliasRes?.RoutingConfig?.AddtionVersionMatchs
|
|
48
|
+
let finalConfig = []
|
|
49
|
+
if (routingConfig.length === 1) {
|
|
50
|
+
finalConfig.push({
|
|
51
|
+
version: routingConfig[0].Version,
|
|
52
|
+
value: parseRoutingConfigValue(routingConfig[0].Expression)
|
|
53
|
+
})
|
|
54
|
+
} else if (routingConfig.length === 2) {
|
|
55
|
+
finalConfig.push({
|
|
56
|
+
version: routingConfig[0].Version,
|
|
57
|
+
value: parseRoutingConfigValue(routingConfig[0].Expression)
|
|
58
|
+
}, {
|
|
59
|
+
version: routingConfig[1].Version,
|
|
60
|
+
value: 100 - Number(parseRoutingConfigValue(routingConfig[0].Expression))
|
|
61
|
+
})
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
loading.stop()
|
|
65
|
+
|
|
66
|
+
const head: string[] = ['版本', '流量比例']
|
|
67
|
+
|
|
68
|
+
const tableData = finalConfig.map((item) => [
|
|
69
|
+
item.version,
|
|
70
|
+
item.value
|
|
71
|
+
])
|
|
72
|
+
|
|
73
|
+
printHorizontalTable(head, tableData)
|
|
74
|
+
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
|
|
2
|
+
import { Command, ICommand } from '../../common'
|
|
3
|
+
import { CloudBaseError } from '../../../error'
|
|
4
|
+
import { loadingFactory } from '../../../utils'
|
|
5
|
+
import { setFunctionAliasConfig } from '../../../function'
|
|
6
|
+
import { InjectParams, CmdContext, ArgsParams, ArgsOptions } from '../../../decorators'
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@ICommand()
|
|
10
|
+
export class setFunctionRoutingConfig extends Command {
|
|
11
|
+
get options() {
|
|
12
|
+
return {
|
|
13
|
+
cmd: 'fn',
|
|
14
|
+
childCmd: 'config-route <name> <version1> <traffic1> [version2] [traffic2]',
|
|
15
|
+
options: [
|
|
16
|
+
{
|
|
17
|
+
flags: '-e, --envId <envId>',
|
|
18
|
+
desc: '环境 Id'
|
|
19
|
+
}
|
|
20
|
+
],
|
|
21
|
+
desc: '设置函数版本流量配置'
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
@InjectParams()
|
|
26
|
+
async execute(@CmdContext() ctx, @ArgsParams() params) {
|
|
27
|
+
const name = params?.[0]
|
|
28
|
+
const version1 = params?.[1]
|
|
29
|
+
const traffic1 = Number(params?.[2])
|
|
30
|
+
|
|
31
|
+
const version2 = params?.[3]
|
|
32
|
+
const traffic2 = Number(params?.[4])
|
|
33
|
+
|
|
34
|
+
// 校验
|
|
35
|
+
|
|
36
|
+
// 1. version2 及 traffic2 必须同时存在
|
|
37
|
+
if ((version2 === undefined && traffic2 !== undefined) || (version2 !== undefined && traffic2 === undefined)) {
|
|
38
|
+
throw new CloudBaseError('version2 和 traffic2 必须同时设置')
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (traffic1 !== undefined && traffic2 !== undefined) {
|
|
42
|
+
if (traffic1 + traffic2 !== 100) {
|
|
43
|
+
throw new CloudBaseError('traffic1 和 traffic2 同时设置时,需保证总和 100')
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const {
|
|
48
|
+
envId
|
|
49
|
+
} = ctx
|
|
50
|
+
|
|
51
|
+
const loading = loadingFactory()
|
|
52
|
+
loading.start(`设置函数 [${name}] 版本流量配置中...`)
|
|
53
|
+
|
|
54
|
+
let routingConfigParams = {
|
|
55
|
+
AddtionVersionMatchs: [{
|
|
56
|
+
Expression: `[0,${traffic1})`,
|
|
57
|
+
Key: "invoke.headers.X-Tcb-Route-Key",
|
|
58
|
+
Method: "range",
|
|
59
|
+
Version: version1
|
|
60
|
+
}]
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (version2 !== undefined) {
|
|
64
|
+
routingConfigParams.AddtionVersionMatchs.push({
|
|
65
|
+
Expression: `[${traffic1},${100})`,
|
|
66
|
+
Key: "invoke.headers.X-Tcb-Route-Key",
|
|
67
|
+
Method: "range",
|
|
68
|
+
Version: version2
|
|
69
|
+
})
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
await setFunctionAliasConfig({
|
|
73
|
+
envId,
|
|
74
|
+
functionName: name,
|
|
75
|
+
name: '$DEFAULT',
|
|
76
|
+
functionVersion: '$LATEST',
|
|
77
|
+
routingConfig: routingConfigParams
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
loading.succeed(`设置函数 [${name}] 版本流量配置成功!`)
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
|
|
2
|
+
import { Command, ICommand } from '../../common'
|
|
3
|
+
import { CloudBaseError } from '../../../error'
|
|
4
|
+
import { loadingFactory } from '../../../utils'
|
|
5
|
+
import { deleteProvisionedConcurrencyConfig } from '../../../function'
|
|
6
|
+
import { InjectParams, CmdContext, ArgsParams, ArgsOptions } from '../../../decorators'
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@ICommand()
|
|
10
|
+
export class deleteProvisionedConcurrency extends Command {
|
|
11
|
+
get options() {
|
|
12
|
+
return {
|
|
13
|
+
cmd: 'fn',
|
|
14
|
+
childCmd: 'delete-provisioned-concurrency <name> <version>',
|
|
15
|
+
options: [
|
|
16
|
+
{
|
|
17
|
+
flags: '-e, --envId <envId>',
|
|
18
|
+
desc: '环境 Id'
|
|
19
|
+
}
|
|
20
|
+
],
|
|
21
|
+
desc: '删除函数版本预置并发配置'
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
@InjectParams()
|
|
26
|
+
async execute(@CmdContext() ctx, @ArgsParams() params) {
|
|
27
|
+
const name = params?.[0]
|
|
28
|
+
const version = params?.[1]
|
|
29
|
+
|
|
30
|
+
const {
|
|
31
|
+
envId
|
|
32
|
+
} = ctx
|
|
33
|
+
|
|
34
|
+
const loading = loadingFactory()
|
|
35
|
+
loading.start(`删除函数 [${name}] 预置并发配置中...`)
|
|
36
|
+
|
|
37
|
+
await deleteProvisionedConcurrencyConfig({
|
|
38
|
+
envId,
|
|
39
|
+
functionName: name,
|
|
40
|
+
qualifier: version
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
loading.succeed(`删除函数 [${name}] 预置并发配置成功!`)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
|
|
2
|
+
import { Command, ICommand } from '../../common'
|
|
3
|
+
import { CloudBaseError } from '../../../error'
|
|
4
|
+
import { loadingFactory, printHorizontalTable } from '../../../utils'
|
|
5
|
+
import { getProvisionedConcurrencyConfig } from '../../../function'
|
|
6
|
+
import { InjectParams, CmdContext, ArgsParams, ArgsOptions } from '../../../decorators'
|
|
7
|
+
import { StatusMap, ConcurrencyTaskStatus } from '../../../constant'
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@ICommand()
|
|
11
|
+
export class getProvisionedConcurrency extends Command {
|
|
12
|
+
get options() {
|
|
13
|
+
return {
|
|
14
|
+
cmd: 'fn',
|
|
15
|
+
childCmd: 'get-provisioned-concurrency <name> [version]',
|
|
16
|
+
options: [
|
|
17
|
+
{
|
|
18
|
+
flags: '-e, --envId <envId>',
|
|
19
|
+
desc: '环境 Id'
|
|
20
|
+
}
|
|
21
|
+
],
|
|
22
|
+
desc: '获取函数版本预置并发配置'
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
@InjectParams()
|
|
27
|
+
async execute(@CmdContext() ctx, @ArgsParams() params, @ArgsOptions() options) {
|
|
28
|
+
const name = params?.[0]
|
|
29
|
+
const version = params?.[1]
|
|
30
|
+
|
|
31
|
+
const {
|
|
32
|
+
envId
|
|
33
|
+
} = ctx
|
|
34
|
+
|
|
35
|
+
const loading = loadingFactory()
|
|
36
|
+
loading.start(`拉取函数 [${name}] 预置并发配置中...`)
|
|
37
|
+
|
|
38
|
+
const res = await getProvisionedConcurrencyConfig({
|
|
39
|
+
envId,
|
|
40
|
+
functionName: name,
|
|
41
|
+
qualifier: version
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
loading.stop()
|
|
45
|
+
|
|
46
|
+
const head: string[] = ['设置并发数', '已完成并发数', '预置任务状态', '状态说明', '版本号']
|
|
47
|
+
|
|
48
|
+
const tableData = res.Allocated.map((item) => [
|
|
49
|
+
item.AllocatedProvisionedConcurrencyNum,
|
|
50
|
+
item.AvailableProvisionedConcurrencyNum,
|
|
51
|
+
ConcurrencyTaskStatus[item.Status] || '无',
|
|
52
|
+
item.StatusReason,
|
|
53
|
+
item.Qualifier
|
|
54
|
+
])
|
|
55
|
+
|
|
56
|
+
printHorizontalTable(head, tableData)
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
|
|
2
|
+
import { Command, ICommand } from '../../common'
|
|
3
|
+
import { CloudBaseError } from '../../../error'
|
|
4
|
+
import { loadingFactory } from '../../../utils'
|
|
5
|
+
import { setProvisionedConcurrencyConfig } from '../../../function'
|
|
6
|
+
import { InjectParams, CmdContext, ArgsParams, ArgsOptions } from '../../../decorators'
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@ICommand()
|
|
10
|
+
export class setProvisionedConcurrency extends Command {
|
|
11
|
+
get options() {
|
|
12
|
+
return {
|
|
13
|
+
cmd: 'fn',
|
|
14
|
+
childCmd: 'set-provisioned-concurrency <name> <version> <concurrency>',
|
|
15
|
+
options: [
|
|
16
|
+
{
|
|
17
|
+
flags: '-e, --envId <envId>',
|
|
18
|
+
desc: '环境 Id'
|
|
19
|
+
}
|
|
20
|
+
],
|
|
21
|
+
desc: '设置函数版本预置并发'
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
@InjectParams()
|
|
26
|
+
async execute(@CmdContext() ctx, @ArgsParams() params) {
|
|
27
|
+
const name = params?.[0]
|
|
28
|
+
const version = params?.[1]
|
|
29
|
+
const concurrency = Number(params?.[2] || 0)
|
|
30
|
+
|
|
31
|
+
const {
|
|
32
|
+
envId
|
|
33
|
+
} = ctx
|
|
34
|
+
|
|
35
|
+
const loading = loadingFactory()
|
|
36
|
+
loading.start(`配置函数 [${name}] 预置并发中...`)
|
|
37
|
+
|
|
38
|
+
await setProvisionedConcurrencyConfig({
|
|
39
|
+
envId,
|
|
40
|
+
functionName: name,
|
|
41
|
+
qualifier: version,
|
|
42
|
+
versionProvisionedConcurrencyNum: concurrency
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
loading.succeed(`配置函数 [${name}] 预置并发成功!`)
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -3,14 +3,7 @@ import { CloudBaseError } from '../../error'
|
|
|
3
3
|
import { listFunction } from '../../function'
|
|
4
4
|
import { printHorizontalTable, loadingFactory } from '../../utils'
|
|
5
5
|
import { InjectParams, EnvId, ArgsOptions } from '../../decorators'
|
|
6
|
-
|
|
7
|
-
const StatusMap = {
|
|
8
|
-
Active: '部署完成',
|
|
9
|
-
Creating: '创建中',
|
|
10
|
-
CreateFailed: '创建失败',
|
|
11
|
-
Updating: '更新中',
|
|
12
|
-
UpdateFailed: '更新失败'
|
|
13
|
-
}
|
|
6
|
+
import { StatusMap } from '../../constant'
|
|
14
7
|
|
|
15
8
|
@ICommand()
|
|
16
9
|
export class ListFunction extends Command {
|