@cloudbase/manager-node 4.2.3 → 4.2.4
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/package.json +4 -3
- package/lib/access/index.js +0 -141
- package/lib/access/types.js +0 -2
- package/lib/billing/index.js +0 -36
- package/lib/cam/index.js +0 -77
- package/lib/cloudBaseRun/index.js +0 -36
- package/lib/cloudBaseRun/types.js +0 -2
- package/lib/common/index.js +0 -39
- package/lib/constant.js +0 -51
- package/lib/context.js +0 -14
- package/lib/database/index.js +0 -244
- package/lib/debug.js +0 -34
- package/lib/env/index.js +0 -488
- package/lib/environment.js +0 -124
- package/lib/environmentManager.js +0 -44
- package/lib/error.js +0 -16
- package/lib/function/index.js +0 -1022
- package/lib/function/packer.js +0 -129
- package/lib/function/types.js +0 -2
- package/lib/hosting/index.js +0 -461
- package/lib/index.js +0 -83
- package/lib/interfaces/base.interface.js +0 -2
- package/lib/interfaces/billing.interface.js +0 -2
- package/lib/interfaces/cam.interface.js +0 -2
- package/lib/interfaces/flexdb.interface.js +0 -2
- package/lib/interfaces/function.interface.js +0 -2
- package/lib/interfaces/index.js +0 -19
- package/lib/interfaces/storage.interface.js +0 -2
- package/lib/interfaces/tcb.interface.js +0 -2
- package/lib/storage/index.js +0 -1037
- package/lib/third/index.js +0 -18
- package/lib/user/index.js +0 -136
- package/lib/user/types.js +0 -2
- package/lib/utils/auth.js +0 -97
- package/lib/utils/cloud-api-request.js +0 -205
- package/lib/utils/cloudbase-request.js +0 -69
- package/lib/utils/envLazy.js +0 -18
- package/lib/utils/fs.js +0 -64
- package/lib/utils/http-request.js +0 -44
- package/lib/utils/index.js +0 -103
- package/lib/utils/parallel.js +0 -69
- package/lib/utils/uuid.js +0 -18
- 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/types/access/index.d.ts +0 -38
- package/types/access/types.d.ts +0 -42
- package/types/billing/index.d.ts +0 -21
- package/types/cam/index.d.ts +0 -63
- package/types/cloudBaseRun/index.d.ts +0 -12
- package/types/cloudBaseRun/types.d.ts +0 -21
- package/types/common/index.d.ts +0 -18
- package/types/constant.d.ts +0 -37
- package/types/context.d.ts +0 -17
- package/types/database/index.d.ts +0 -66
- package/types/debug.d.ts +0 -1
- package/types/env/index.d.ts +0 -144
- package/types/environment.d.ts +0 -51
- package/types/environmentManager.d.ts +0 -13
- package/types/error.d.ts +0 -18
- package/types/function/index.d.ts +0 -379
- package/types/function/packer.d.ts +0 -37
- package/types/function/types.d.ts +0 -156
- package/types/hosting/index.d.ts +0 -253
- package/types/index.d.ts +0 -52
- package/types/interfaces/base.interface.d.ts +0 -7
- package/types/interfaces/billing.interface.d.ts +0 -18
- package/types/interfaces/cam.interface.d.ts +0 -24
- package/types/interfaces/flexdb.interface.d.ts +0 -67
- package/types/interfaces/function.interface.d.ts +0 -65
- package/types/interfaces/index.d.ts +0 -7
- package/types/interfaces/storage.interface.d.ts +0 -26
- package/types/interfaces/tcb.interface.d.ts +0 -305
- package/types/storage/index.d.ts +0 -324
- package/types/third/index.d.ts +0 -11
- package/types/user/index.d.ts +0 -52
- package/types/user/types.d.ts +0 -20
- package/types/utils/auth.d.ts +0 -8
- package/types/utils/cloud-api-request.d.ts +0 -21
- package/types/utils/cloudbase-request.d.ts +0 -14
- package/types/utils/envLazy.d.ts +0 -1
- package/types/utils/fs.d.ts +0 -7
- package/types/utils/http-request.d.ts +0 -2
- package/types/utils/index.d.ts +0 -20
- package/types/utils/parallel.d.ts +0 -17
- package/types/utils/uuid.d.ts +0 -2
package/lib/debug.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const index_1 = __importDefault(require("./index"));
|
|
7
|
-
// import { cloudBaseConfig } from '../test/config'
|
|
8
|
-
// const app = new CloudBase(cloudBaseConfig)
|
|
9
|
-
const app = new index_1.default({});
|
|
10
|
-
async function test() {
|
|
11
|
-
// const hosting = await app.hosting.getInfo()
|
|
12
|
-
// const { Bucket, Regoin } = hosting[0]
|
|
13
|
-
// const res = await app.storage.uploadFilesCustom({
|
|
14
|
-
// files: [
|
|
15
|
-
// {
|
|
16
|
-
// localPath: 'test/storage/test_data/data.txt',
|
|
17
|
-
// cloudPath: 'test/storage/test_data/data.txt'
|
|
18
|
-
// },
|
|
19
|
-
// {
|
|
20
|
-
// localPath: 'test/storage/test_data/download.txt',
|
|
21
|
-
// cloudPath: 'test/storage/test_data/download.txt'
|
|
22
|
-
// }
|
|
23
|
-
// ],
|
|
24
|
-
// region: Regoin,
|
|
25
|
-
// bucket: Bucket
|
|
26
|
-
// })
|
|
27
|
-
const res = await app.hosting.uploadFiles({
|
|
28
|
-
localPath: '/Users/wuyiqing/Desktop/cloudbase-demo/functions/node-sdk',
|
|
29
|
-
cloudPath: '',
|
|
30
|
-
onProgress: console.log
|
|
31
|
-
});
|
|
32
|
-
console.log(res);
|
|
33
|
-
}
|
|
34
|
-
test().catch(console.log);
|
package/lib/env/index.js
DELETED
|
@@ -1,488 +0,0 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.EnvService = void 0;
|
|
13
|
-
const cos_nodejs_sdk_v5_1 = __importDefault(require("cos-nodejs-sdk-v5"));
|
|
14
|
-
const util_1 = __importDefault(require("util"));
|
|
15
|
-
const error_1 = require("../error");
|
|
16
|
-
const utils_1 = require("../utils");
|
|
17
|
-
const cam_1 = require("../cam");
|
|
18
|
-
const constant_1 = require("../constant");
|
|
19
|
-
const billing_1 = require("../billing");
|
|
20
|
-
class EnvService {
|
|
21
|
-
constructor(environment) {
|
|
22
|
-
this.environment = environment;
|
|
23
|
-
this.envId = environment.getEnvId();
|
|
24
|
-
this.envType = environment.getEnvType();
|
|
25
|
-
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
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* 列出所有环境
|
|
31
|
-
* @returns {Promise<IListEnvRes>}
|
|
32
|
-
*/
|
|
33
|
-
async listEnvs() {
|
|
34
|
-
return this.cloudService.request('DescribeEnvs');
|
|
35
|
-
}
|
|
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
|
-
/**
|
|
239
|
-
* 拉取安全域名列表
|
|
240
|
-
* @returns {Promise<IAuthDomainsRes>}
|
|
241
|
-
*/
|
|
242
|
-
async getEnvAuthDomains() {
|
|
243
|
-
return this.cloudService.request('DescribeAuthDomains', {
|
|
244
|
-
EnvId: this.envId
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
/**
|
|
248
|
-
* 添加环境安全域名
|
|
249
|
-
* @param {string[]} domains 域名字符串数组
|
|
250
|
-
* @returns {Promise<IResponseInfo>}
|
|
251
|
-
*/
|
|
252
|
-
async createEnvDomain(domains) {
|
|
253
|
-
const res = await this.cloudService.request('CreateAuthDomain', {
|
|
254
|
-
EnvId: this.envId,
|
|
255
|
-
Domains: domains
|
|
256
|
-
});
|
|
257
|
-
// 添加 COS CORS 域名
|
|
258
|
-
const promises = domains.map(async (domain) => {
|
|
259
|
-
this.modifyCosCorsDomain(domain);
|
|
260
|
-
});
|
|
261
|
-
await Promise.all(promises);
|
|
262
|
-
return res;
|
|
263
|
-
}
|
|
264
|
-
/**
|
|
265
|
-
* 删除环境安全域名
|
|
266
|
-
* @param {string[]} domainIds 域名字符串数组
|
|
267
|
-
* @returns {Promise<IDeleteDomainRes>}
|
|
268
|
-
*/
|
|
269
|
-
async deleteEnvDomain(domains) {
|
|
270
|
-
// 根据域名获取域名 Id
|
|
271
|
-
const { Domains } = await this.getEnvAuthDomains();
|
|
272
|
-
const domainIds = Domains.filter(item => domains.includes(item.Domain)).map(item => item.Id);
|
|
273
|
-
const res = await this.cloudService.request('DeleteAuthDomain', {
|
|
274
|
-
EnvId: this.envId,
|
|
275
|
-
DomainIds: domainIds
|
|
276
|
-
});
|
|
277
|
-
// 删除 COS CORS 域名
|
|
278
|
-
const promises = domains.map(async (domain) => {
|
|
279
|
-
this.modifyCosCorsDomain(domain, true);
|
|
280
|
-
});
|
|
281
|
-
await Promise.all(promises);
|
|
282
|
-
return res;
|
|
283
|
-
}
|
|
284
|
-
/**
|
|
285
|
-
* 检查tcb服务是否开通
|
|
286
|
-
* @returns {Promise<ICheckTcbServiceRes>}
|
|
287
|
-
* @memberof CamService
|
|
288
|
-
*/
|
|
289
|
-
async checkTcbService() {
|
|
290
|
-
return this.cloudService.request('CheckTcbService', {});
|
|
291
|
-
}
|
|
292
|
-
/**
|
|
293
|
-
* 初始化TCB
|
|
294
|
-
* @returns {Promise<IResponseInfo>}
|
|
295
|
-
* @memberof EnvService
|
|
296
|
-
*/
|
|
297
|
-
async initTcb(param) {
|
|
298
|
-
let initParam = {};
|
|
299
|
-
if (param) {
|
|
300
|
-
initParam = Object.assign({}, param);
|
|
301
|
-
}
|
|
302
|
-
return this.cloudService.request('InitTcb', initParam);
|
|
303
|
-
}
|
|
304
|
-
/**
|
|
305
|
-
* 开通后付费套餐
|
|
306
|
-
* @param {string} envId
|
|
307
|
-
* @param {SOURCE} [source]
|
|
308
|
-
* @returns {Promise<ICreatePostpayRes>}
|
|
309
|
-
* @memberof EnvService
|
|
310
|
-
*/
|
|
311
|
-
async CreatePostpayPackage(envId, source) {
|
|
312
|
-
const realSource = source ? source : 'qcloud';
|
|
313
|
-
return this.cloudService.request('CreatePostpayPackage', {
|
|
314
|
-
EnvId: envId,
|
|
315
|
-
Source: realSource
|
|
316
|
-
});
|
|
317
|
-
}
|
|
318
|
-
/**
|
|
319
|
-
* 销毁环境
|
|
320
|
-
* @param {string} envId
|
|
321
|
-
* @returns {Promise<IResponseInfo>}
|
|
322
|
-
* @memberof EnvService
|
|
323
|
-
*/
|
|
324
|
-
async destroyEnv(envId) {
|
|
325
|
-
return this.cloudService.request('DestroyEnv', {
|
|
326
|
-
EnvId: envId
|
|
327
|
-
});
|
|
328
|
-
}
|
|
329
|
-
/**
|
|
330
|
-
* 获取环境信息
|
|
331
|
-
* @returns {Promise<IEnvInfoRes>}
|
|
332
|
-
*/
|
|
333
|
-
async getEnvInfo() {
|
|
334
|
-
// NOTE: DescribeEnv 接口废弃,需要使用 DescribeEnvs 接口
|
|
335
|
-
const params = {
|
|
336
|
-
EnvId: this.envId
|
|
337
|
-
};
|
|
338
|
-
if (this.envType === 'run') {
|
|
339
|
-
params.EnvType = 'run';
|
|
340
|
-
}
|
|
341
|
-
const { EnvList, RequestId } = await this.cloudService.request('DescribeEnvs', params);
|
|
342
|
-
return {
|
|
343
|
-
EnvInfo: (EnvList === null || EnvList === void 0 ? void 0 : EnvList.length) ? EnvList[0] : {},
|
|
344
|
-
RequestId
|
|
345
|
-
};
|
|
346
|
-
}
|
|
347
|
-
/**
|
|
348
|
-
* 修改环境名称
|
|
349
|
-
* @param {string} alias 环境名称
|
|
350
|
-
* @returns {Promise<IResponseInfo>}
|
|
351
|
-
*/
|
|
352
|
-
async updateEnvInfo(alias) {
|
|
353
|
-
return this.cloudService.request('ModifyEnv', {
|
|
354
|
-
EnvId: this.envId,
|
|
355
|
-
Alias: alias
|
|
356
|
-
});
|
|
357
|
-
}
|
|
358
|
-
/**
|
|
359
|
-
* 拉取登录配置列表
|
|
360
|
-
* @returns {Promise<IEnvLoginConfigRes>}
|
|
361
|
-
*/
|
|
362
|
-
async getLoginConfigList() {
|
|
363
|
-
return this.cloudService.request('DescribeLoginConfigs', {
|
|
364
|
-
EnvId: this.envId
|
|
365
|
-
});
|
|
366
|
-
}
|
|
367
|
-
/**
|
|
368
|
-
* 创建登录方式
|
|
369
|
-
* 'WECHAT-OPEN':微信开放平台
|
|
370
|
-
* 'WECHAT-PUBLIC':微信公众平台
|
|
371
|
-
* @param {('WECHAT-OPEN' | 'WECHAT-PUBLIC')} platform 'WECHAT-OPEN' | 'WECHAT-PUBLIC'
|
|
372
|
-
* @param {string} appId 微信 appId
|
|
373
|
-
* @param {string} appSecret 微信 appSecret
|
|
374
|
-
* @returns {Promise<IResponseInfo>}
|
|
375
|
-
*/
|
|
376
|
-
async createLoginConfig(platform, appId, appSecret) {
|
|
377
|
-
let finalAppSecret = appSecret;
|
|
378
|
-
if (platform === 'ANONYMOUS') {
|
|
379
|
-
finalAppSecret = 'anonymous';
|
|
380
|
-
}
|
|
381
|
-
return this.cloudService.request('CreateLoginConfig', {
|
|
382
|
-
EnvId: this.envId,
|
|
383
|
-
// 平台, “QQ" "WECHAT-OPEN" "WECHAT-PUBLIC"
|
|
384
|
-
Platform: platform,
|
|
385
|
-
PlatformId: appId,
|
|
386
|
-
PlatformSecret: finalAppSecret ? utils_1.rsaEncrypt(finalAppSecret) : undefined,
|
|
387
|
-
Status: 'ENABLE'
|
|
388
|
-
});
|
|
389
|
-
}
|
|
390
|
-
/**
|
|
391
|
-
* 更新登录方式配置
|
|
392
|
-
* @param {string} configId 配置 Id,从配置列表中获取
|
|
393
|
-
* @param {string} [status='ENABLE'] 是否启用 'ENABLE', 'DISABLE' ,可选
|
|
394
|
-
* @param {string} [appId=''] 微信 appId,可选
|
|
395
|
-
* @param {string} [appSecret=''] 微信 appSecret,可选
|
|
396
|
-
* @returns {Promise<IResponseInfo>}
|
|
397
|
-
*/
|
|
398
|
-
/* eslint-disable-next-line */
|
|
399
|
-
async updateLoginConfig(configId, status = 'ENABLE', appId = '', appSecret = '') {
|
|
400
|
-
const validStatus = ['ENABLE', 'DISABLE'];
|
|
401
|
-
let finalAppSecret = appSecret;
|
|
402
|
-
if (!validStatus.includes(status)) {
|
|
403
|
-
throw new error_1.CloudBaseError(`Invalid status value: ${status}. Only support 'ENABLE', 'DISABLE'`);
|
|
404
|
-
}
|
|
405
|
-
const params = {
|
|
406
|
-
EnvId: this.envId,
|
|
407
|
-
ConfigId: configId,
|
|
408
|
-
Status: status
|
|
409
|
-
};
|
|
410
|
-
if (appId === 'anonymous') {
|
|
411
|
-
finalAppSecret = 'anonymous';
|
|
412
|
-
}
|
|
413
|
-
appId && (params.PlatformId = appId);
|
|
414
|
-
finalAppSecret && (params.PlatformSecret = utils_1.rsaEncrypt(finalAppSecret));
|
|
415
|
-
return this.cloudService.request('UpdateLoginConfig', params);
|
|
416
|
-
}
|
|
417
|
-
// 创建自定义登录私钥
|
|
418
|
-
async createCustomLoginKeys() {
|
|
419
|
-
return this.cloudService.request('CreateCustomLoginKeys', {
|
|
420
|
-
EnvId: this.envId
|
|
421
|
-
});
|
|
422
|
-
}
|
|
423
|
-
// 获取 COS CORS 域名
|
|
424
|
-
async getCOSDomains() {
|
|
425
|
-
const cos = this.getCos();
|
|
426
|
-
const getBucketCors = util_1.default.promisify(cos.getBucketCors).bind(cos);
|
|
427
|
-
const { bucket, region } = this.getStorageConfig();
|
|
428
|
-
const res = await getBucketCors({
|
|
429
|
-
Bucket: bucket,
|
|
430
|
-
Region: region
|
|
431
|
-
});
|
|
432
|
-
return res.CORSRules;
|
|
433
|
-
}
|
|
434
|
-
// 添加 COS CORS 域名,和 Web 端行为保持一致
|
|
435
|
-
async modifyCosCorsDomain(domain, deleted = false) {
|
|
436
|
-
const cos = this.getCos();
|
|
437
|
-
const putBucketCors = util_1.default.promisify(cos.putBucketCors).bind(cos);
|
|
438
|
-
const { bucket, region } = this.getStorageConfig();
|
|
439
|
-
// 去掉原有此域名CORS配置
|
|
440
|
-
let corsRules = await this.getCOSDomains();
|
|
441
|
-
corsRules = corsRules.filter(item => {
|
|
442
|
-
return !(item.AllowedOrigins &&
|
|
443
|
-
item.AllowedOrigins.length === 2 &&
|
|
444
|
-
item.AllowedOrigins[0] === `http://${domain}` &&
|
|
445
|
-
item.AllowedOrigins[1] === `https://${domain}`);
|
|
446
|
-
});
|
|
447
|
-
if (!deleted) {
|
|
448
|
-
corsRules.push({
|
|
449
|
-
AllowedOrigin: [`http://${domain}`, `https://${domain}`],
|
|
450
|
-
AllowedMethod: ['GET', 'POST', 'PUT', 'DELETE', 'HEAD'],
|
|
451
|
-
AllowedHeader: ['*'],
|
|
452
|
-
ExposeHeader: ['Etag', 'Date'],
|
|
453
|
-
MaxAgeSeconds: '5'
|
|
454
|
-
});
|
|
455
|
-
}
|
|
456
|
-
await putBucketCors({
|
|
457
|
-
Bucket: bucket,
|
|
458
|
-
Region: region,
|
|
459
|
-
CORSRules: corsRules
|
|
460
|
-
});
|
|
461
|
-
}
|
|
462
|
-
getCos() {
|
|
463
|
-
const { secretId, secretKey, token } = this.environment.getAuthConfig();
|
|
464
|
-
return new cos_nodejs_sdk_v5_1.default({
|
|
465
|
-
SecretId: secretId,
|
|
466
|
-
SecretKey: secretKey,
|
|
467
|
-
SecurityToken: token
|
|
468
|
-
});
|
|
469
|
-
}
|
|
470
|
-
getStorageConfig() {
|
|
471
|
-
var _a;
|
|
472
|
-
const envConfig = this.environment.lazyEnvironmentConfig;
|
|
473
|
-
const storageConfig = (_a = envConfig === null || envConfig === void 0 ? void 0 : envConfig.Storages) === null || _a === void 0 ? void 0 : _a[0];
|
|
474
|
-
const { Region, Bucket } = storageConfig;
|
|
475
|
-
return {
|
|
476
|
-
env: envConfig.EnvId,
|
|
477
|
-
region: Region,
|
|
478
|
-
bucket: Bucket
|
|
479
|
-
};
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
__decorate([
|
|
483
|
-
utils_1.preLazy()
|
|
484
|
-
], EnvService.prototype, "createEnvDomain", null);
|
|
485
|
-
__decorate([
|
|
486
|
-
utils_1.preLazy()
|
|
487
|
-
], EnvService.prototype, "deleteEnvDomain", null);
|
|
488
|
-
exports.EnvService = EnvService;
|
package/lib/environment.js
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Environment = void 0;
|
|
4
|
-
const database_1 = require("./database");
|
|
5
|
-
const function_1 = require("./function");
|
|
6
|
-
const storage_1 = require("./storage");
|
|
7
|
-
const env_1 = require("./env");
|
|
8
|
-
const common_1 = require("./common");
|
|
9
|
-
const error_1 = require("./error");
|
|
10
|
-
const constant_1 = require("./constant");
|
|
11
|
-
const utils_1 = require("./utils");
|
|
12
|
-
const hosting_1 = require("./hosting");
|
|
13
|
-
const third_1 = require("./third");
|
|
14
|
-
const access_1 = require("./access");
|
|
15
|
-
const user_1 = require("./user");
|
|
16
|
-
const cloudBaseRun_1 = require("./cloudBaseRun");
|
|
17
|
-
class Environment {
|
|
18
|
-
constructor(context, envId) {
|
|
19
|
-
this.inited = false;
|
|
20
|
-
this.envId = envId;
|
|
21
|
-
this.cloudBaseContext = context;
|
|
22
|
-
this.envType = context.envType;
|
|
23
|
-
// 拉取当前环境 的环境信息 todo
|
|
24
|
-
this.functionService = new function_1.FunctionService(this);
|
|
25
|
-
this.databaseService = new database_1.DatabaseService(this);
|
|
26
|
-
this.storageService = new storage_1.StorageService(this);
|
|
27
|
-
this.envService = new env_1.EnvService(this);
|
|
28
|
-
this.hostingService = new hosting_1.HostingService(this);
|
|
29
|
-
this.thirdService = new third_1.ThirdService(this);
|
|
30
|
-
this.accessService = new access_1.AccessService(this);
|
|
31
|
-
this.userService = new user_1.UserService(this);
|
|
32
|
-
this.cloudBaseRunService = new cloudBaseRun_1.CloudBaseRunService(this);
|
|
33
|
-
}
|
|
34
|
-
async lazyInit() {
|
|
35
|
-
if (!this.inited) {
|
|
36
|
-
const envConfig = this.envService;
|
|
37
|
-
return envConfig.getEnvInfo().then(envInfo => {
|
|
38
|
-
this.lazyEnvironmentConfig = envInfo.EnvInfo;
|
|
39
|
-
if (!this.lazyEnvironmentConfig.EnvId) {
|
|
40
|
-
throw new error_1.CloudBaseError(`Environment ${this.envId} not found`);
|
|
41
|
-
}
|
|
42
|
-
this.inited = true;
|
|
43
|
-
return this.lazyEnvironmentConfig;
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
return this.lazyEnvironmentConfig;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
getEnvId() {
|
|
51
|
-
return this.envId;
|
|
52
|
-
}
|
|
53
|
-
getEnvType() {
|
|
54
|
-
return this.envType;
|
|
55
|
-
}
|
|
56
|
-
getStorageService() {
|
|
57
|
-
return this.storageService;
|
|
58
|
-
}
|
|
59
|
-
getDatabaseService() {
|
|
60
|
-
return this.databaseService;
|
|
61
|
-
}
|
|
62
|
-
getFunctionService() {
|
|
63
|
-
return this.functionService;
|
|
64
|
-
}
|
|
65
|
-
getEnvService() {
|
|
66
|
-
return this.envService;
|
|
67
|
-
}
|
|
68
|
-
getHostingService() {
|
|
69
|
-
return this.hostingService;
|
|
70
|
-
}
|
|
71
|
-
getThirdService() {
|
|
72
|
-
return this.thirdService;
|
|
73
|
-
}
|
|
74
|
-
getAccessService() {
|
|
75
|
-
return this.accessService;
|
|
76
|
-
}
|
|
77
|
-
getUserService() {
|
|
78
|
-
return this.userService;
|
|
79
|
-
}
|
|
80
|
-
getCloudBaseRunService() {
|
|
81
|
-
return this.cloudBaseRunService;
|
|
82
|
-
}
|
|
83
|
-
getCommonService(serviceType = 'tcb', serviceVersion) {
|
|
84
|
-
return new common_1.CommonService(this, serviceType, serviceVersion);
|
|
85
|
-
}
|
|
86
|
-
getServicesEnvInfo() {
|
|
87
|
-
const envConfig = this.envService;
|
|
88
|
-
return envConfig.getEnvInfo().then(envInfo => {
|
|
89
|
-
return envInfo.EnvInfo;
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
getAuthConfig() {
|
|
93
|
-
let { secretId, secretKey, token, proxy, region } = this.cloudBaseContext;
|
|
94
|
-
const envId = this.getEnvId();
|
|
95
|
-
if (!secretId || !secretKey) {
|
|
96
|
-
// 未主动传入密钥,从环境变量中读取
|
|
97
|
-
const envSecretId = utils_1.getEnvVar(constant_1.ENV_NAME.ENV_SECRETID);
|
|
98
|
-
const envSecretKey = utils_1.getEnvVar(constant_1.ENV_NAME.ENV_SECRETKEY);
|
|
99
|
-
const envToken = utils_1.getEnvVar(constant_1.ENV_NAME.ENV_SESSIONTOKEN);
|
|
100
|
-
if (!envSecretId || !envSecretKey) {
|
|
101
|
-
if (utils_1.getRuntime() === constant_1.RUN_ENV.SCF) {
|
|
102
|
-
throw new Error('missing authoration key, redeploy the function');
|
|
103
|
-
}
|
|
104
|
-
else {
|
|
105
|
-
throw new Error('missing secretId or secretKey of tencent cloud');
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
else {
|
|
109
|
-
secretId = envSecretId;
|
|
110
|
-
secretKey = envSecretKey;
|
|
111
|
-
token = envToken;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
return {
|
|
115
|
-
envId,
|
|
116
|
-
secretId,
|
|
117
|
-
secretKey,
|
|
118
|
-
token,
|
|
119
|
-
proxy,
|
|
120
|
-
region
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
exports.Environment = Environment;
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EnvironmentManager = void 0;
|
|
4
|
-
const environment_1 = require("./environment");
|
|
5
|
-
const constant_1 = require("./constant");
|
|
6
|
-
class EnvironmentManager {
|
|
7
|
-
constructor(context) {
|
|
8
|
-
this.envs = {};
|
|
9
|
-
this.currentEnv = null;
|
|
10
|
-
this.cloudBaseContext = context;
|
|
11
|
-
}
|
|
12
|
-
getCurrentEnv() {
|
|
13
|
-
if (!this.currentEnv) {
|
|
14
|
-
throw new Error(constant_1.ERROR.CURRENT_ENVIRONMENT_IS_NULL);
|
|
15
|
-
}
|
|
16
|
-
return this.currentEnv;
|
|
17
|
-
}
|
|
18
|
-
add(envId) {
|
|
19
|
-
if (!this.envs[envId]) {
|
|
20
|
-
this.envs[envId] = new environment_1.Environment(this.cloudBaseContext, envId);
|
|
21
|
-
}
|
|
22
|
-
if (!this.currentEnv) {
|
|
23
|
-
this.currentEnv = this.envs[envId];
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
remove(envId) {
|
|
27
|
-
this.envs[envId] = null;
|
|
28
|
-
delete this.envs[envId];
|
|
29
|
-
}
|
|
30
|
-
get(envId) {
|
|
31
|
-
return this.envs[envId] || null;
|
|
32
|
-
}
|
|
33
|
-
switchEnv(envId) {
|
|
34
|
-
const env = this.envs[envId];
|
|
35
|
-
if (env) {
|
|
36
|
-
this.currentEnv = env;
|
|
37
|
-
return true;
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
return false;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
exports.EnvironmentManager = EnvironmentManager;
|