@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/src/env/index.ts
DELETED
|
@@ -1,614 +0,0 @@
|
|
|
1
|
-
import COS from 'cos-nodejs-sdk-v5'
|
|
2
|
-
import Util from 'util'
|
|
3
|
-
import { Environment } from '../environment'
|
|
4
|
-
import {
|
|
5
|
-
IResponseInfo,
|
|
6
|
-
AuthDomain,
|
|
7
|
-
EnvInfo,
|
|
8
|
-
LoginConfigItem,
|
|
9
|
-
ICheckTcbServiceRes,
|
|
10
|
-
ICreatePostpayRes
|
|
11
|
-
} from '../interfaces'
|
|
12
|
-
import { CloudBaseError } from '../error'
|
|
13
|
-
import { guid6, rsaEncrypt, CloudService, preLazy } from '../utils'
|
|
14
|
-
import { CamService } from '../cam'
|
|
15
|
-
import { ROLE_NAME } from '../constant'
|
|
16
|
-
import { BillingService } from '../billing'
|
|
17
|
-
|
|
18
|
-
interface ICreateEnvParam {
|
|
19
|
-
name: string
|
|
20
|
-
paymentMode?: PAYMENT_MODE
|
|
21
|
-
channel?: QCLOUD_CHANNEL
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
interface ICreateEnvRes {
|
|
25
|
-
// 环境当前状态:NORMAL:正常可用 NOINITIALIZE:尚未初始化 INITIALIZING:初始化过程中
|
|
26
|
-
Status: 'NORMAL' | 'NOINITIALIZE' | 'INITIALIZING'
|
|
27
|
-
// 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。
|
|
28
|
-
RequestId: string
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
type PAYMENT_MODE = 'prepay' | 'postpay'
|
|
32
|
-
type SOURCE = 'miniapp' | 'qcloud'
|
|
33
|
-
type WX_CHANNEL = 'ide' | 'api'
|
|
34
|
-
type QCLOUD_CHANNEL = 'cocos' | 'qq' | 'cloudgame' | 'qc_console' | 'dcloud'
|
|
35
|
-
|
|
36
|
-
interface IDeleteDomainRes {
|
|
37
|
-
RequestId: string
|
|
38
|
-
Deleted: number
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
interface IAuthDomainsRes {
|
|
42
|
-
RequestId: string
|
|
43
|
-
Domains: AuthDomain[]
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
interface IListEnvRes {
|
|
47
|
-
RequestId: string
|
|
48
|
-
EnvList: EnvInfo[]
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
interface IEnvLoginConfigRes {
|
|
52
|
-
RequestId: string
|
|
53
|
-
ConfigList: LoginConfigItem[]
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
interface IInitParam {
|
|
57
|
-
Channel?: string
|
|
58
|
-
Source?: string
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export class EnvService {
|
|
62
|
-
private environment: Environment
|
|
63
|
-
private envId: string
|
|
64
|
-
private cloudService: CloudService
|
|
65
|
-
private camService: CamService
|
|
66
|
-
private billService: BillingService
|
|
67
|
-
private envType?: string
|
|
68
|
-
|
|
69
|
-
constructor(environment: Environment) {
|
|
70
|
-
this.environment = environment
|
|
71
|
-
this.envId = environment.getEnvId()
|
|
72
|
-
this.envType = environment.getEnvType()
|
|
73
|
-
this.cloudService = new CloudService(environment.cloudBaseContext, 'tcb', '2018-06-08')
|
|
74
|
-
this.camService = new CamService(environment.cloudBaseContext)
|
|
75
|
-
this.billService = new BillingService(environment.cloudBaseContext)
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* 列出所有环境
|
|
80
|
-
* @returns {Promise<IListEnvRes>}
|
|
81
|
-
*/
|
|
82
|
-
async listEnvs(): Promise<IListEnvRes> {
|
|
83
|
-
return this.cloudService.request('DescribeEnvs')
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* 创建新环境
|
|
88
|
-
* @param {string} name 环境名称
|
|
89
|
-
* @returns {Promise<ICreateEnvRes>}
|
|
90
|
-
*/
|
|
91
|
-
async createEnv(
|
|
92
|
-
param: ICreateEnvParam
|
|
93
|
-
): Promise<{
|
|
94
|
-
envId: string
|
|
95
|
-
}> {
|
|
96
|
-
// 1. 检查是否开通过TCB服务,若未开通,跳2检查角色 开通则跳5 创建环境
|
|
97
|
-
// 2. 查询tcb 角色是否绑定该账户
|
|
98
|
-
// 3. 若未绑定,则创建角色并绑定角色
|
|
99
|
-
// 4. 开通TCB服务
|
|
100
|
-
// 5. 创建环境
|
|
101
|
-
// 6. 购买环境,选择预付费 或 后付费 套餐
|
|
102
|
-
// 7. 若购买失败,将当前环境销毁,若购买成功,返回envId
|
|
103
|
-
const { name, paymentMode, channel = 'qc_console' } = param
|
|
104
|
-
|
|
105
|
-
// 1. 检查TCB服务是否开通
|
|
106
|
-
const { Initialized } = await this.checkTcbService()
|
|
107
|
-
|
|
108
|
-
if (!Initialized) {
|
|
109
|
-
// 跳2 查询TCB角色是否绑定
|
|
110
|
-
let hasTcbRole = false
|
|
111
|
-
try {
|
|
112
|
-
const res = await this.camService.getRole(ROLE_NAME.TCB)
|
|
113
|
-
hasTcbRole = true
|
|
114
|
-
} catch (e) {
|
|
115
|
-
// 判断是否为角色不存在错误
|
|
116
|
-
if (e.code !== 'InvalidParameter.RoleNotExist') {
|
|
117
|
-
throw e
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
if (!hasTcbRole) {
|
|
122
|
-
// 3. 当前账户没有tcbRole,创建角色并绑定
|
|
123
|
-
|
|
124
|
-
// 创建角色
|
|
125
|
-
const createRoleResult = await this.camService.createRole({
|
|
126
|
-
RoleName: ROLE_NAME.TCB,
|
|
127
|
-
Description:
|
|
128
|
-
'云开发(TCB)操作权限含在访问管理(CAM)创建角色,新增角色载体,给角色绑定策略;含读写对象存储(COS)数据;含读写无服务器云函数(SCF)数据;含读取云监控(Monitor)数据。',
|
|
129
|
-
PolicyDocument:
|
|
130
|
-
'{"version":"2.0","statement":[{"action":"sts:AssumeRole","effect":"allow","principal":{"service":["scf.qcloud.com","tcb.cloud.tencent.com", "cvm.qcloud.com"]}}]}'
|
|
131
|
-
})
|
|
132
|
-
|
|
133
|
-
const { RoleId } = createRoleResult
|
|
134
|
-
|
|
135
|
-
// 绑定角色策略
|
|
136
|
-
// await this.camService.attachRolePolicy({
|
|
137
|
-
// PolicyId: 8825032,
|
|
138
|
-
// AttachRoleName: ROLE_NAME.TCB
|
|
139
|
-
// })
|
|
140
|
-
|
|
141
|
-
await this.camService.attachRolePolicies({
|
|
142
|
-
RoleName: ROLE_NAME.TCB,
|
|
143
|
-
PolicyName: [
|
|
144
|
-
'QcloudAccessForTCBRole',
|
|
145
|
-
'QcloudAccessForTCBRoleInAccessCloudBaseRun'
|
|
146
|
-
]
|
|
147
|
-
})
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
// 4. 未开通则初始化TCB
|
|
151
|
-
await this.initTcb({ Channel: channel, Source: 'qcloud' })
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
// 5. 创建环境
|
|
155
|
-
|
|
156
|
-
const params: any = {
|
|
157
|
-
Alias: name,
|
|
158
|
-
EnvId: `${name}-${guid6()}`,
|
|
159
|
-
Source: 'qcloud'
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
if (channel) {
|
|
163
|
-
params.Channel = channel
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
const { EnvId } = await this.cloudService.request('CreateEnv', params)
|
|
167
|
-
|
|
168
|
-
const realPaymentMode = paymentMode ? paymentMode : 'postpay'
|
|
169
|
-
// 6. 购买环境
|
|
170
|
-
|
|
171
|
-
let prepayCreateDeal = false
|
|
172
|
-
let prepayPayDeal = false
|
|
173
|
-
let postpayDeal = false
|
|
174
|
-
let payError = null
|
|
175
|
-
|
|
176
|
-
if (realPaymentMode === 'prepay') {
|
|
177
|
-
// 预付费
|
|
178
|
-
// 1. 创建订单
|
|
179
|
-
// 2. 支付订单
|
|
180
|
-
|
|
181
|
-
const goods = [
|
|
182
|
-
{
|
|
183
|
-
GoodsCategoryId: 101183,
|
|
184
|
-
// action: 'purchase',
|
|
185
|
-
// currency: 'CNY',
|
|
186
|
-
RegionId: 1,
|
|
187
|
-
ZoneId: 0,
|
|
188
|
-
GoodsNum: 1,
|
|
189
|
-
ProjectId: 0,
|
|
190
|
-
PayMode: 1,
|
|
191
|
-
Platform: 1,
|
|
192
|
-
GoodsDetail: JSON.stringify({
|
|
193
|
-
productCode: 'p_tcb',
|
|
194
|
-
subProductCode: 'sp_tcb_basic',
|
|
195
|
-
resourceId: EnvId,
|
|
196
|
-
pid: 16677,
|
|
197
|
-
timeUnit: 'm',
|
|
198
|
-
timeSpan: 1,
|
|
199
|
-
tcb_cos: 1,
|
|
200
|
-
tcb_cdn: 1,
|
|
201
|
-
tcb_scf: 1,
|
|
202
|
-
tcb_mongodb: 1,
|
|
203
|
-
region: 'ap-shanghai',
|
|
204
|
-
zone: 'ap-shanghai-1',
|
|
205
|
-
source: 'qcloud',
|
|
206
|
-
envId: EnvId,
|
|
207
|
-
packageId: 'basic',
|
|
208
|
-
isAutoRenew: 'true',
|
|
209
|
-
tranType: 1,
|
|
210
|
-
productInfo: [
|
|
211
|
-
{
|
|
212
|
-
name: '套餐版本',
|
|
213
|
-
value: '基础版 1'
|
|
214
|
-
},
|
|
215
|
-
{
|
|
216
|
-
name: '存储空间',
|
|
217
|
-
value: '5GB'
|
|
218
|
-
},
|
|
219
|
-
{
|
|
220
|
-
name: 'CDN流量',
|
|
221
|
-
value: '5GB'
|
|
222
|
-
},
|
|
223
|
-
{
|
|
224
|
-
name: '云函数资源使用量',
|
|
225
|
-
value: '4万GBs'
|
|
226
|
-
},
|
|
227
|
-
{
|
|
228
|
-
name: '数据库容量',
|
|
229
|
-
value: '2GB'
|
|
230
|
-
},
|
|
231
|
-
{
|
|
232
|
-
name: '数据库同时连接数',
|
|
233
|
-
value: '20个'
|
|
234
|
-
}
|
|
235
|
-
]
|
|
236
|
-
})
|
|
237
|
-
}
|
|
238
|
-
]
|
|
239
|
-
|
|
240
|
-
let OrderIdsList = []
|
|
241
|
-
try {
|
|
242
|
-
const { OrderIds } = await this.billService.GenerateDeals(goods)
|
|
243
|
-
OrderIdsList = OrderIds
|
|
244
|
-
prepayCreateDeal = true
|
|
245
|
-
} catch (e) {
|
|
246
|
-
// 预付费下单失败
|
|
247
|
-
payError = e
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
if (prepayCreateDeal) {
|
|
251
|
-
// 下单成功
|
|
252
|
-
try {
|
|
253
|
-
// 购买环境套餐
|
|
254
|
-
const { OrderIds: succOrderIds } = await this.billService.PayDeals(OrderIdsList)
|
|
255
|
-
|
|
256
|
-
// 判断订单是否支付成功
|
|
257
|
-
if (succOrderIds[0] === OrderIdsList[0]) {
|
|
258
|
-
prepayPayDeal = true
|
|
259
|
-
} else {
|
|
260
|
-
throw new CloudBaseError('支付成功的订单号不一致')
|
|
261
|
-
}
|
|
262
|
-
} catch (e) {
|
|
263
|
-
// 预付费订单支付失败
|
|
264
|
-
payError = new CloudBaseError(
|
|
265
|
-
'预付费订单支付失败,请进入订单管理页面(https://console.cloud.tencent.com/deal)重新支付',
|
|
266
|
-
{
|
|
267
|
-
original: e
|
|
268
|
-
}
|
|
269
|
-
)
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
if (realPaymentMode === 'postpay') {
|
|
275
|
-
// 后付费
|
|
276
|
-
try {
|
|
277
|
-
const { TranId } = await this.CreatePostpayPackage(EnvId)
|
|
278
|
-
postpayDeal = true
|
|
279
|
-
} catch (e) {
|
|
280
|
-
payError = e
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
// 检查支付状态
|
|
285
|
-
// 1. 预付费下单失败 删除环境
|
|
286
|
-
// 2. 预付费下单成功过,支付订单失败,提示用户
|
|
287
|
-
// 3. 后付费开通失败 删除环境
|
|
288
|
-
if (realPaymentMode === 'prepay') {
|
|
289
|
-
if (!prepayCreateDeal) {
|
|
290
|
-
// 情形1
|
|
291
|
-
await this.destroyEnv(EnvId)
|
|
292
|
-
throw payError
|
|
293
|
-
} else {
|
|
294
|
-
if (!prepayPayDeal) {
|
|
295
|
-
// 情形2
|
|
296
|
-
throw payError
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
if (realPaymentMode === 'postpay') {
|
|
302
|
-
if (!postpayDeal) {
|
|
303
|
-
// 情形3
|
|
304
|
-
await this.destroyEnv(EnvId)
|
|
305
|
-
throw payError
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
// 成功返回envId
|
|
310
|
-
return {
|
|
311
|
-
envId: EnvId
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
/**
|
|
316
|
-
* 拉取安全域名列表
|
|
317
|
-
* @returns {Promise<IAuthDomainsRes>}
|
|
318
|
-
*/
|
|
319
|
-
public async getEnvAuthDomains(): Promise<IAuthDomainsRes> {
|
|
320
|
-
return this.cloudService.request('DescribeAuthDomains', {
|
|
321
|
-
EnvId: this.envId
|
|
322
|
-
})
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
/**
|
|
326
|
-
* 添加环境安全域名
|
|
327
|
-
* @param {string[]} domains 域名字符串数组
|
|
328
|
-
* @returns {Promise<IResponseInfo>}
|
|
329
|
-
*/
|
|
330
|
-
@preLazy()
|
|
331
|
-
public async createEnvDomain(domains: string[]): Promise<IResponseInfo> {
|
|
332
|
-
const res = await this.cloudService.request<IResponseInfo>('CreateAuthDomain', {
|
|
333
|
-
EnvId: this.envId,
|
|
334
|
-
Domains: domains
|
|
335
|
-
})
|
|
336
|
-
// 添加 COS CORS 域名
|
|
337
|
-
const promises = domains.map(async domain => {
|
|
338
|
-
this.modifyCosCorsDomain(domain)
|
|
339
|
-
})
|
|
340
|
-
await Promise.all(promises)
|
|
341
|
-
return res
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
/**
|
|
345
|
-
* 删除环境安全域名
|
|
346
|
-
* @param {string[]} domainIds 域名字符串数组
|
|
347
|
-
* @returns {Promise<IDeleteDomainRes>}
|
|
348
|
-
*/
|
|
349
|
-
@preLazy()
|
|
350
|
-
public async deleteEnvDomain(domains: string[]): Promise<IDeleteDomainRes> {
|
|
351
|
-
// 根据域名获取域名 Id
|
|
352
|
-
const { Domains } = await this.getEnvAuthDomains()
|
|
353
|
-
const domainIds = Domains.filter(item => domains.includes(item.Domain)).map(item => item.Id)
|
|
354
|
-
const res = await this.cloudService.request<IDeleteDomainRes>('DeleteAuthDomain', {
|
|
355
|
-
EnvId: this.envId,
|
|
356
|
-
DomainIds: domainIds
|
|
357
|
-
})
|
|
358
|
-
// 删除 COS CORS 域名
|
|
359
|
-
const promises = domains.map(async domain => {
|
|
360
|
-
this.modifyCosCorsDomain(domain, true)
|
|
361
|
-
})
|
|
362
|
-
await Promise.all(promises)
|
|
363
|
-
return res
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
/**
|
|
367
|
-
* 检查tcb服务是否开通
|
|
368
|
-
* @returns {Promise<ICheckTcbServiceRes>}
|
|
369
|
-
* @memberof CamService
|
|
370
|
-
*/
|
|
371
|
-
public async checkTcbService(): Promise<ICheckTcbServiceRes> {
|
|
372
|
-
return this.cloudService.request<ICheckTcbServiceRes>('CheckTcbService', {})
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
/**
|
|
376
|
-
* 初始化TCB
|
|
377
|
-
* @returns {Promise<IResponseInfo>}
|
|
378
|
-
* @memberof EnvService
|
|
379
|
-
*/
|
|
380
|
-
public async initTcb(param: IInitParam): Promise<IResponseInfo> {
|
|
381
|
-
let initParam = {}
|
|
382
|
-
if (param) {
|
|
383
|
-
initParam = { ...param }
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
return this.cloudService.request<IResponseInfo>('InitTcb', initParam)
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
/**
|
|
390
|
-
* 开通后付费套餐
|
|
391
|
-
* @param {string} envId
|
|
392
|
-
* @param {SOURCE} [source]
|
|
393
|
-
* @returns {Promise<ICreatePostpayRes>}
|
|
394
|
-
* @memberof EnvService
|
|
395
|
-
*/
|
|
396
|
-
public async CreatePostpayPackage(envId: string, source?: SOURCE): Promise<ICreatePostpayRes> {
|
|
397
|
-
const realSource = source ? source : 'qcloud'
|
|
398
|
-
return this.cloudService.request<ICreatePostpayRes>('CreatePostpayPackage', {
|
|
399
|
-
EnvId: envId,
|
|
400
|
-
Source: realSource
|
|
401
|
-
})
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
/**
|
|
405
|
-
* 销毁环境
|
|
406
|
-
* @param {string} envId
|
|
407
|
-
* @returns {Promise<IResponseInfo>}
|
|
408
|
-
* @memberof EnvService
|
|
409
|
-
*/
|
|
410
|
-
public async destroyEnv(envId: string): Promise<IResponseInfo> {
|
|
411
|
-
return this.cloudService.request<IResponseInfo>('DestroyEnv', {
|
|
412
|
-
EnvId: envId
|
|
413
|
-
})
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
/**
|
|
417
|
-
* 获取环境信息
|
|
418
|
-
* @returns {Promise<IEnvInfoRes>}
|
|
419
|
-
*/
|
|
420
|
-
public async getEnvInfo(): Promise<{
|
|
421
|
-
EnvInfo: EnvInfo
|
|
422
|
-
RequestId: string
|
|
423
|
-
}> {
|
|
424
|
-
// NOTE: DescribeEnv 接口废弃,需要使用 DescribeEnvs 接口
|
|
425
|
-
const params: any = {
|
|
426
|
-
EnvId: this.envId
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
if (this.envType === 'run') {
|
|
430
|
-
params.EnvType = 'run'
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
const { EnvList, RequestId } = await this.cloudService.request('DescribeEnvs', params)
|
|
434
|
-
|
|
435
|
-
return {
|
|
436
|
-
EnvInfo: EnvList?.length ? EnvList[0] : {},
|
|
437
|
-
RequestId
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
/**
|
|
442
|
-
* 修改环境名称
|
|
443
|
-
* @param {string} alias 环境名称
|
|
444
|
-
* @returns {Promise<IResponseInfo>}
|
|
445
|
-
*/
|
|
446
|
-
public async updateEnvInfo(alias: string): Promise<IResponseInfo> {
|
|
447
|
-
return this.cloudService.request('ModifyEnv', {
|
|
448
|
-
EnvId: this.envId,
|
|
449
|
-
Alias: alias
|
|
450
|
-
})
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
/**
|
|
454
|
-
* 拉取登录配置列表
|
|
455
|
-
* @returns {Promise<IEnvLoginConfigRes>}
|
|
456
|
-
*/
|
|
457
|
-
async getLoginConfigList(): Promise<IEnvLoginConfigRes> {
|
|
458
|
-
return this.cloudService.request('DescribeLoginConfigs', {
|
|
459
|
-
EnvId: this.envId
|
|
460
|
-
})
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
/**
|
|
464
|
-
* 创建登录方式
|
|
465
|
-
* 'WECHAT-OPEN':微信开放平台
|
|
466
|
-
* 'WECHAT-PUBLIC':微信公众平台
|
|
467
|
-
* @param {('WECHAT-OPEN' | 'WECHAT-PUBLIC')} platform 'WECHAT-OPEN' | 'WECHAT-PUBLIC'
|
|
468
|
-
* @param {string} appId 微信 appId
|
|
469
|
-
* @param {string} appSecret 微信 appSecret
|
|
470
|
-
* @returns {Promise<IResponseInfo>}
|
|
471
|
-
*/
|
|
472
|
-
async createLoginConfig(
|
|
473
|
-
platform: 'WECHAT-OPEN' | 'WECHAT-PUBLIC' | 'QQ' | 'ANONYMOUS' | 'USERNAME',
|
|
474
|
-
appId: string,
|
|
475
|
-
appSecret?: string
|
|
476
|
-
): Promise<IResponseInfo> {
|
|
477
|
-
let finalAppSecret = appSecret
|
|
478
|
-
|
|
479
|
-
if (platform === 'ANONYMOUS') {
|
|
480
|
-
finalAppSecret = 'anonymous'
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
return this.cloudService.request('CreateLoginConfig', {
|
|
484
|
-
EnvId: this.envId,
|
|
485
|
-
// 平台, “QQ" "WECHAT-OPEN" "WECHAT-PUBLIC"
|
|
486
|
-
Platform: platform,
|
|
487
|
-
PlatformId: appId,
|
|
488
|
-
PlatformSecret: finalAppSecret ? rsaEncrypt(finalAppSecret) : undefined,
|
|
489
|
-
Status: 'ENABLE'
|
|
490
|
-
})
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
/**
|
|
494
|
-
* 更新登录方式配置
|
|
495
|
-
* @param {string} configId 配置 Id,从配置列表中获取
|
|
496
|
-
* @param {string} [status='ENABLE'] 是否启用 'ENABLE', 'DISABLE' ,可选
|
|
497
|
-
* @param {string} [appId=''] 微信 appId,可选
|
|
498
|
-
* @param {string} [appSecret=''] 微信 appSecret,可选
|
|
499
|
-
* @returns {Promise<IResponseInfo>}
|
|
500
|
-
*/
|
|
501
|
-
/* eslint-disable-next-line */
|
|
502
|
-
async updateLoginConfig(
|
|
503
|
-
configId: string,
|
|
504
|
-
status = 'ENABLE',
|
|
505
|
-
appId = '',
|
|
506
|
-
appSecret = ''
|
|
507
|
-
): Promise<IResponseInfo> {
|
|
508
|
-
const validStatus = ['ENABLE', 'DISABLE']
|
|
509
|
-
let finalAppSecret = appSecret
|
|
510
|
-
|
|
511
|
-
if (!validStatus.includes(status)) {
|
|
512
|
-
throw new CloudBaseError(
|
|
513
|
-
`Invalid status value: ${status}. Only support 'ENABLE', 'DISABLE'`
|
|
514
|
-
)
|
|
515
|
-
}
|
|
516
|
-
const params: any = {
|
|
517
|
-
EnvId: this.envId,
|
|
518
|
-
ConfigId: configId,
|
|
519
|
-
Status: status
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
if (appId === 'anonymous') {
|
|
523
|
-
finalAppSecret = 'anonymous'
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
appId && (params.PlatformId = appId)
|
|
527
|
-
finalAppSecret && (params.PlatformSecret = rsaEncrypt(finalAppSecret))
|
|
528
|
-
|
|
529
|
-
return this.cloudService.request('UpdateLoginConfig', params)
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
// 创建自定义登录私钥
|
|
533
|
-
public async createCustomLoginKeys(): Promise<{
|
|
534
|
-
PrivateKey: string // 自定义签名私钥
|
|
535
|
-
KeyID: string // 私钥id
|
|
536
|
-
RequestId: string // 请求ID
|
|
537
|
-
}> {
|
|
538
|
-
return this.cloudService.request<{
|
|
539
|
-
PrivateKey: string // 自定义签名私钥
|
|
540
|
-
KeyID: string // 私钥id
|
|
541
|
-
RequestId: string // 请求ID
|
|
542
|
-
}>('CreateCustomLoginKeys', {
|
|
543
|
-
EnvId: this.envId
|
|
544
|
-
})
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
// 获取 COS CORS 域名
|
|
548
|
-
private async getCOSDomains() {
|
|
549
|
-
const cos = this.getCos()
|
|
550
|
-
const getBucketCors = Util.promisify(cos.getBucketCors).bind(cos)
|
|
551
|
-
const { bucket, region } = this.getStorageConfig()
|
|
552
|
-
|
|
553
|
-
const res = await getBucketCors({
|
|
554
|
-
Bucket: bucket,
|
|
555
|
-
Region: region
|
|
556
|
-
})
|
|
557
|
-
return res.CORSRules
|
|
558
|
-
}
|
|
559
|
-
|
|
560
|
-
// 添加 COS CORS 域名,和 Web 端行为保持一致
|
|
561
|
-
private async modifyCosCorsDomain(domain: string, deleted = false) {
|
|
562
|
-
const cos = this.getCos()
|
|
563
|
-
const putBucketCors = Util.promisify(cos.putBucketCors).bind(cos)
|
|
564
|
-
const { bucket, region } = this.getStorageConfig()
|
|
565
|
-
|
|
566
|
-
// 去掉原有此域名CORS配置
|
|
567
|
-
let corsRules = await this.getCOSDomains()
|
|
568
|
-
corsRules = corsRules.filter(item => {
|
|
569
|
-
return !(
|
|
570
|
-
item.AllowedOrigins &&
|
|
571
|
-
item.AllowedOrigins.length === 2 &&
|
|
572
|
-
item.AllowedOrigins[0] === `http://${domain}` &&
|
|
573
|
-
item.AllowedOrigins[1] === `https://${domain}`
|
|
574
|
-
)
|
|
575
|
-
})
|
|
576
|
-
|
|
577
|
-
if (!deleted) {
|
|
578
|
-
corsRules.push({
|
|
579
|
-
AllowedOrigin: [`http://${domain}`, `https://${domain}`],
|
|
580
|
-
AllowedMethod: ['GET', 'POST', 'PUT', 'DELETE', 'HEAD'],
|
|
581
|
-
AllowedHeader: ['*'],
|
|
582
|
-
ExposeHeader: ['Etag', 'Date'],
|
|
583
|
-
MaxAgeSeconds: '5'
|
|
584
|
-
})
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
await putBucketCors({
|
|
588
|
-
Bucket: bucket,
|
|
589
|
-
Region: region,
|
|
590
|
-
CORSRules: corsRules
|
|
591
|
-
})
|
|
592
|
-
}
|
|
593
|
-
|
|
594
|
-
private getCos() {
|
|
595
|
-
const { secretId, secretKey, token } = this.environment.getAuthConfig()
|
|
596
|
-
|
|
597
|
-
return new COS({
|
|
598
|
-
SecretId: secretId,
|
|
599
|
-
SecretKey: secretKey,
|
|
600
|
-
SecurityToken: token
|
|
601
|
-
})
|
|
602
|
-
}
|
|
603
|
-
|
|
604
|
-
private getStorageConfig() {
|
|
605
|
-
const envConfig = this.environment.lazyEnvironmentConfig
|
|
606
|
-
const storageConfig = envConfig?.Storages?.[0]
|
|
607
|
-
const { Region, Bucket } = storageConfig
|
|
608
|
-
return {
|
|
609
|
-
env: envConfig.EnvId,
|
|
610
|
-
region: Region,
|
|
611
|
-
bucket: Bucket
|
|
612
|
-
}
|
|
613
|
-
}
|
|
614
|
-
}
|