1
- const { apigw} = require ( 'tencent-cloud-sdk' )
2
- const { uniqueArray} = require ( '../../utils/index' )
1
+ const { apigw } = require ( 'tencent-cloud-sdk' )
2
+ const { uniqueArray } = require ( '../../utils/index' )
3
3
4
4
class Apigw {
5
5
constructor ( credentials = { } , region ) {
@@ -55,8 +55,7 @@ class Apigw {
55
55
protocol : protocols
56
56
} )
57
57
}
58
- } catch ( e ) {
59
- }
58
+ } catch ( e ) { }
60
59
}
61
60
if ( ! exist ) {
62
61
const createData = await this . request ( {
@@ -77,7 +76,7 @@ class Apigw {
77
76
}
78
77
}
79
78
80
- async createOrUpdateApi ( { serviceId, endpoint} ) {
79
+ async createOrUpdateApi ( { serviceId, endpoint } ) {
81
80
const output = {
82
81
path : endpoint . path ,
83
82
method : endpoint . method ,
@@ -107,8 +106,8 @@ class Apigw {
107
106
const funcQualifier = endpoint . function . functionQualifier
108
107
? endpoint . function . functionQualifier
109
108
: '$LATEST'
110
- ? endpoint . function . functionQualifier
111
- : '$LATEST'
109
+ ? endpoint . function . functionQualifier
110
+ : '$LATEST'
112
111
113
112
if ( endpoint . protocol === 'WEBSOCKET' ) {
114
113
if ( ! endpoint . function . transportFunctionName ) {
@@ -152,7 +151,10 @@ class Apigw {
152
151
} )
153
152
if ( pathAPIList . apiIdStatusSet ) {
154
153
for ( let i = 0 ; i < pathAPIList . apiIdStatusSet . length ; i ++ ) {
155
- if ( pathAPIList . apiIdStatusSet [ i ] . method == endpoint . method && pathAPIList . apiIdStatusSet [ i ] . path == endpoint . path ) {
154
+ if (
155
+ pathAPIList . apiIdStatusSet [ i ] . method == endpoint . method &&
156
+ pathAPIList . apiIdStatusSet [ i ] . path == endpoint . path
157
+ ) {
156
158
endpoint . apiId = pathAPIList . apiIdStatusSet [ i ] . apiId
157
159
}
158
160
}
@@ -177,13 +179,11 @@ class Apigw {
177
179
output . apiId = endpoint . apiId
178
180
console . log ( `Service with id ${ output . apiId } updated.` )
179
181
}
180
- } catch ( e ) {
181
- }
182
+ } catch ( e ) { }
182
183
}
183
184
184
-
185
185
if ( ! exist ) {
186
- const { apiId} = await this . request ( {
186
+ const { apiId } = await this . request ( {
187
187
Action : 'CreateApi' ,
188
188
...apiInputs
189
189
} )
@@ -192,7 +192,7 @@ class Apigw {
192
192
console . log ( `API with id ${ output . apiId } created.` )
193
193
}
194
194
195
- const { internalDomain} = await this . request ( {
195
+ const { internalDomain } = await this . request ( {
196
196
Action : 'DescribeApi' ,
197
197
serviceId : serviceId ,
198
198
apiId : output . apiId
@@ -202,15 +202,15 @@ class Apigw {
202
202
return output
203
203
}
204
204
205
- async setupUsagePlanSecret ( { secretName, secretIds} ) {
205
+ async setupUsagePlanSecret ( { secretName, secretIds } ) {
206
206
const secretIdsOutput = {
207
207
created : false ,
208
208
secretIds
209
209
}
210
210
211
211
if ( secretIds . length === 0 ) {
212
212
console . log ( `Creating a new Secret key.` )
213
- const { secretId, secretKey} = await this . request ( {
213
+ const { secretId, secretKey } = await this . request ( {
214
214
Action : 'CreateApiKey' ,
215
215
secretName : secretName ,
216
216
type : 'auto'
@@ -222,7 +222,7 @@ class Apigw {
222
222
const uniqSecretIds = uniqueArray ( secretIds )
223
223
224
224
// get all secretId, check local secretId exists
225
- const { apiKeyStatusSet} = await this . request ( {
225
+ const { apiKeyStatusSet } = await this . request ( {
226
226
Action : 'DescribeApiKeysStatus' ,
227
227
secretIds : uniqSecretIds ,
228
228
limit : uniqSecretIds . length
@@ -259,7 +259,7 @@ class Apigw {
259
259
return secretIdsOutput
260
260
}
261
261
262
- async setupApiUsagePlan ( { usagePlan} ) {
262
+ async setupApiUsagePlan ( { usagePlan } ) {
263
263
const usageInputs = {
264
264
usagePlanName : usagePlan . usagePlanName || '' ,
265
265
usagePlanDesc : usagePlan . usagePlanDesc || '' ,
@@ -295,9 +295,9 @@ class Apigw {
295
295
/**
296
296
* get all unbound secretids
297
297
*/
298
- async getUnboundSecretIds ( { usagePlanId, secretIds} ) {
299
- const getAllBoundSecrets = async ( res = [ ] , { limit, offset = 0 } ) => {
300
- const { secretIdList} = await this . request ( {
298
+ async getUnboundSecretIds ( { usagePlanId, secretIds } ) {
299
+ const getAllBoundSecrets = async ( res = [ ] , { limit, offset = 0 } ) => {
300
+ const { secretIdList } = await this . request ( {
301
301
Action : 'DescribeUsagePlanSecretIds' ,
302
302
usagePlanId,
303
303
limit,
@@ -306,9 +306,9 @@ class Apigw {
306
306
if ( secretIdList . length < limit ) {
307
307
return res
308
308
}
309
- return getAllBoundSecrets ( res , { limit, offset : offset + secretIdList . length } )
309
+ return getAllBoundSecrets ( res , { limit, offset : offset + secretIdList . length } )
310
310
}
311
- const allBoundSecretObjs = await getAllBoundSecrets ( [ ] , { limit : 100 } )
311
+ const allBoundSecretObjs = await getAllBoundSecrets ( [ ] , { limit : 100 } )
312
312
const allBoundSecretIds = allBoundSecretObjs . map ( ( item ) => item . secretId )
313
313
const unboundSecretIds = secretIds . filter ( ( item ) => {
314
314
if ( allBoundSecretIds . indexOf ( item ) === - 1 ) {
@@ -321,8 +321,8 @@ class Apigw {
321
321
}
322
322
323
323
// bind custom domains
324
- async bindCustomDomain ( { serviceId, subDomain, inputs} ) {
325
- const { customDomains, oldState = { } } = inputs
324
+ async bindCustomDomain ( { serviceId, subDomain, inputs } ) {
325
+ const { customDomains, oldState = { } } = inputs
326
326
// 1. unbind all custom domain
327
327
const customDomainDetail = await this . request ( {
328
328
Action : 'DescribeServiceSubDomains' ,
@@ -333,7 +333,7 @@ class Apigw {
333
333
customDomainDetail . domainSet &&
334
334
customDomainDetail . domainSet . length > 0
335
335
) {
336
- const { domainSet = [ ] } = customDomainDetail
336
+ const { domainSet = [ ] } = customDomainDetail
337
337
// unbind all created domain
338
338
const stateDomains = oldState . customDomains || [ ]
339
339
for ( let i = 0 ; i < domainSet . length ; i ++ ) {
@@ -389,14 +389,14 @@ class Apigw {
389
389
390
390
// bind environment fo usage plan
391
391
async bindUsagePlanEnvironment ( {
392
- environment,
393
- bindType = 'API' ,
394
- serviceId,
395
- apiId,
396
- endpoint,
397
- usagePlan
398
- } ) {
399
- const { usagePlanList} = await this . request ( {
392
+ environment,
393
+ bindType = 'API' ,
394
+ serviceId,
395
+ apiId,
396
+ endpoint,
397
+ usagePlan
398
+ } ) {
399
+ const { usagePlanList } = await this . request ( {
400
400
Action : 'DescribeApiUsagePlan' ,
401
401
serviceId,
402
402
apiIds : [ apiId ]
@@ -424,17 +424,17 @@ class Apigw {
424
424
}
425
425
426
426
async deploy ( inputs ) {
427
- const { environment, oldState = { } } = inputs
427
+ const { environment, oldState = { } } = inputs
428
428
inputs . protocols = this . getProtocolString ( inputs . protocols )
429
429
430
- const { serviceId, serviceName, subDomain, serviceCreated} = await this . createOrUpdateService (
430
+ const { serviceId, serviceName, subDomain, serviceCreated } = await this . createOrUpdateService (
431
431
inputs
432
432
)
433
433
434
434
const apiList = [ ]
435
435
const stateApiList = oldState . apiList || [ ]
436
436
437
- const { endpoints} = inputs
437
+ const { endpoints } = inputs
438
438
for ( let i = 0 , len = endpoints . length ; i < len ; i ++ ) {
439
439
const endpoint = endpoints [ i ]
440
440
// if exist in state list, set created to be true
@@ -466,7 +466,7 @@ class Apigw {
466
466
// store in api list
467
467
curApi . usagePlan = usagePlan
468
468
469
- const { secretIds = [ ] } = endpoint . auth
469
+ const { secretIds = [ ] } = endpoint . auth
470
470
const secrets = await this . setupUsagePlanSecret ( {
471
471
secretName : endpoint . auth . secretName ,
472
472
secretIds
@@ -538,15 +538,15 @@ class Apigw {
538
538
}
539
539
540
540
async remove ( inputs ) {
541
- const { created, environment, serviceId, apiList, customDomains} = inputs
541
+ const { created, environment, serviceId, apiList, customDomains } = inputs
542
542
// 1. remove all apis
543
543
for ( let i = 0 ; i < apiList . length ; i ++ ) {
544
544
const curApi = apiList [ i ]
545
545
546
546
// 1. remove usage plan
547
547
if ( curApi . usagePlan ) {
548
548
// 1.1 unbind secrete ids
549
- const { secrets} = curApi . usagePlan
549
+ const { secrets } = curApi . usagePlan
550
550
if ( secrets && secrets . secretIds ) {
551
551
await this . request ( {
552
552
Action : 'UnBindSecretIds' ,
0 commit comments