@cloudbase/manager-node 4.2.3 → 4.2.5
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/CHANGELOG.md +4 -0
- package/lib/constant.js +5 -1
- package/lib/env/index.js +10 -209
- package/lib/function/index.js +0 -3
- package/lib/storage/index.js +24 -10
- package/lib/utils/cloud-api-request.js +7 -0
- package/lib/utils/http-request.js +3 -3
- package/lib/utils/runenv.js +8 -0
- package/package.json +4 -3
- package/types/constant.d.ts +7 -0
- package/types/env/index.d.ts +0 -17
- package/types/function/types.d.ts +0 -2
- package/types/utils/runenv.d.ts +1 -0
- package/src/access/index.ts +0 -168
- package/src/access/types.ts +0 -55
- package/src/billing/index.ts +0 -43
- package/src/cam/index.ts +0 -106
- package/src/cloudBaseRun/index.ts +0 -40
- package/src/cloudBaseRun/types.ts +0 -24
- package/src/common/index.ts +0 -54
- package/src/constant.ts +0 -56
- package/src/context.ts +0 -18
- package/src/database/index.ts +0 -369
- package/src/debug.ts +0 -34
- package/src/env/index.ts +0 -614
- package/src/environment.ts +0 -156
- package/src/environmentManager.ts +0 -50
- package/src/error.ts +0 -27
- package/src/function/index.ts +0 -1378
- package/src/function/packer.ts +0 -164
- package/src/function/types.ts +0 -165
- package/src/hosting/index.ts +0 -698
- package/src/index.ts +0 -127
- package/src/interfaces/base.interface.ts +0 -8
- package/src/interfaces/billing.interface.ts +0 -21
- package/src/interfaces/cam.interface.ts +0 -28
- package/src/interfaces/flexdb.interface.ts +0 -104
- package/src/interfaces/function.interface.ts +0 -75
- package/src/interfaces/index.ts +0 -7
- package/src/interfaces/storage.interface.ts +0 -29
- package/src/interfaces/tcb.interface.ts +0 -642
- package/src/storage/index.ts +0 -1290
- package/src/third/index.ts +0 -24
- package/src/user/index.ts +0 -174
- package/src/user/types.ts +0 -21
- package/src/utils/auth.ts +0 -112
- package/src/utils/cloud-api-request.ts +0 -252
- package/src/utils/cloudbase-request.ts +0 -109
- package/src/utils/envLazy.ts +0 -15
- package/src/utils/fs.ts +0 -57
- package/src/utils/http-request.ts +0 -37
- package/src/utils/index.ts +0 -103
- package/src/utils/parallel.ts +0 -82
- package/src/utils/uuid.ts +0 -14
package/CHANGELOG.md
CHANGED
package/lib/constant.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// static credentail = 'credential'
|
|
5
5
|
// }
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.SCF_STATUS = exports.ROLE_NAME = exports.PUBLIC_RSA_KEY = exports.ERROR = exports.SERVICE_TYPE = exports.ENDPOINT = exports.RUN_ENV = exports.SDK_VERSION = exports.ENV_NAME = void 0;
|
|
7
|
+
exports.COS_SDK_KEEPALIVE = exports.COS_SDK_PROTOCOL = exports.USE_INTERNAL_ENDPOINT = exports.SCF_STATUS = exports.ROLE_NAME = exports.PUBLIC_RSA_KEY = exports.ERROR = exports.SERVICE_TYPE = exports.ENDPOINT = exports.RUN_ENV = exports.SDK_VERSION = exports.ENV_NAME = void 0;
|
|
8
8
|
exports.ENV_NAME = {
|
|
9
9
|
ENV_SECRETID: 'TENCENTCLOUD_SECRETID',
|
|
10
10
|
ENV_SECRETKEY: 'TENCENTCLOUD_SECRETKEY',
|
|
@@ -49,3 +49,7 @@ exports.SCF_STATUS = {
|
|
|
49
49
|
UPDATING: 'Updating',
|
|
50
50
|
CREATE_FAILED: 'CreateFailed'
|
|
51
51
|
};
|
|
52
|
+
// 是否使用内网域名
|
|
53
|
+
exports.USE_INTERNAL_ENDPOINT = "USE_INTERNAL_ENDPOINT" in process.env;
|
|
54
|
+
exports.COS_SDK_PROTOCOL = process.env.COS_SDK_PROTOCOL;
|
|
55
|
+
exports.COS_SDK_KEEPALIVE = process.env.COS_SDK_KEEPALIVE;
|
package/lib/env/index.js
CHANGED
|
@@ -14,17 +14,13 @@ const cos_nodejs_sdk_v5_1 = __importDefault(require("cos-nodejs-sdk-v5"));
|
|
|
14
14
|
const util_1 = __importDefault(require("util"));
|
|
15
15
|
const error_1 = require("../error");
|
|
16
16
|
const utils_1 = require("../utils");
|
|
17
|
-
const cam_1 = require("../cam");
|
|
18
17
|
const constant_1 = require("../constant");
|
|
19
|
-
const billing_1 = require("../billing");
|
|
20
18
|
class EnvService {
|
|
21
19
|
constructor(environment) {
|
|
22
20
|
this.environment = environment;
|
|
23
21
|
this.envId = environment.getEnvId();
|
|
24
22
|
this.envType = environment.getEnvType();
|
|
25
23
|
this.cloudService = new utils_1.CloudService(environment.cloudBaseContext, 'tcb', '2018-06-08');
|
|
26
|
-
this.camService = new cam_1.CamService(environment.cloudBaseContext);
|
|
27
|
-
this.billService = new billing_1.BillingService(environment.cloudBaseContext);
|
|
28
24
|
}
|
|
29
25
|
/**
|
|
30
26
|
* 列出所有环境
|
|
@@ -33,208 +29,6 @@ class EnvService {
|
|
|
33
29
|
async listEnvs() {
|
|
34
30
|
return this.cloudService.request('DescribeEnvs');
|
|
35
31
|
}
|
|
36
|
-
/**
|
|
37
|
-
* 创建新环境
|
|
38
|
-
* @param {string} name 环境名称
|
|
39
|
-
* @returns {Promise<ICreateEnvRes>}
|
|
40
|
-
*/
|
|
41
|
-
async createEnv(param) {
|
|
42
|
-
// 1. 检查是否开通过TCB服务,若未开通,跳2检查角色 开通则跳5 创建环境
|
|
43
|
-
// 2. 查询tcb 角色是否绑定该账户
|
|
44
|
-
// 3. 若未绑定,则创建角色并绑定角色
|
|
45
|
-
// 4. 开通TCB服务
|
|
46
|
-
// 5. 创建环境
|
|
47
|
-
// 6. 购买环境,选择预付费 或 后付费 套餐
|
|
48
|
-
// 7. 若购买失败,将当前环境销毁,若购买成功,返回envId
|
|
49
|
-
const { name, paymentMode, channel = 'qc_console' } = param;
|
|
50
|
-
// 1. 检查TCB服务是否开通
|
|
51
|
-
const { Initialized } = await this.checkTcbService();
|
|
52
|
-
if (!Initialized) {
|
|
53
|
-
// 跳2 查询TCB角色是否绑定
|
|
54
|
-
let hasTcbRole = false;
|
|
55
|
-
try {
|
|
56
|
-
const res = await this.camService.getRole(constant_1.ROLE_NAME.TCB);
|
|
57
|
-
hasTcbRole = true;
|
|
58
|
-
}
|
|
59
|
-
catch (e) {
|
|
60
|
-
// 判断是否为角色不存在错误
|
|
61
|
-
if (e.code !== 'InvalidParameter.RoleNotExist') {
|
|
62
|
-
throw e;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
if (!hasTcbRole) {
|
|
66
|
-
// 3. 当前账户没有tcbRole,创建角色并绑定
|
|
67
|
-
// 创建角色
|
|
68
|
-
const createRoleResult = await this.camService.createRole({
|
|
69
|
-
RoleName: constant_1.ROLE_NAME.TCB,
|
|
70
|
-
Description: '云开发(TCB)操作权限含在访问管理(CAM)创建角色,新增角色载体,给角色绑定策略;含读写对象存储(COS)数据;含读写无服务器云函数(SCF)数据;含读取云监控(Monitor)数据。',
|
|
71
|
-
PolicyDocument: '{"version":"2.0","statement":[{"action":"sts:AssumeRole","effect":"allow","principal":{"service":["scf.qcloud.com","tcb.cloud.tencent.com", "cvm.qcloud.com"]}}]}'
|
|
72
|
-
});
|
|
73
|
-
const { RoleId } = createRoleResult;
|
|
74
|
-
// 绑定角色策略
|
|
75
|
-
// await this.camService.attachRolePolicy({
|
|
76
|
-
// PolicyId: 8825032,
|
|
77
|
-
// AttachRoleName: ROLE_NAME.TCB
|
|
78
|
-
// })
|
|
79
|
-
await this.camService.attachRolePolicies({
|
|
80
|
-
RoleName: constant_1.ROLE_NAME.TCB,
|
|
81
|
-
PolicyName: [
|
|
82
|
-
'QcloudAccessForTCBRole',
|
|
83
|
-
'QcloudAccessForTCBRoleInAccessCloudBaseRun'
|
|
84
|
-
]
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
// 4. 未开通则初始化TCB
|
|
88
|
-
await this.initTcb({ Channel: channel, Source: 'qcloud' });
|
|
89
|
-
}
|
|
90
|
-
// 5. 创建环境
|
|
91
|
-
const params = {
|
|
92
|
-
Alias: name,
|
|
93
|
-
EnvId: `${name}-${utils_1.guid6()}`,
|
|
94
|
-
Source: 'qcloud'
|
|
95
|
-
};
|
|
96
|
-
if (channel) {
|
|
97
|
-
params.Channel = channel;
|
|
98
|
-
}
|
|
99
|
-
const { EnvId } = await this.cloudService.request('CreateEnv', params);
|
|
100
|
-
const realPaymentMode = paymentMode ? paymentMode : 'postpay';
|
|
101
|
-
// 6. 购买环境
|
|
102
|
-
let prepayCreateDeal = false;
|
|
103
|
-
let prepayPayDeal = false;
|
|
104
|
-
let postpayDeal = false;
|
|
105
|
-
let payError = null;
|
|
106
|
-
if (realPaymentMode === 'prepay') {
|
|
107
|
-
// 预付费
|
|
108
|
-
// 1. 创建订单
|
|
109
|
-
// 2. 支付订单
|
|
110
|
-
const goods = [
|
|
111
|
-
{
|
|
112
|
-
GoodsCategoryId: 101183,
|
|
113
|
-
// action: 'purchase',
|
|
114
|
-
// currency: 'CNY',
|
|
115
|
-
RegionId: 1,
|
|
116
|
-
ZoneId: 0,
|
|
117
|
-
GoodsNum: 1,
|
|
118
|
-
ProjectId: 0,
|
|
119
|
-
PayMode: 1,
|
|
120
|
-
Platform: 1,
|
|
121
|
-
GoodsDetail: JSON.stringify({
|
|
122
|
-
productCode: 'p_tcb',
|
|
123
|
-
subProductCode: 'sp_tcb_basic',
|
|
124
|
-
resourceId: EnvId,
|
|
125
|
-
pid: 16677,
|
|
126
|
-
timeUnit: 'm',
|
|
127
|
-
timeSpan: 1,
|
|
128
|
-
tcb_cos: 1,
|
|
129
|
-
tcb_cdn: 1,
|
|
130
|
-
tcb_scf: 1,
|
|
131
|
-
tcb_mongodb: 1,
|
|
132
|
-
region: 'ap-shanghai',
|
|
133
|
-
zone: 'ap-shanghai-1',
|
|
134
|
-
source: 'qcloud',
|
|
135
|
-
envId: EnvId,
|
|
136
|
-
packageId: 'basic',
|
|
137
|
-
isAutoRenew: 'true',
|
|
138
|
-
tranType: 1,
|
|
139
|
-
productInfo: [
|
|
140
|
-
{
|
|
141
|
-
name: '套餐版本',
|
|
142
|
-
value: '基础版 1'
|
|
143
|
-
},
|
|
144
|
-
{
|
|
145
|
-
name: '存储空间',
|
|
146
|
-
value: '5GB'
|
|
147
|
-
},
|
|
148
|
-
{
|
|
149
|
-
name: 'CDN流量',
|
|
150
|
-
value: '5GB'
|
|
151
|
-
},
|
|
152
|
-
{
|
|
153
|
-
name: '云函数资源使用量',
|
|
154
|
-
value: '4万GBs'
|
|
155
|
-
},
|
|
156
|
-
{
|
|
157
|
-
name: '数据库容量',
|
|
158
|
-
value: '2GB'
|
|
159
|
-
},
|
|
160
|
-
{
|
|
161
|
-
name: '数据库同时连接数',
|
|
162
|
-
value: '20个'
|
|
163
|
-
}
|
|
164
|
-
]
|
|
165
|
-
})
|
|
166
|
-
}
|
|
167
|
-
];
|
|
168
|
-
let OrderIdsList = [];
|
|
169
|
-
try {
|
|
170
|
-
const { OrderIds } = await this.billService.GenerateDeals(goods);
|
|
171
|
-
OrderIdsList = OrderIds;
|
|
172
|
-
prepayCreateDeal = true;
|
|
173
|
-
}
|
|
174
|
-
catch (e) {
|
|
175
|
-
// 预付费下单失败
|
|
176
|
-
payError = e;
|
|
177
|
-
}
|
|
178
|
-
if (prepayCreateDeal) {
|
|
179
|
-
// 下单成功
|
|
180
|
-
try {
|
|
181
|
-
// 购买环境套餐
|
|
182
|
-
const { OrderIds: succOrderIds } = await this.billService.PayDeals(OrderIdsList);
|
|
183
|
-
// 判断订单是否支付成功
|
|
184
|
-
if (succOrderIds[0] === OrderIdsList[0]) {
|
|
185
|
-
prepayPayDeal = true;
|
|
186
|
-
}
|
|
187
|
-
else {
|
|
188
|
-
throw new error_1.CloudBaseError('支付成功的订单号不一致');
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
catch (e) {
|
|
192
|
-
// 预付费订单支付失败
|
|
193
|
-
payError = new error_1.CloudBaseError('预付费订单支付失败,请进入订单管理页面(https://console.cloud.tencent.com/deal)重新支付', {
|
|
194
|
-
original: e
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
if (realPaymentMode === 'postpay') {
|
|
200
|
-
// 后付费
|
|
201
|
-
try {
|
|
202
|
-
const { TranId } = await this.CreatePostpayPackage(EnvId);
|
|
203
|
-
postpayDeal = true;
|
|
204
|
-
}
|
|
205
|
-
catch (e) {
|
|
206
|
-
payError = e;
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
// 检查支付状态
|
|
210
|
-
// 1. 预付费下单失败 删除环境
|
|
211
|
-
// 2. 预付费下单成功过,支付订单失败,提示用户
|
|
212
|
-
// 3. 后付费开通失败 删除环境
|
|
213
|
-
if (realPaymentMode === 'prepay') {
|
|
214
|
-
if (!prepayCreateDeal) {
|
|
215
|
-
// 情形1
|
|
216
|
-
await this.destroyEnv(EnvId);
|
|
217
|
-
throw payError;
|
|
218
|
-
}
|
|
219
|
-
else {
|
|
220
|
-
if (!prepayPayDeal) {
|
|
221
|
-
// 情形2
|
|
222
|
-
throw payError;
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
if (realPaymentMode === 'postpay') {
|
|
227
|
-
if (!postpayDeal) {
|
|
228
|
-
// 情形3
|
|
229
|
-
await this.destroyEnv(EnvId);
|
|
230
|
-
throw payError;
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
// 成功返回envId
|
|
234
|
-
return {
|
|
235
|
-
envId: EnvId
|
|
236
|
-
};
|
|
237
|
-
}
|
|
238
32
|
/**
|
|
239
33
|
* 拉取安全域名列表
|
|
240
34
|
* @returns {Promise<IAuthDomainsRes>}
|
|
@@ -461,11 +255,18 @@ class EnvService {
|
|
|
461
255
|
}
|
|
462
256
|
getCos() {
|
|
463
257
|
const { secretId, secretKey, token } = this.environment.getAuthConfig();
|
|
464
|
-
|
|
258
|
+
const cosConfig = {
|
|
465
259
|
SecretId: secretId,
|
|
466
260
|
SecretKey: secretKey,
|
|
467
|
-
SecurityToken: token
|
|
468
|
-
|
|
261
|
+
SecurityToken: token,
|
|
262
|
+
Domain: constant_1.USE_INTERNAL_ENDPOINT ? "{Bucket}.cos-internal.{Region}.tencentcos.cn" /* INTERNAL */ : "{Bucket}.cos.{Region}.tencentcos.cn" /* PUBLIC */
|
|
263
|
+
};
|
|
264
|
+
if (constant_1.COS_SDK_PROTOCOL) {
|
|
265
|
+
cosConfig.Protocol = constant_1.COS_SDK_PROTOCOL.endsWith(':')
|
|
266
|
+
? constant_1.COS_SDK_PROTOCOL.toLowerCase()
|
|
267
|
+
: constant_1.COS_SDK_PROTOCOL.toLowerCase() + ':';
|
|
268
|
+
}
|
|
269
|
+
return new cos_nodejs_sdk_v5_1.default(cosConfig);
|
|
469
270
|
}
|
|
470
271
|
getStorageConfig() {
|
|
471
272
|
var _a;
|
package/lib/function/index.js
CHANGED
|
@@ -146,9 +146,6 @@ class FunctionService {
|
|
|
146
146
|
functionPath,
|
|
147
147
|
functionRootPath
|
|
148
148
|
}, params.InstallDependency);
|
|
149
|
-
const { TopicId, LogsetId } = this.getClsServiceConfig();
|
|
150
|
-
params.ClsTopicId = TopicId;
|
|
151
|
-
params.ClsLogsetId = LogsetId;
|
|
152
149
|
try {
|
|
153
150
|
// 创建云函数
|
|
154
151
|
const res = await this.scfService.request('CreateFunction', params);
|
package/lib/storage/index.js
CHANGED
|
@@ -20,6 +20,8 @@ const cos_nodejs_sdk_v5_1 = __importDefault(require("cos-nodejs-sdk-v5"));
|
|
|
20
20
|
const utils_1 = require("../utils");
|
|
21
21
|
const error_1 = require("../error");
|
|
22
22
|
const parallel_1 = require("../utils/parallel");
|
|
23
|
+
const runenv_1 = require("../utils/runenv");
|
|
24
|
+
const constant_1 = require("../constant");
|
|
23
25
|
const BIG_FILE_SIZE = 5242880; // 5MB 1024*1024*5
|
|
24
26
|
class StorageService {
|
|
25
27
|
constructor(environment) {
|
|
@@ -839,14 +841,27 @@ class StorageService {
|
|
|
839
841
|
getCos(parallel = 20) {
|
|
840
842
|
const { secretId, secretKey, token, proxy } = this.environment.getAuthConfig();
|
|
841
843
|
const cosProxy = process.env.TCB_COS_PROXY;
|
|
842
|
-
const
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
}
|
|
849
|
-
|
|
844
|
+
const cosConfig = {
|
|
845
|
+
FileParallelLimit: parallel,
|
|
846
|
+
SecretId: secretId,
|
|
847
|
+
SecretKey: secretKey,
|
|
848
|
+
Proxy: cosProxy || proxy,
|
|
849
|
+
SecurityToken: token,
|
|
850
|
+
Domain: constant_1.USE_INTERNAL_ENDPOINT ? "{Bucket}.cos-internal.{Region}.tencentcos.cn" /* INTERNAL */ : "{Bucket}.cos.{Region}.tencentcos.cn" /* PUBLIC */
|
|
851
|
+
};
|
|
852
|
+
if (constant_1.COS_SDK_PROTOCOL) {
|
|
853
|
+
cosConfig.Protocol = constant_1.COS_SDK_PROTOCOL.endsWith(':')
|
|
854
|
+
? constant_1.COS_SDK_PROTOCOL.toLowerCase()
|
|
855
|
+
: constant_1.COS_SDK_PROTOCOL.toLowerCase() + ':';
|
|
856
|
+
}
|
|
857
|
+
// COSSDK 默认开启 KeepAlive,这里提供关闭的方式
|
|
858
|
+
if (constant_1.COS_SDK_KEEPALIVE) {
|
|
859
|
+
cosConfig.KeepAlive = { true: true, false: false }[constant_1.COS_SDK_KEEPALIVE];
|
|
860
|
+
}
|
|
861
|
+
else if (runenv_1.checkIsInScf()) {
|
|
862
|
+
cosConfig.KeepAlive = false;
|
|
863
|
+
}
|
|
864
|
+
return new cos_nodejs_sdk_v5_1.default(cosConfig);
|
|
850
865
|
}
|
|
851
866
|
/**
|
|
852
867
|
* 将 cloudPath 转换成 cloudPath/ 形式
|
|
@@ -920,8 +935,7 @@ class StorageService {
|
|
|
920
935
|
times: times - 1,
|
|
921
936
|
interval,
|
|
922
937
|
failedFiles: tempFailedFiles
|
|
923
|
-
})
|
|
924
|
-
.then(res => resolve(res))
|
|
938
|
+
}).then(res => resolve(res))
|
|
925
939
|
.catch(err => reject(err)), interval);
|
|
926
940
|
});
|
|
927
941
|
}
|
|
@@ -70,6 +70,13 @@ class CloudService {
|
|
|
70
70
|
cam: 'https://cam.tencentcloudapi.com',
|
|
71
71
|
cdn: 'https://cdn.tencentcloudapi.com'
|
|
72
72
|
};
|
|
73
|
+
// 云梯账号走内网域名
|
|
74
|
+
const intranetUrlMap = Object.keys(urlMap).map((service) => ({
|
|
75
|
+
[service]: `https://${service}.internal.tencentcloudapi.com`,
|
|
76
|
+
})).reduce((acc, cur) => (Object.assign(Object.assign({}, acc), cur)), {});
|
|
77
|
+
if (constant_1.USE_INTERNAL_ENDPOINT) {
|
|
78
|
+
return intranetUrlMap[this.service];
|
|
79
|
+
}
|
|
73
80
|
if (urlMap[this.service]) {
|
|
74
81
|
return urlMap[this.service];
|
|
75
82
|
}
|
|
@@ -6,12 +6,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.fetchStream = exports.fetch = void 0;
|
|
7
7
|
const url_1 = require("url");
|
|
8
8
|
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
9
|
-
const https_proxy_agent_1 =
|
|
9
|
+
const https_proxy_agent_1 = require("https-proxy-agent");
|
|
10
10
|
const error_1 = require("../error");
|
|
11
11
|
// 使用 fetch + 代理
|
|
12
12
|
async function fetch(url, config = {}, proxy) {
|
|
13
13
|
if (proxy || process.env.http_proxy) {
|
|
14
|
-
config.agent = new https_proxy_agent_1.
|
|
14
|
+
config.agent = new https_proxy_agent_1.HttpsProxyAgent(proxy || process.env.http_proxy);
|
|
15
15
|
}
|
|
16
16
|
// 解决中文编码问题
|
|
17
17
|
const escapeUrl = new url_1.URL(url).toString();
|
|
@@ -35,7 +35,7 @@ async function fetch(url, config = {}, proxy) {
|
|
|
35
35
|
exports.fetch = fetch;
|
|
36
36
|
async function fetchStream(url, config = {}, proxy) {
|
|
37
37
|
if (proxy || process.env.http_proxy) {
|
|
38
|
-
config.agent = new https_proxy_agent_1.
|
|
38
|
+
config.agent = new https_proxy_agent_1.HttpsProxyAgent(proxy || process.env.http_proxy);
|
|
39
39
|
}
|
|
40
40
|
// 解决中文编码问题
|
|
41
41
|
const escapeUrl = new url_1.URL(url).toString();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudbase/manager-node",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.5",
|
|
4
4
|
"description": "The node manage service api for cloudbase.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
"test": "jest --runInBand --detectOpenHandles --coverage --testTimeout=50000",
|
|
9
9
|
"lint": "eslint \"./**/*.ts\"",
|
|
10
10
|
"lint:fix": "eslint --fix \"./**/*.ts\"",
|
|
11
|
-
"prepublishOnly": "npm run build"
|
|
11
|
+
"prepublishOnly": "npm run build",
|
|
12
|
+
"watch": "rimraf lib types && tsc -w"
|
|
12
13
|
},
|
|
13
14
|
"repository": {
|
|
14
15
|
"type": "git",
|
|
@@ -37,7 +38,7 @@
|
|
|
37
38
|
"archiver": "^3.1.1",
|
|
38
39
|
"cos-nodejs-sdk-v5": "2.9.0",
|
|
39
40
|
"del": "^5.1.0",
|
|
40
|
-
"https-proxy-agent": "^
|
|
41
|
+
"https-proxy-agent": "^5.0.1",
|
|
41
42
|
"make-dir": "^3.0.0",
|
|
42
43
|
"micromatch": "^4.0.2",
|
|
43
44
|
"node-fetch": "^2.6.0",
|
package/types/constant.d.ts
CHANGED
|
@@ -35,3 +35,10 @@ export declare const SCF_STATUS: {
|
|
|
35
35
|
UPDATING: string;
|
|
36
36
|
CREATE_FAILED: string;
|
|
37
37
|
};
|
|
38
|
+
export declare const USE_INTERNAL_ENDPOINT: boolean;
|
|
39
|
+
export declare const enum COS_ENDPOINT {
|
|
40
|
+
INTERNAL = "{Bucket}.cos-internal.{Region}.tencentcos.cn",
|
|
41
|
+
PUBLIC = "{Bucket}.cos.{Region}.tencentcos.cn"
|
|
42
|
+
}
|
|
43
|
+
export declare const COS_SDK_PROTOCOL: string;
|
|
44
|
+
export declare const COS_SDK_KEEPALIVE: string;
|
package/types/env/index.d.ts
CHANGED
|
@@ -1,13 +1,6 @@
|
|
|
1
1
|
import { Environment } from '../environment';
|
|
2
2
|
import { IResponseInfo, AuthDomain, EnvInfo, LoginConfigItem, ICheckTcbServiceRes, ICreatePostpayRes } from '../interfaces';
|
|
3
|
-
interface ICreateEnvParam {
|
|
4
|
-
name: string;
|
|
5
|
-
paymentMode?: PAYMENT_MODE;
|
|
6
|
-
channel?: QCLOUD_CHANNEL;
|
|
7
|
-
}
|
|
8
|
-
declare type PAYMENT_MODE = 'prepay' | 'postpay';
|
|
9
3
|
declare type SOURCE = 'miniapp' | 'qcloud';
|
|
10
|
-
declare type QCLOUD_CHANNEL = 'cocos' | 'qq' | 'cloudgame' | 'qc_console' | 'dcloud';
|
|
11
4
|
interface IDeleteDomainRes {
|
|
12
5
|
RequestId: string;
|
|
13
6
|
Deleted: number;
|
|
@@ -32,8 +25,6 @@ export declare class EnvService {
|
|
|
32
25
|
private environment;
|
|
33
26
|
private envId;
|
|
34
27
|
private cloudService;
|
|
35
|
-
private camService;
|
|
36
|
-
private billService;
|
|
37
28
|
private envType?;
|
|
38
29
|
constructor(environment: Environment);
|
|
39
30
|
/**
|
|
@@ -41,14 +32,6 @@ export declare class EnvService {
|
|
|
41
32
|
* @returns {Promise<IListEnvRes>}
|
|
42
33
|
*/
|
|
43
34
|
listEnvs(): Promise<IListEnvRes>;
|
|
44
|
-
/**
|
|
45
|
-
* 创建新环境
|
|
46
|
-
* @param {string} name 环境名称
|
|
47
|
-
* @returns {Promise<ICreateEnvRes>}
|
|
48
|
-
*/
|
|
49
|
-
createEnv(param: ICreateEnvParam): Promise<{
|
|
50
|
-
envId: string;
|
|
51
|
-
}>;
|
|
52
35
|
/**
|
|
53
36
|
* 拉取安全域名列表
|
|
54
37
|
* @returns {Promise<IAuthDomainsRes>}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function checkIsInScf(): boolean;
|
package/src/access/index.ts
DELETED
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
import { Environment } from '../environment'
|
|
2
|
-
import { CloudService, preLazy } from '../utils'
|
|
3
|
-
import {
|
|
4
|
-
ICreateAccessOptions,
|
|
5
|
-
IApi,
|
|
6
|
-
IUpdateOptions,
|
|
7
|
-
IService,
|
|
8
|
-
IDeleteOptions,
|
|
9
|
-
IGetOptions,
|
|
10
|
-
IDomainOptions
|
|
11
|
-
} from './types'
|
|
12
|
-
import { IResponseInfo } from '../interfaces'
|
|
13
|
-
|
|
14
|
-
export class AccessService {
|
|
15
|
-
private tcbService: CloudService
|
|
16
|
-
private environment: Environment
|
|
17
|
-
|
|
18
|
-
constructor(environment: Environment) {
|
|
19
|
-
this.environment = environment
|
|
20
|
-
this.tcbService = new CloudService(environment.cloudBaseContext, 'tcb', '2018-06-08')
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// 创建云接入路径
|
|
24
|
-
@preLazy()
|
|
25
|
-
public async createAccess(options: ICreateAccessOptions) {
|
|
26
|
-
const { path, name, type = 1, auth } = options
|
|
27
|
-
const { envId } = this.getEnvInfo()
|
|
28
|
-
|
|
29
|
-
return this.tcbService.request<{
|
|
30
|
-
APIId: string
|
|
31
|
-
RequestId: string
|
|
32
|
-
}>('CreateCloudBaseGWAPI', {
|
|
33
|
-
ServiceId: envId,
|
|
34
|
-
Path: path,
|
|
35
|
-
Type: type,
|
|
36
|
-
Name: name,
|
|
37
|
-
AuthSwitch: auth ? 1 : 2
|
|
38
|
-
})
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// 获取云接入自定义域名列表
|
|
42
|
-
@preLazy()
|
|
43
|
-
public async getDomainList() {
|
|
44
|
-
const { envId } = this.getEnvInfo()
|
|
45
|
-
return this.tcbService.request<{
|
|
46
|
-
RequestId: string
|
|
47
|
-
// 云接入默认域名
|
|
48
|
-
DefaultDomain: string
|
|
49
|
-
// 是否开启了云接入服务
|
|
50
|
-
EnableService: boolean
|
|
51
|
-
// 云接入服务列表
|
|
52
|
-
ServiceSet: IService[]
|
|
53
|
-
}>('DescribeCloudBaseGWService', {
|
|
54
|
-
ServiceId: envId
|
|
55
|
-
})
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// 获取云接入服务列表
|
|
59
|
-
@preLazy()
|
|
60
|
-
public async getAccessList(options: IGetOptions = {}) {
|
|
61
|
-
const { path, name, offset, limit } = options
|
|
62
|
-
const { envId } = this.getEnvInfo()
|
|
63
|
-
|
|
64
|
-
return this.tcbService.request<{
|
|
65
|
-
RequestId: string
|
|
66
|
-
APISet: IApi[]
|
|
67
|
-
Total: number
|
|
68
|
-
Limit: number
|
|
69
|
-
Offset: number
|
|
70
|
-
EnableService: boolean
|
|
71
|
-
}>('DescribeCloudBaseGWAPI', {
|
|
72
|
-
ServiceId: envId,
|
|
73
|
-
Path: path,
|
|
74
|
-
Name: name,
|
|
75
|
-
Offset: offset,
|
|
76
|
-
limit: limit
|
|
77
|
-
})
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// 切换云接入服务开关:开启/关闭
|
|
81
|
-
@preLazy()
|
|
82
|
-
public async switchAuth(auth: boolean) {
|
|
83
|
-
const { envId } = this.getEnvInfo()
|
|
84
|
-
return this.tcbService.request<{
|
|
85
|
-
Count: number
|
|
86
|
-
RequestId: string
|
|
87
|
-
}>('ModifyCloudBaseGWPrivilege', {
|
|
88
|
-
ServiceId: envId,
|
|
89
|
-
EnableService: auth,
|
|
90
|
-
Options: [
|
|
91
|
-
{
|
|
92
|
-
Key: 'serviceswitch',
|
|
93
|
-
Value: auth ? 'true' : 'false'
|
|
94
|
-
}
|
|
95
|
-
]
|
|
96
|
-
})
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// 更新云接入路径鉴权
|
|
100
|
-
@preLazy()
|
|
101
|
-
public async switchPathAuth(options: IUpdateOptions) {
|
|
102
|
-
const { apiIds, auth } = options
|
|
103
|
-
const { envId } = this.getEnvInfo()
|
|
104
|
-
return this.tcbService.request<{
|
|
105
|
-
Count: number
|
|
106
|
-
RequestId: string
|
|
107
|
-
}>('ModifyCloudBaseGWAPIPrivilegeBatch', {
|
|
108
|
-
ServiceId: envId,
|
|
109
|
-
APIIdSet: apiIds,
|
|
110
|
-
Options: [
|
|
111
|
-
{
|
|
112
|
-
Key: 'authswitch',
|
|
113
|
-
Value: auth ? 'true' : 'false'
|
|
114
|
-
}
|
|
115
|
-
]
|
|
116
|
-
})
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// 删除云接入服务
|
|
120
|
-
@preLazy()
|
|
121
|
-
public async deleteAccess(options: IDeleteOptions) {
|
|
122
|
-
const { name, type = 1, apiId } = options
|
|
123
|
-
const { envId } = this.getEnvInfo()
|
|
124
|
-
|
|
125
|
-
return this.tcbService.request<IResponseInfo>('DeleteCloudBaseGWAPI', {
|
|
126
|
-
ServiceId: envId,
|
|
127
|
-
Name: name,
|
|
128
|
-
Type: type,
|
|
129
|
-
APIId: apiId
|
|
130
|
-
})
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
// 添加自定义域名
|
|
134
|
-
@preLazy()
|
|
135
|
-
public async addCustomDomain(options: IDomainOptions) {
|
|
136
|
-
const { domain, certId } = options
|
|
137
|
-
const { envId } = this.getEnvInfo()
|
|
138
|
-
|
|
139
|
-
return this.tcbService.request<IResponseInfo>('BindCloudBaseGWDomain', {
|
|
140
|
-
Domain: domain,
|
|
141
|
-
ServiceId: envId,
|
|
142
|
-
CertId: certId
|
|
143
|
-
})
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// 删除自定义域名
|
|
147
|
-
@preLazy()
|
|
148
|
-
public async deleteCustomDomain(domain: string) {
|
|
149
|
-
const { envId } = this.getEnvInfo()
|
|
150
|
-
|
|
151
|
-
return this.tcbService.request<IResponseInfo>('DeleteCloudBaseGWDomain', {
|
|
152
|
-
Domain: domain,
|
|
153
|
-
ServiceId: envId
|
|
154
|
-
})
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
private getEnvInfo() {
|
|
158
|
-
const envConfig = this.environment.lazyEnvironmentConfig
|
|
159
|
-
const appId = envConfig.Storages[0]?.AppId
|
|
160
|
-
const { proxy } = this.environment.cloudBaseContext
|
|
161
|
-
|
|
162
|
-
return {
|
|
163
|
-
appId,
|
|
164
|
-
proxy,
|
|
165
|
-
envId: envConfig.EnvId
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
}
|