From d3dee73237b5412987dbf77898cc67122aed5498 Mon Sep 17 00:00:00 2001 From: Serverlesstencent <111848527+Serverlesstencent@users.noreply.github.com> Date: Wed, 2 Nov 2022 16:23:06 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20tags=E5=88=A4=E6=96=AD=E4=BC=A0?= =?UTF-8?q?=E7=A9=BA=E6=97=B6=E4=B8=8D=E6=93=8D=E4=BD=9C=E8=B5=84=E6=BA=90?= =?UTF-8?q?=E6=A0=87=E7=AD=BE=20(#284)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: darminzhou --- package-lock.json | 2 +- src/modules/apigw/index.ts | 33 ++++++++++++----------- src/modules/cdn/index.ts | 20 +++++++------- src/modules/cfs/index.ts | 22 ++++++++------- src/modules/cynosdb/index.ts | 22 ++++++++------- src/modules/postgresql/index.ts | 22 ++++++++------- src/modules/vpc/index.ts | 48 ++++++++++++++++++--------------- 7 files changed, 91 insertions(+), 78 deletions(-) diff --git a/package-lock.json b/package-lock.json index ad53716..b905b76 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "tencent-component-toolkit", - "version": "2.18.1", + "version": "2.24.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/src/modules/apigw/index.ts b/src/modules/apigw/index.ts index e213ef6..4885223 100644 --- a/src/modules/apigw/index.ts +++ b/src/modules/apigw/index.ts @@ -152,15 +152,17 @@ export default class Apigw { } try { - const { tags = [] } = inputs; - await this.tagClient.deployResourceTags({ - tags: tags.map(({ key, value }) => ({ TagKey: key, TagValue: value })), - resourceId: serviceId, - serviceType: ApiServiceType.apigw, - resourcePrefix: 'service', - }); - if (tags.length > 0) { - outputs.tags = tags; + const { tags } = inputs; + if (tags) { + await this.tagClient.deployResourceTags({ + tags: tags.map(({ key, value }) => ({ TagKey: key, TagValue: value })), + resourceId: serviceId, + serviceType: ApiServiceType.apigw, + resourcePrefix: 'service', + }); + if (tags.length > 0) { + outputs.tags = tags; + } } } catch (e) { console.log(`[TAG] ${e.message}`); @@ -299,19 +301,18 @@ export default class Apigw { apiList, }; - const { tags = [] } = inputs; - if (tags.length > 0) { - const deployedTags = await this.tagClient.deployResourceTags({ + const { tags } = inputs; + if (tags) { + await this.tagClient.deployResourceTags({ tags: tags.map(({ key, value }) => ({ TagKey: key, TagValue: value })), resourceId: serviceId, serviceType: ApiServiceType.apigw, resourcePrefix: 'service', }); - outputs.tags = deployedTags.map((item) => ({ - key: item.TagKey, - value: item.TagValue!, - })); + if (tags.length > 0) { + outputs.tags = tags; + } } // return this.formatApigwOutputs(outputs); diff --git a/src/modules/cdn/index.ts b/src/modules/cdn/index.ts index 4bfa9b0..01f58af 100644 --- a/src/modules/cdn/index.ts +++ b/src/modules/cdn/index.ts @@ -240,15 +240,17 @@ export default class Cdn { } try { - const { tags = [] } = inputs; - await this.tagClient.deployResourceTags({ - tags: tags.map(({ key, value }) => ({ TagKey: key, TagValue: value })), - resourceId: Domain, - serviceType: ApiServiceType.cdn, - resourcePrefix: 'domain', - }); - if (tags.length > 0) { - outputs.tags = tags; + const { tags } = inputs; + if (tags) { + await this.tagClient.deployResourceTags({ + tags: tags.map(({ key, value }) => ({ TagKey: key, TagValue: value })), + resourceId: Domain, + serviceType: ApiServiceType.cdn, + resourcePrefix: 'domain', + }); + if (tags.length > 0) { + outputs.tags = tags; + } } } catch (e) { console.log(`[TAG] ${e.message}`); diff --git a/src/modules/cfs/index.ts b/src/modules/cfs/index.ts index 3975173..ec4e8fc 100644 --- a/src/modules/cfs/index.ts +++ b/src/modules/cfs/index.ts @@ -102,16 +102,18 @@ export default class CFS { } try { - const { tags = [] } = inputs; - await this.tagClient.deployResourceTags({ - tags: tags.map((item) => ({ TagKey: item.key, TagValue: item.value })), - serviceType: ApiServiceType.cfs, - resourcePrefix: 'filesystem', - resourceId: outputs.fileSystemId!, - }); - - if (tags.length > 0) { - outputs.tags = tags; + const { tags } = inputs; + if (tags) { + await this.tagClient.deployResourceTags({ + tags: tags.map((item) => ({ TagKey: item.key, TagValue: item.value })), + serviceType: ApiServiceType.cfs, + resourcePrefix: 'filesystem', + resourceId: outputs.fileSystemId!, + }); + + if (tags.length > 0) { + outputs.tags = tags; + } } } catch (e) { console.log(`[TAG] ${e.message}`); diff --git a/src/modules/cynosdb/index.ts b/src/modules/cynosdb/index.ts index 2049158..0b9a4cb 100644 --- a/src/modules/cynosdb/index.ts +++ b/src/modules/cynosdb/index.ts @@ -160,16 +160,18 @@ export default class Cynosdb { })); try { - const { tags = [] } = inputs; - await this.tagClient.deployResourceTags({ - tags: tags.map(({ key, value }) => ({ TagKey: key, TagValue: value })), - resourceId: outputs.clusterId!, - serviceType: ApiServiceType.cynosdb, - resourcePrefix: 'instance', - }); - - if (tags.length > 0) { - outputs.tags = tags; + const { tags } = inputs; + if (tags) { + await this.tagClient.deployResourceTags({ + tags: tags.map(({ key, value }) => ({ TagKey: key, TagValue: value })), + resourceId: outputs.clusterId!, + serviceType: ApiServiceType.cynosdb, + resourcePrefix: 'instance', + }); + + if (tags.length > 0) { + outputs.tags = tags; + } } } catch (e) { console.log(`[TAG] ${e.message}`); diff --git a/src/modules/postgresql/index.ts b/src/modules/postgresql/index.ts index 699dc93..ffeb70c 100644 --- a/src/modules/postgresql/index.ts +++ b/src/modules/postgresql/index.ts @@ -131,16 +131,18 @@ export default class Postgresql { } try { - const { tags = [] } = inputs; - await this.tagClient.deployResourceTags({ - tags: tags.map(({ key, value }) => ({ TagKey: key, TagValue: value })), - resourceId: dbDetail.DBInstanceId, - serviceType: ApiServiceType.postgres, - resourcePrefix: 'DBInstanceId', - }); - - if (tags.length > 0) { - outputs.tags = tags; + const { tags } = inputs; + if (tags) { + await this.tagClient.deployResourceTags({ + tags: tags.map(({ key, value }) => ({ TagKey: key, TagValue: value })), + resourceId: dbDetail.DBInstanceId, + serviceType: ApiServiceType.postgres, + resourcePrefix: 'DBInstanceId', + }); + + if (tags.length > 0) { + outputs.tags = tags; + } } } catch (e) { console.log(`[TAG] ${e.message}`); diff --git a/src/modules/vpc/index.ts b/src/modules/vpc/index.ts index d0aadd3..11d36ed 100644 --- a/src/modules/vpc/index.ts +++ b/src/modules/vpc/index.ts @@ -34,8 +34,8 @@ export default class Vpc { enableMulticast, dnsServers, domainName, - tags = [], - subnetTags = [], + tags, + subnetTags, enableSubnetBroadcast, } = inputs; @@ -78,15 +78,17 @@ export default class Vpc { vId = res.VpcId; } - try { - await this.tagClient.deployResourceTags({ - tags: tags.map(({ key, value }) => ({ TagKey: key, TagValue: value })), - resourceId: vId, - serviceType: ApiServiceType.vpc, - resourcePrefix: 'vpc', - }); - } catch (e) { - console.log(`[TAG] ${e.message}`); + if (tags) { + try { + await this.tagClient.deployResourceTags({ + tags: tags.map(({ key, value }) => ({ TagKey: key, TagValue: value })), + resourceId: vId, + serviceType: ApiServiceType.vpc, + resourcePrefix: 'vpc', + }); + } catch (e) { + console.log(`[TAG] ${e.message}`); + } } return vId; @@ -139,16 +141,18 @@ export default class Vpc { } } - const subnetTagList = subnetTags.length > 0 ? subnetTags : tags; - try { - await this.tagClient.deployResourceTags({ - tags: subnetTagList.map(({ key, value }) => ({ TagKey: key, TagValue: value })), - resourceId: sId, - serviceType: ApiServiceType.vpc, - resourcePrefix: 'subnet', - }); - } catch (e) { - console.log(`[TAG] ${e.message}`); + const subnetTagList = subnetTags ? subnetTags : tags; + if (subnetTagList) { + try { + await this.tagClient.deployResourceTags({ + tags: subnetTagList.map(({ key, value }) => ({ TagKey: key, TagValue: value })), + resourceId: sId, + serviceType: ApiServiceType.vpc, + resourcePrefix: 'subnet', + }); + } catch (e) { + console.log(`[TAG] ${e.message}`); + } } return sId; }; @@ -170,7 +174,7 @@ export default class Vpc { subnetName, }; - if (tags.length > 0) { + if (tags && tags.length > 0) { outputs.tags = tags; } From e91c2ecf57c93c623b423d0e2d65d01bbfdfba8a Mon Sep 17 00:00:00 2001 From: slsplus Date: Wed, 2 Nov 2022 08:23:51 +0000 Subject: [PATCH 2/2] chore(release): version 2.24.2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## [2.24.2](https://github.com/serverless-tencent/tencent-component-toolkit/compare/v2.24.1...v2.24.2) (2022-11-02) ### Bug Fixes * tags判断传空时不操作资源标签 ([#284](https://github.com/serverless-tencent/tencent-component-toolkit/issues/284)) ([d3dee73](https://github.com/serverless-tencent/tencent-component-toolkit/commit/d3dee73237b5412987dbf77898cc67122aed5498)) --- CHANGELOG.md | 7 +++++++ package.json | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index be0450b..64d629d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## [2.24.2](https://github.com/serverless-tencent/tencent-component-toolkit/compare/v2.24.1...v2.24.2) (2022-11-02) + + +### Bug Fixes + +* tags判断传空时不操作资源标签 ([#284](https://github.com/serverless-tencent/tencent-component-toolkit/issues/284)) ([d3dee73](https://github.com/serverless-tencent/tencent-component-toolkit/commit/d3dee73237b5412987dbf77898cc67122aed5498)) + ## [2.24.1](https://github.com/serverless-tencent/tencent-component-toolkit/compare/v2.24.0...v2.24.1) (2022-05-11) diff --git a/package.json b/package.json index 0fe6122..2faee77 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tencent-component-toolkit", - "version": "2.24.1", + "version": "2.24.2", "description": "Tencent component toolkit", "main": "lib/index.js", "types": "lib/index.d.ts",