Skip to content

Commit 6d1d224

Browse files
committed
fix: optimize code
1 parent 301c1f0 commit 6d1d224

File tree

9 files changed

+30
-24
lines changed

9 files changed

+30
-24
lines changed

src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const Vpc = require('./modules/vpc');
1212
const Cam = require('./modules/cam');
1313
const Metrics = require('./modules/metrics');
1414
const Layer = require('./modules/layer');
15+
const Cfs = require('./modules/cfs');
1516

1617
module.exports = {
1718
Apigw,
@@ -28,4 +29,5 @@ module.exports = {
2829
Cam,
2930
Metrics,
3031
Layer,
32+
Cfs,
3133
};

src/modules/cfs/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class CFS {
66
this.region = region || 'ap-guangzhou';
77
this.credentials = credentials;
88
this.capi = new Capi({
9-
Region: region,
9+
Region: this.region,
1010
SecretId: credentials.SecretId,
1111
SecretKey: credentials.SecretKey,
1212
Token: credentials.Token,

src/modules/layer/apis/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const utils = {
2121
});
2222
return res;
2323
} catch (e) {
24-
return {};
24+
return null;
2525
}
2626
},
2727

src/modules/layer/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class Layer {
77
this.region = region || 'ap-guangzhou';
88
this.credentials = credentials;
99
this.capi = new Capi({
10-
Region: region,
10+
Region: this.region,
1111
SecretId: credentials.SecretId,
1212
SecretKey: credentials.SecretKey,
1313
Token: credentials.Token,
@@ -67,7 +67,7 @@ class Layer {
6767
console.log(e);
6868
}
6969

70-
return {};
70+
return true;
7171
}
7272
}
7373

src/modules/postgresql/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Postgresql {
1313
this.region = region || 'ap-guangzhou';
1414
this.credentials = credentials;
1515
this.capi = new Capi({
16-
Region: region,
16+
Region: this.region,
1717
AppId: this.credentials.AppId,
1818
SecretId: this.credentials.SecretId,
1919
SecretKey: this.credentials.SecretKey,
@@ -74,11 +74,11 @@ class Postgresql {
7474
postgresInputs.SubnetId = vpcConfig.subnetId;
7575
}
7676
dbDetail = await createDbInstance(this.capi, postgresInputs);
77-
outputs.dBInstanceId = dbDetail.DBInstanceId;
7877
if (extranetAccess) {
7978
dbDetail = await toggleDbInstanceAccess(this.capi, dBInstanceName, extranetAccess);
8079
}
8180
}
81+
outputs.dBInstanceId = dbDetail.DBInstanceId;
8282

8383
const {
8484
DBInstanceNetInfo,

src/modules/scf/index.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -394,22 +394,21 @@ class Scf {
394394
let funcInfo = await this.getFunction(namespace, inputs.name);
395395
if (!funcInfo) {
396396
await this.createFunction(inputs);
397-
funcInfo = await this.getFunction(namespace, inputs.name);
398397
} else {
399398
await this.updateFunctionCode(inputs, funcInfo);
400399

401400
// should check function status is active, then continue
402401
await this.isOperationalStatus(namespace, inputs.name);
403402

404403
await this.updatefunctionConfigure(inputs, funcInfo);
405-
406-
// after updating function, get latest function info
407-
funcInfo = await this.getFunction(namespace, inputs.name);
408404
}
409405

410406
// should check function status is active, then continue
411407
await this.isOperationalStatus(namespace, inputs.name);
412408

409+
// after create/update function, get latest function info
410+
funcInfo = await this.getFunction(namespace, inputs.name);
411+
413412
const outputs = funcInfo;
414413
if (inputs.publish) {
415414
const { FunctionVersion } = await this.publishVersion({
@@ -506,6 +505,10 @@ class Scf {
506505

507506
await this.deleteFunction(namespace, functionName);
508507

508+
try {
509+
await this.isOperationalStatus(namespace, functionName);
510+
} catch (e) {}
511+
509512
if (inputs.Triggers) {
510513
for (let i = 0; i < inputs.Triggers.length; i++) {
511514
if (inputs.Triggers[i].serviceId) {
@@ -521,6 +524,8 @@ class Scf {
521524
}
522525

523526
console.log(`Remove function ${functionName} and it's triggers success`);
527+
528+
return true;
524529
}
525530

526531
async invoke(inputs = {}) {

src/modules/tag/apis.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const { ApiFactory } = require('../../utils/api');
22

3-
const ACTIONS = ['ModifyResourceTags'];
3+
const ACTIONS = ['ModifyResourceTags', 'DescribeResourceTags'];
44

55
const APIS = ApiFactory({
66
// debug: true,

src/modules/tag/index.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
const { Capi } = require('@tencent-sdk/capi');
22
const Apis = require('./apis');
3-
const { camelCaseProperty } = require('../../utils/index');
43

54
class Tag {
65
constructor(credentials = {}, region = 'ap-guangzhou') {
@@ -16,18 +15,19 @@ class Tag {
1615
}
1716

1817
async request({ Action, ...data }) {
19-
const result = await Apis[Action](this.capi, camelCaseProperty(data));
18+
const result = await Apis[Action](this.capi, data);
2019
return result;
2120
}
2221

23-
async addArray(body, tags, key) {
24-
let index = 0;
25-
for (const item in tags) {
26-
body[`${key}.${index}.TagKey`] = item;
27-
body[`${key}.${index}.TagValue`] = tags[item];
28-
index++;
29-
}
30-
return body;
22+
async getScfResourceTags(inputs) {
23+
const data = {
24+
Action: 'DescribeResourceTags',
25+
ResourcePrefix: 'namespace',
26+
ResourceId: `${inputs.namespace || 'default'}/function/${inputs.functionName}`,
27+
};
28+
29+
const { Rows } = await this.request(data);
30+
return Rows;
3131
}
3232

3333
async deploy(inputs = {}) {
@@ -45,9 +45,8 @@ class Tag {
4545
}));
4646
}
4747
if (Object.keys(deleteTags).length > 0) {
48-
tagsInputs.DeleteTags = Object.entries(deleteTags).map(([key, val]) => ({
48+
tagsInputs.DeleteTags = Object.keys(deleteTags).map((key) => ({
4949
TagKey: key,
50-
TagValue: val,
5150
}));
5251
}
5352

src/modules/vpc/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class Vpc {
77
this.region = region || 'ap-guangzhou';
88
this.credentials = credentials;
99
this.capi = new Capi({
10-
Region: region,
10+
Region: this.region,
1111
AppId: credentials.AppId,
1212
SecretId: credentials.SecretId,
1313
SecretKey: credentials.SecretKey,

0 commit comments

Comments
 (0)