@cloudbase/manager-node 4.11.0-alpha.8 → 5.0.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/.claude/settings.local.json +9 -0
- package/jest.config.js +1 -0
- package/lib/agent/index.js +3 -3
- package/lib/cloudApp/index.js +243 -0
- package/lib/cloudApp/types.js +10 -0
- package/lib/cloudrun/index.js +28 -28
- package/lib/env/index.js +92 -0
- package/lib/environment.js +5 -0
- package/lib/index.js +25 -0
- package/lib/interfaces/cloudApp.interface.js +20 -0
- package/lib/interfaces/index.js +1 -0
- package/lib/permission/index.js +4 -7
- package/package.json +2 -2
- package/types/agent/index.d.ts +3 -3
- package/types/agent/type.d.ts +2 -2
- package/types/cloudApp/index.d.ts +73 -0
- package/types/cloudApp/types.d.ts +325 -0
- package/types/cloudrun/index.d.ts +2 -2
- package/types/cloudrun/type.d.ts +5 -3
- package/types/env/index.d.ts +39 -1
- package/types/env/type.d.ts +187 -0
- package/types/environment.d.ts +3 -0
- package/types/index.d.ts +20 -0
- package/types/interfaces/cloudApp.interface.d.ts +4 -0
- package/types/interfaces/index.d.ts +1 -0
- package/types/permission/types.d.ts +1 -1
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
{
|
|
2
|
+
"permissions": {
|
|
3
|
+
"allow": [
|
|
4
|
+
"Bash(TCB_BASE_URL=https://tcb.pre.tencentcloudapi.woa.com npm test -- --testPathPattern=cloudApp 2>&1)",
|
|
5
|
+
"Bash(TCB_BASE_URL=https://tcb.pre.tencentcloudapi.woa.com npm test 2>&1)",
|
|
6
|
+
"Bash(TCB_BASE_URL=https://tcb.pre.tencentcloudapi.woa.com npm test -- --testPathPattern=cloudApp --testNamePattern=\"获取版本列表\")"
|
|
7
|
+
]
|
|
8
|
+
}
|
|
9
|
+
}
|
package/jest.config.js
CHANGED
|
@@ -10,6 +10,7 @@ module.exports = {
|
|
|
10
10
|
},
|
|
11
11
|
transformIgnorePatterns: ['node_modules'],
|
|
12
12
|
testEnvironment: 'node',
|
|
13
|
+
forceExit: true,
|
|
13
14
|
// https://github.com/facebook/jest/issues/5164
|
|
14
15
|
globalSetup: './test/global-setup-hook.ts',
|
|
15
16
|
// globalTeardown: './test/global-teardown-hook.js',
|
package/lib/agent/index.js
CHANGED
|
@@ -28,14 +28,14 @@ class AgentService {
|
|
|
28
28
|
}
|
|
29
29
|
// ==================== SCF 云函数部署 ====================
|
|
30
30
|
/**
|
|
31
|
-
* 创建
|
|
31
|
+
* 创建 Agent
|
|
32
32
|
* 支持两种方式:
|
|
33
33
|
* 1. 传入 cwd 代码目录,自动打包上传
|
|
34
34
|
* 2. 传入 ZipFile / CosBucketRegion + TempCosObjectName,直接上传
|
|
35
35
|
* @param params 创建参数
|
|
36
36
|
* @returns Agent 创建结果
|
|
37
37
|
*/
|
|
38
|
-
async
|
|
38
|
+
async createAgent(params) {
|
|
39
39
|
const envConfig = this.environment.lazyEnvironmentConfig;
|
|
40
40
|
// 默认会话配置
|
|
41
41
|
const defaultSessionConfig = {
|
|
@@ -622,7 +622,7 @@ class AgentService {
|
|
|
622
622
|
exports.AgentService = AgentService;
|
|
623
623
|
__decorate([
|
|
624
624
|
(0, utils_1.preLazy)()
|
|
625
|
-
], AgentService.prototype, "
|
|
625
|
+
], AgentService.prototype, "createAgent", null);
|
|
626
626
|
__decorate([
|
|
627
627
|
(0, utils_1.preLazy)()
|
|
628
628
|
], AgentService.prototype, "describeAgentList", null);
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
14
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
15
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
16
|
+
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;
|
|
17
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
18
|
+
};
|
|
19
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
20
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
21
|
+
};
|
|
22
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.CloudAppService = void 0;
|
|
27
|
+
const fs_1 = __importDefault(require("fs"));
|
|
28
|
+
const os_1 = __importDefault(require("os"));
|
|
29
|
+
const path_1 = __importDefault(require("path"));
|
|
30
|
+
const error_1 = require("../error");
|
|
31
|
+
const utils_1 = require("../utils");
|
|
32
|
+
const http_request_1 = require("../utils/http-request");
|
|
33
|
+
__exportStar(require("./types"), exports);
|
|
34
|
+
/**
|
|
35
|
+
* CloudApp 统一部署服务
|
|
36
|
+
* 提供 Web 应用的创建、查询、删除、版本管理等功能
|
|
37
|
+
*/
|
|
38
|
+
class CloudAppService {
|
|
39
|
+
constructor(environment) {
|
|
40
|
+
this.environment = environment;
|
|
41
|
+
this.tcbService = new utils_1.CloudService(environment.cloudBaseContext, 'tcb', '2018-06-08');
|
|
42
|
+
}
|
|
43
|
+
// =========== 应用管理 API ===========
|
|
44
|
+
/**
|
|
45
|
+
* 创建/更新 CloudApp 应用
|
|
46
|
+
* @param params 创建参数
|
|
47
|
+
*/
|
|
48
|
+
async createApp(params) {
|
|
49
|
+
const { envId } = this.getEnvInfo();
|
|
50
|
+
this.validateRequiredParams(params, ['serviceName', 'deployType']);
|
|
51
|
+
return this.tcbService.request('CreateCloudApp', (0, utils_1.upperCaseObjKey)(Object.assign(Object.assign({}, params), { envId: params.envId || envId })));
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* 获取 CloudApp 应用列表
|
|
55
|
+
* @param params 查询参数
|
|
56
|
+
*/
|
|
57
|
+
async describeAppList(params) {
|
|
58
|
+
const { envId } = this.getEnvInfo();
|
|
59
|
+
return this.tcbService.request('DescribeCloudAppList', (0, utils_1.upperCaseObjKey)(Object.assign(Object.assign({}, params), { envId: params.envId || envId })));
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* 获取 CloudApp 应用详情
|
|
63
|
+
* @param params 查询参数
|
|
64
|
+
*/
|
|
65
|
+
async describeAppInfo(params) {
|
|
66
|
+
const { envId } = this.getEnvInfo();
|
|
67
|
+
this.validateRequiredParams(params, ['serviceName', 'deployType']);
|
|
68
|
+
return this.tcbService.request('DescribeCloudAppInfo', (0, utils_1.upperCaseObjKey)(Object.assign(Object.assign({}, params), { envId: params.envId || envId })));
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* 删除 CloudApp 应用
|
|
72
|
+
* @param params 删除参数
|
|
73
|
+
*/
|
|
74
|
+
async deleteApp(params) {
|
|
75
|
+
const { envId } = this.getEnvInfo();
|
|
76
|
+
this.validateRequiredParams(params, ['serviceName', 'deployType']);
|
|
77
|
+
return this.tcbService.request('DeleteCloudApp', (0, utils_1.upperCaseObjKey)(Object.assign(Object.assign({}, params), { envId: params.envId || envId })));
|
|
78
|
+
}
|
|
79
|
+
// =========== 版本管理 API ===========
|
|
80
|
+
/**
|
|
81
|
+
* 获取 CloudApp 版本详情
|
|
82
|
+
* 不指定 versionName 或 buildId 时返回最新版本
|
|
83
|
+
* @param params 查询参数
|
|
84
|
+
*/
|
|
85
|
+
async describeAppVersion(params) {
|
|
86
|
+
const { envId } = this.getEnvInfo();
|
|
87
|
+
this.validateRequiredParams(params, ['serviceName', 'deployType']);
|
|
88
|
+
return this.tcbService.request('DescribeCloudAppVersion', (0, utils_1.upperCaseObjKey)(Object.assign(Object.assign({}, params), { envId: params.envId || envId })));
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* 获取 CloudApp 版本列表
|
|
92
|
+
* @param params 查询参数
|
|
93
|
+
*/
|
|
94
|
+
async describeAppVersionList(params) {
|
|
95
|
+
const { envId } = this.getEnvInfo();
|
|
96
|
+
this.validateRequiredParams(params, ['serviceName', 'deployType']);
|
|
97
|
+
return this.tcbService.request('DescribeCloudAppVersionList', (0, utils_1.upperCaseObjKey)(Object.assign(Object.assign({}, params), { envId: params.envId || envId })));
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* 删除 CloudApp 版本
|
|
101
|
+
* @param params 删除参数
|
|
102
|
+
*/
|
|
103
|
+
async deleteAppVersion(params) {
|
|
104
|
+
const { envId } = this.getEnvInfo();
|
|
105
|
+
this.validateRequiredParams(params, ['serviceName', 'deployType', 'versionName']);
|
|
106
|
+
return this.tcbService.request('DeleteCloudAppVersion', (0, utils_1.upperCaseObjKey)(Object.assign(Object.assign({}, params), { envId: params.envId || envId })));
|
|
107
|
+
}
|
|
108
|
+
// =========== COS 上传相关 API ===========
|
|
109
|
+
/**
|
|
110
|
+
* 获取 CloudApp COS 上传信息(预签名 URL)
|
|
111
|
+
* @param params 查询参数
|
|
112
|
+
*/
|
|
113
|
+
async describeCosInfo(params) {
|
|
114
|
+
const { envId } = this.getEnvInfo();
|
|
115
|
+
this.validateRequiredParams(params, ['serviceName', 'deployType']);
|
|
116
|
+
return this.tcbService.request('DescribeCloudAppCosInfo', (0, utils_1.upperCaseObjKey)(Object.assign(Object.assign({}, params), { envId: params.envId || envId, suffix: params.suffix || '.zip' })));
|
|
117
|
+
}
|
|
118
|
+
// =========== 辅助方法 ===========
|
|
119
|
+
/**
|
|
120
|
+
* 上传本地代码到 COS
|
|
121
|
+
* 自动打包 ZIP 并上传到预签名 URL
|
|
122
|
+
*
|
|
123
|
+
* 注意:此方法不依赖应用是否已创建,可在创建应用前调用
|
|
124
|
+
* 返回的 cosTimestamp 用于 createApp 时传入 staticConfig.cosTimestamp
|
|
125
|
+
*
|
|
126
|
+
* @param params 上传参数
|
|
127
|
+
*/
|
|
128
|
+
async uploadCode(params) {
|
|
129
|
+
const { serviceName, localPath, ignore = [] } = params;
|
|
130
|
+
// 1. 验证本地路径
|
|
131
|
+
if (!fs_1.default.existsSync(localPath)) {
|
|
132
|
+
throw new error_1.CloudBaseError(`本地路径不存在: ${localPath}`);
|
|
133
|
+
}
|
|
134
|
+
const stat = fs_1.default.statSync(localPath);
|
|
135
|
+
if (!stat.isDirectory()) {
|
|
136
|
+
throw new error_1.CloudBaseError(`localPath 必须是目录: ${localPath}`);
|
|
137
|
+
}
|
|
138
|
+
// 2. 打包本地文件为 ZIP
|
|
139
|
+
const tmpZipPath = path_1.default.join(os_1.default.tmpdir(), `cloudapp-${Date.now()}-${Math.random().toString(36).slice(2)}.zip`);
|
|
140
|
+
const defaultIgnore = ['node_modules/**', '.git/**', '.DS_Store', '**/.DS_Store'];
|
|
141
|
+
await (0, utils_1.compressToZip)({
|
|
142
|
+
dirPath: localPath,
|
|
143
|
+
outputPath: tmpZipPath,
|
|
144
|
+
ignore: [...defaultIgnore, ...ignore]
|
|
145
|
+
});
|
|
146
|
+
try {
|
|
147
|
+
// 3. 获取上传凭证
|
|
148
|
+
const cosInfo = await this.describeCosInfo({
|
|
149
|
+
deployType: params.deployType,
|
|
150
|
+
serviceName,
|
|
151
|
+
suffix: '.zip'
|
|
152
|
+
});
|
|
153
|
+
// 4. 读取 ZIP 文件
|
|
154
|
+
const zipBuffer = fs_1.default.readFileSync(tmpZipPath);
|
|
155
|
+
// 5. 构建请求头
|
|
156
|
+
const headers = {
|
|
157
|
+
'Content-Type': 'application/zip'
|
|
158
|
+
};
|
|
159
|
+
if (cosInfo.UploadHeaders && cosInfo.UploadHeaders.length > 0) {
|
|
160
|
+
for (const h of cosInfo.UploadHeaders) {
|
|
161
|
+
headers[h.Key] = h.Value;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
// 6. 使用预签名 URL 上传
|
|
165
|
+
const response = await (0, http_request_1.fetchStream)(cosInfo.UploadUrl, {
|
|
166
|
+
method: 'PUT',
|
|
167
|
+
body: zipBuffer,
|
|
168
|
+
headers
|
|
169
|
+
});
|
|
170
|
+
if (!response.ok) {
|
|
171
|
+
let errorDetail = '';
|
|
172
|
+
try {
|
|
173
|
+
const responseText = await response.text();
|
|
174
|
+
errorDetail = responseText ? ` - ${responseText.substring(0, 500)}` : '';
|
|
175
|
+
}
|
|
176
|
+
catch (_a) {
|
|
177
|
+
// 解析失败时 errorDetail 保持空串,不影响主错误抛出
|
|
178
|
+
}
|
|
179
|
+
throw new error_1.CloudBaseError(`上传失败: ${response.status} ${response.statusText}${errorDetail}`);
|
|
180
|
+
}
|
|
181
|
+
// 7. 返回结果(返回 cosTimestamp,用于创建应用)
|
|
182
|
+
return {
|
|
183
|
+
cosTimestamp: cosInfo.UnixTimestamp,
|
|
184
|
+
unixTimestamp: cosInfo.UnixTimestamp
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
finally {
|
|
188
|
+
// 8. 清理临时文件
|
|
189
|
+
if (fs_1.default.existsSync(tmpZipPath)) {
|
|
190
|
+
fs_1.default.unlinkSync(tmpZipPath);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* 获取环境信息
|
|
196
|
+
*/
|
|
197
|
+
getEnvInfo() {
|
|
198
|
+
const envConfig = this.environment.lazyEnvironmentConfig;
|
|
199
|
+
return {
|
|
200
|
+
envId: envConfig.EnvId
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* 校验必填参数
|
|
205
|
+
* @param params 参数对象
|
|
206
|
+
* @param fields 必填字段列表
|
|
207
|
+
*/
|
|
208
|
+
validateRequiredParams(params, fields) {
|
|
209
|
+
for (const field of fields) {
|
|
210
|
+
if (!params[field]) {
|
|
211
|
+
throw new error_1.CloudBaseError(`${field} 是必填参数`);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
exports.CloudAppService = CloudAppService;
|
|
217
|
+
__decorate([
|
|
218
|
+
(0, utils_1.preLazy)()
|
|
219
|
+
], CloudAppService.prototype, "createApp", null);
|
|
220
|
+
__decorate([
|
|
221
|
+
(0, utils_1.preLazy)()
|
|
222
|
+
], CloudAppService.prototype, "describeAppList", null);
|
|
223
|
+
__decorate([
|
|
224
|
+
(0, utils_1.preLazy)()
|
|
225
|
+
], CloudAppService.prototype, "describeAppInfo", null);
|
|
226
|
+
__decorate([
|
|
227
|
+
(0, utils_1.preLazy)()
|
|
228
|
+
], CloudAppService.prototype, "deleteApp", null);
|
|
229
|
+
__decorate([
|
|
230
|
+
(0, utils_1.preLazy)()
|
|
231
|
+
], CloudAppService.prototype, "describeAppVersion", null);
|
|
232
|
+
__decorate([
|
|
233
|
+
(0, utils_1.preLazy)()
|
|
234
|
+
], CloudAppService.prototype, "describeAppVersionList", null);
|
|
235
|
+
__decorate([
|
|
236
|
+
(0, utils_1.preLazy)()
|
|
237
|
+
], CloudAppService.prototype, "deleteAppVersion", null);
|
|
238
|
+
__decorate([
|
|
239
|
+
(0, utils_1.preLazy)()
|
|
240
|
+
], CloudAppService.prototype, "describeCosInfo", null);
|
|
241
|
+
__decorate([
|
|
242
|
+
(0, utils_1.preLazy)()
|
|
243
|
+
], CloudAppService.prototype, "uploadCode", null);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* CloudApp 统一部署服务类型定义
|
|
4
|
+
* 支持 static-hosting(静态托管)和 http-function(预留)两种部署类型
|
|
5
|
+
*
|
|
6
|
+
* 命名规范:
|
|
7
|
+
* - 入参接口(IXxxParams):camelCase,通过 upperCaseObjKey 转换后透传给 API
|
|
8
|
+
* - 返回值接口(IXxxResult):PascalCase,与 API 响应字段保持一致
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
package/lib/cloudrun/index.js
CHANGED
|
@@ -346,34 +346,6 @@ class CloudRunService {
|
|
|
346
346
|
async getTemplates() {
|
|
347
347
|
return (0, utils_1.fetchTemplates)(['tcbrFunc', 'tcbrContainer']);
|
|
348
348
|
}
|
|
349
|
-
async _checkFunctionExist(name) {
|
|
350
|
-
try {
|
|
351
|
-
await this.detail({
|
|
352
|
-
serverName: name
|
|
353
|
-
});
|
|
354
|
-
return true;
|
|
355
|
-
}
|
|
356
|
-
catch (e) {
|
|
357
|
-
if (e.code === 'ResourceNotFound' ||
|
|
358
|
-
e.code === 'ResourceNotFound.ServerNotFound' ||
|
|
359
|
-
// 备注:以下条件当 NotFound 处理(已与 fisheryan 确认过)
|
|
360
|
-
(e.code === 'InvalidParameter' && e.original.Message === 'service data illegal')) {
|
|
361
|
-
return false;
|
|
362
|
-
}
|
|
363
|
-
throw e;
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
_upsertFunction(isNew, data) {
|
|
367
|
-
const { name, deployInfo, serverConfig } = data;
|
|
368
|
-
const envConfig = this.environment.lazyEnvironmentConfig;
|
|
369
|
-
const Items = parseObjectToDiffConfigItem(serverConfig);
|
|
370
|
-
return this.tcbrService.request(isNew ? 'CreateCloudRunServer' : 'UpdateCloudRunServer', {
|
|
371
|
-
EnvId: envConfig.EnvId,
|
|
372
|
-
ServerName: name,
|
|
373
|
-
DeployInfo: deployInfo,
|
|
374
|
-
Items,
|
|
375
|
-
});
|
|
376
|
-
}
|
|
377
349
|
/**
|
|
378
350
|
* 获取部署记录列表,按部署时间倒序(最新在前)
|
|
379
351
|
*/
|
|
@@ -408,6 +380,34 @@ class CloudRunService {
|
|
|
408
380
|
RunId: params.RunId,
|
|
409
381
|
});
|
|
410
382
|
}
|
|
383
|
+
async _checkFunctionExist(name) {
|
|
384
|
+
try {
|
|
385
|
+
await this.detail({
|
|
386
|
+
serverName: name
|
|
387
|
+
});
|
|
388
|
+
return true;
|
|
389
|
+
}
|
|
390
|
+
catch (e) {
|
|
391
|
+
if (e.code === 'ResourceNotFound' ||
|
|
392
|
+
e.code === 'ResourceNotFound.ServerNotFound' ||
|
|
393
|
+
// 备注:以下条件当 NotFound 处理(已与 fisheryan 确认过)
|
|
394
|
+
(e.code === 'InvalidParameter' && e.original.Message === 'service data illegal')) {
|
|
395
|
+
return false;
|
|
396
|
+
}
|
|
397
|
+
throw e;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
_upsertFunction(isNew, data) {
|
|
401
|
+
const { name, deployInfo, serverConfig } = data;
|
|
402
|
+
const envConfig = this.environment.lazyEnvironmentConfig;
|
|
403
|
+
const Items = parseObjectToDiffConfigItem(serverConfig);
|
|
404
|
+
return this.tcbrService.request(isNew ? 'CreateCloudRunServer' : 'UpdateCloudRunServer', {
|
|
405
|
+
EnvId: envConfig.EnvId,
|
|
406
|
+
ServerName: name,
|
|
407
|
+
DeployInfo: deployInfo,
|
|
408
|
+
Items,
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
411
|
}
|
|
412
412
|
exports.CloudRunService = CloudRunService;
|
|
413
413
|
__decorate([
|
package/lib/env/index.js
CHANGED
|
@@ -508,6 +508,98 @@ class EnvService {
|
|
|
508
508
|
async describeCreditsUsageDetail(params) {
|
|
509
509
|
return this.cloudService.request('DescribeCreditsUsageDetail', Object.assign({}, params));
|
|
510
510
|
}
|
|
511
|
+
/**
|
|
512
|
+
* 查询HTTP访问服务域名路由信息
|
|
513
|
+
* @param {DescribeHttpServiceRouteParams} params 查询参数
|
|
514
|
+
* @returns {Promise<DescribeHttpServiceRouteRes>}
|
|
515
|
+
*/
|
|
516
|
+
async describeHttpServiceRoute(params) {
|
|
517
|
+
return this.cloudService.request('DescribeHTTPServiceRoute', Object.assign({}, params));
|
|
518
|
+
}
|
|
519
|
+
/**
|
|
520
|
+
* 创建HTTP访问服务域名路由
|
|
521
|
+
* @param {CreateHttpServiceRouteParams} params 创建参数
|
|
522
|
+
* @returns {Promise<CreateHttpServiceRouteRes>}
|
|
523
|
+
*/
|
|
524
|
+
async createHttpServiceRoute(params) {
|
|
525
|
+
return this.cloudService.request('CreateHTTPServiceRoute', Object.assign({}, params));
|
|
526
|
+
}
|
|
527
|
+
/**
|
|
528
|
+
* 修改HTTP访问服务域名路由
|
|
529
|
+
* @param {ModifyHttpServiceRouteParams} params 修改参数
|
|
530
|
+
* @returns {Promise<ModifyHttpServiceRouteRes>}
|
|
531
|
+
*/
|
|
532
|
+
async modifyHttpServiceRoute(params) {
|
|
533
|
+
return this.cloudService.request('ModifyHTTPServiceRoute', Object.assign({}, params));
|
|
534
|
+
}
|
|
535
|
+
/**
|
|
536
|
+
* 删除HTTP访问服务域名路由
|
|
537
|
+
* @param {DeleteHttpServiceRouteParams} params 删除参数
|
|
538
|
+
* @returns {Promise<DeleteHttpServiceRouteRes>}
|
|
539
|
+
*/
|
|
540
|
+
async deleteHttpServiceRoute(params) {
|
|
541
|
+
return this.cloudService.request('DeleteHTTPServiceRoute', Object.assign({}, params));
|
|
542
|
+
}
|
|
543
|
+
/**
|
|
544
|
+
* 绑定自定义域名到HTTP访问服务
|
|
545
|
+
* 底层调用 CreateHTTPServiceRoute API,专用于域名绑定场景
|
|
546
|
+
* @param {BindCustomDomainParams} params 绑定参数
|
|
547
|
+
* @returns {Promise<BindCustomDomainRes>}
|
|
548
|
+
*/
|
|
549
|
+
async bindCustomDomain(params) {
|
|
550
|
+
const { EnvId, Domain } = params;
|
|
551
|
+
// 构建域名参数,设置默认值
|
|
552
|
+
const domainParam = {
|
|
553
|
+
Domain: Domain.Domain,
|
|
554
|
+
CertId: Domain.CertId,
|
|
555
|
+
AccessType: Domain.AccessType || 'DIRECT',
|
|
556
|
+
Protocol: Domain.Protocol || 'HTTP_AND_HTTPS',
|
|
557
|
+
Enable: Domain.Enable !== undefined ? Domain.Enable : true
|
|
558
|
+
};
|
|
559
|
+
// 自定义接入类型时需要传入 CustomCname
|
|
560
|
+
if (domainParam.AccessType === 'CUSTOM' && Domain.CustomCname) {
|
|
561
|
+
domainParam.CustomCname = Domain.CustomCname;
|
|
562
|
+
}
|
|
563
|
+
return this.cloudService.request('CreateHTTPServiceRoute', {
|
|
564
|
+
EnvId,
|
|
565
|
+
Domain: domainParam
|
|
566
|
+
});
|
|
567
|
+
}
|
|
568
|
+
/**
|
|
569
|
+
* 删除自定义域名
|
|
570
|
+
* 仅当域名下无路由绑定时可删除,否则抛出错误
|
|
571
|
+
* @param {DeleteCustomDomainParams} params 删除参数
|
|
572
|
+
* @returns {Promise<DeleteCustomDomainRes>}
|
|
573
|
+
*/
|
|
574
|
+
async deleteCustomDomain(params) {
|
|
575
|
+
const { EnvId, Domain } = params;
|
|
576
|
+
// 查询domain下的路由
|
|
577
|
+
const queryRes = await this.describeHttpServiceRoute({
|
|
578
|
+
EnvId,
|
|
579
|
+
Filters: [
|
|
580
|
+
{
|
|
581
|
+
Name: 'Domain',
|
|
582
|
+
Values: [Domain]
|
|
583
|
+
}
|
|
584
|
+
]
|
|
585
|
+
});
|
|
586
|
+
const domains = queryRes.Domains || [];
|
|
587
|
+
const targetDomain = domains.find(d => d.Domain === Domain);
|
|
588
|
+
if (!targetDomain) {
|
|
589
|
+
throw new error_1.CloudBaseError(`Domain ${Domain} does not exist`);
|
|
590
|
+
}
|
|
591
|
+
// 检查是否有路由绑定
|
|
592
|
+
const routes = targetDomain.Routes || [];
|
|
593
|
+
if (routes.length > 0) {
|
|
594
|
+
const routePaths = routes.map(r => r.Path).join(', ');
|
|
595
|
+
throw new error_1.CloudBaseError(`Domain ${Domain} has ${routes.length} route binding(s) (${routePaths}). Please delete the routes before deleting the domain.`);
|
|
596
|
+
}
|
|
597
|
+
// 无路由绑定,可以删除域名
|
|
598
|
+
return this.cloudService.request('DeleteHTTPServiceRoute', {
|
|
599
|
+
EnvId,
|
|
600
|
+
Domain
|
|
601
|
+
});
|
|
602
|
+
}
|
|
511
603
|
// 获取 COS CORS 域名
|
|
512
604
|
async getCOSDomains() {
|
|
513
605
|
const cos = this.getCos();
|
package/lib/environment.js
CHANGED
|
@@ -18,6 +18,7 @@ const access_1 = require("./access");
|
|
|
18
18
|
const user_1 = require("./user");
|
|
19
19
|
const cloudBaseRun_1 = require("./cloudBaseRun");
|
|
20
20
|
const mysql_1 = require("./mysql");
|
|
21
|
+
const cloudApp_1 = require("./cloudApp");
|
|
21
22
|
const permission_1 = require("./permission");
|
|
22
23
|
class Environment {
|
|
23
24
|
constructor(context, envId) {
|
|
@@ -41,6 +42,7 @@ class Environment {
|
|
|
41
42
|
this.cloudBaseRunService = new cloudBaseRun_1.CloudBaseRunService(this);
|
|
42
43
|
this.mysqlService = new mysql_1.MysqlService(this);
|
|
43
44
|
this.permissionService = new permission_1.PermissionService(this);
|
|
45
|
+
this.cloudAppService = new cloudApp_1.CloudAppService(this);
|
|
44
46
|
}
|
|
45
47
|
async lazyInit() {
|
|
46
48
|
if (!this.inited) {
|
|
@@ -103,6 +105,9 @@ class Environment {
|
|
|
103
105
|
getMysqlService() {
|
|
104
106
|
return this.mysqlService;
|
|
105
107
|
}
|
|
108
|
+
getCloudAppService() {
|
|
109
|
+
return this.cloudAppService;
|
|
110
|
+
}
|
|
106
111
|
getPermissionService() {
|
|
107
112
|
return this.permissionService;
|
|
108
113
|
}
|
package/lib/index.js
CHANGED
|
@@ -70,9 +70,34 @@ class CloudBase {
|
|
|
70
70
|
get mysql() {
|
|
71
71
|
return this.currentEnvironment().getMysqlService();
|
|
72
72
|
}
|
|
73
|
+
/**
|
|
74
|
+
* 云托管服务(CloudBaseRun)
|
|
75
|
+
* 提供云托管版本流量配置等能力
|
|
76
|
+
* @deprecated 请使用 cloudBaseRun 代替,避免与 cloudAppService 混淆
|
|
77
|
+
*/
|
|
73
78
|
get cloudApp() {
|
|
74
79
|
return this.currentEnvironment().getCloudBaseRunService();
|
|
75
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* 云托管服务(CloudBaseRun)
|
|
83
|
+
* 提供云托管版本流量配置等能力
|
|
84
|
+
*/
|
|
85
|
+
get cloudBaseRun() {
|
|
86
|
+
return this.currentEnvironment().getCloudBaseRunService();
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* 云应用服务(CloudApp 统一部署)
|
|
90
|
+
* 提供 Web 应用的创建、部署、版本管理等能力
|
|
91
|
+
*/
|
|
92
|
+
get cloudAppService() {
|
|
93
|
+
return this.currentEnvironment().getCloudAppService();
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* 获取云应用服务
|
|
97
|
+
*/
|
|
98
|
+
getCloudAppService() {
|
|
99
|
+
return this.currentEnvironment().getCloudAppService();
|
|
100
|
+
}
|
|
76
101
|
commonService(service, version) {
|
|
77
102
|
return this.currentEnvironment().getCommonService(service, version);
|
|
78
103
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
/**
|
|
18
|
+
* CloudApp 统一部署服务接口导出
|
|
19
|
+
*/
|
|
20
|
+
__exportStar(require("../cloudApp/types"), exports);
|
package/lib/interfaces/index.js
CHANGED
|
@@ -21,3 +21,4 @@ __exportStar(require("./base.interface"), exports);
|
|
|
21
21
|
__exportStar(require("./storage.interface"), exports);
|
|
22
22
|
__exportStar(require("./cam.interface"), exports);
|
|
23
23
|
__exportStar(require("./billing.interface"), exports);
|
|
24
|
+
__exportStar(require("./cloudApp.interface"), exports);
|
package/lib/permission/index.js
CHANGED
|
@@ -25,7 +25,9 @@ class PermissionService {
|
|
|
25
25
|
if (!resourceType || !PERMISSION_BY_RESOURCE[resourceType]) {
|
|
26
26
|
throw new Error('Invalid resourceType');
|
|
27
27
|
}
|
|
28
|
-
|
|
28
|
+
const isFunctionResourceType = resourceType === 'function';
|
|
29
|
+
const hasValidResourceValue = typeof resource === 'string' && resource.trim().length > 0;
|
|
30
|
+
if (!isFunctionResourceType && !hasValidResourceValue) {
|
|
29
31
|
throw new Error('Invalid resource');
|
|
30
32
|
}
|
|
31
33
|
const allowed = PERMISSION_BY_RESOURCE[resourceType];
|
|
@@ -43,12 +45,7 @@ class PermissionService {
|
|
|
43
45
|
// throw new Error('securityRule must be a valid JSON string')
|
|
44
46
|
// }
|
|
45
47
|
}
|
|
46
|
-
const reqData = {
|
|
47
|
-
EnvId,
|
|
48
|
-
ResourceType: resourceType,
|
|
49
|
-
Resource: resource,
|
|
50
|
-
Permission: permission
|
|
51
|
-
};
|
|
48
|
+
const reqData = Object.assign({ EnvId, ResourceType: resourceType, Permission: permission }, (hasValidResourceValue || !isFunctionResourceType ? { Resource: resource } : {}));
|
|
52
49
|
if (permission === 'CUSTOM') {
|
|
53
50
|
reqData.SecurityRule = securityRule;
|
|
54
51
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudbase/manager-node",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "The node manage service api for cloudbase.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"node-fetch": "^2.6.0",
|
|
53
53
|
"query-string": "^6.8.3",
|
|
54
54
|
"unzipper": "^0.12.3",
|
|
55
|
-
"uuid": "^
|
|
55
|
+
"uuid": "^9.0.0",
|
|
56
56
|
"walkdir": "^0.4.1"
|
|
57
57
|
},
|
|
58
58
|
"husky": {
|
package/types/agent/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Environment } from '../environment';
|
|
2
|
-
import { ICreateFunctionAgentParams,
|
|
2
|
+
import { ICreateFunctionAgentParams, ICreateAgentParams, ICreateTcbrAgentByImageParams, ICreateTcbrAgentByPackageParams, ICreateTcbrAgentByCodeParams, IDescribeAgentListParams, IDescribeAgentListResponse, IDescribeAgentResponse, IDeleteAgentParams, IDescribeCloudBaseBuildServiceParams, IDescribeCloudBaseBuildServiceResponse, ICreateAgentResponse, IDeleteAgentResponse, ICommonResponse, IUpdateAgentParams, IUpdateScfAgentParams, IUpdateScfAgentResponse, IUpdateTcbrAgentParams, IGetAgentLogsParams } from './type';
|
|
3
3
|
/**
|
|
4
4
|
* Agent 管理类
|
|
5
5
|
* 支持三种部署方式:
|
|
@@ -12,14 +12,14 @@ export declare class AgentService {
|
|
|
12
12
|
private tcbService;
|
|
13
13
|
constructor(environment: Environment);
|
|
14
14
|
/**
|
|
15
|
-
* 创建
|
|
15
|
+
* 创建 Agent
|
|
16
16
|
* 支持两种方式:
|
|
17
17
|
* 1. 传入 cwd 代码目录,自动打包上传
|
|
18
18
|
* 2. 传入 ZipFile / CosBucketRegion + TempCosObjectName,直接上传
|
|
19
19
|
* @param params 创建参数
|
|
20
20
|
* @returns Agent 创建结果
|
|
21
21
|
*/
|
|
22
|
-
|
|
22
|
+
createAgent(params: ICreateAgentParams): Promise<ICreateAgentResponse>;
|
|
23
23
|
/**
|
|
24
24
|
* 查询 Agent 列表
|
|
25
25
|
* @param params 查询参数
|
package/types/agent/type.d.ts
CHANGED
|
@@ -28,12 +28,12 @@ export interface ISessionConfig {
|
|
|
28
28
|
MaxConcurrency?: number;
|
|
29
29
|
}
|
|
30
30
|
/**
|
|
31
|
-
* 创建
|
|
31
|
+
* 创建 Agent 的参数
|
|
32
32
|
* 支持两种方式:
|
|
33
33
|
* 1. 传入 cwd 代码目录,自动打包上传
|
|
34
34
|
* 2. 传入 ZipFile / CosBucketRegion + TempCosObjectName,直接上传
|
|
35
35
|
*/
|
|
36
|
-
export interface
|
|
36
|
+
export interface ICreateAgentParams {
|
|
37
37
|
/** Agent 名称 */
|
|
38
38
|
Name: string;
|
|
39
39
|
/** Agent ID,不传则自动生成 */
|