Skip to content

Commit d3dee73

Browse files
Serverlesstencentdarminzhou
and
darminzhou
authored
fix: tags判断传空时不操作资源标签 (#284)
Co-authored-by: darminzhou <[email protected]>
1 parent 8668909 commit d3dee73

File tree

7 files changed

+91
-78
lines changed

7 files changed

+91
-78
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/modules/apigw/index.ts

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -152,15 +152,17 @@ export default class Apigw {
152152
}
153153

154154
try {
155-
const { tags = [] } = inputs;
156-
await this.tagClient.deployResourceTags({
157-
tags: tags.map(({ key, value }) => ({ TagKey: key, TagValue: value })),
158-
resourceId: serviceId,
159-
serviceType: ApiServiceType.apigw,
160-
resourcePrefix: 'service',
161-
});
162-
if (tags.length > 0) {
163-
outputs.tags = tags;
155+
const { tags } = inputs;
156+
if (tags) {
157+
await this.tagClient.deployResourceTags({
158+
tags: tags.map(({ key, value }) => ({ TagKey: key, TagValue: value })),
159+
resourceId: serviceId,
160+
serviceType: ApiServiceType.apigw,
161+
resourcePrefix: 'service',
162+
});
163+
if (tags.length > 0) {
164+
outputs.tags = tags;
165+
}
164166
}
165167
} catch (e) {
166168
console.log(`[TAG] ${e.message}`);
@@ -299,19 +301,18 @@ export default class Apigw {
299301
apiList,
300302
};
301303

302-
const { tags = [] } = inputs;
303-
if (tags.length > 0) {
304-
const deployedTags = await this.tagClient.deployResourceTags({
304+
const { tags } = inputs;
305+
if (tags) {
306+
await this.tagClient.deployResourceTags({
305307
tags: tags.map(({ key, value }) => ({ TagKey: key, TagValue: value })),
306308
resourceId: serviceId,
307309
serviceType: ApiServiceType.apigw,
308310
resourcePrefix: 'service',
309311
});
310312

311-
outputs.tags = deployedTags.map((item) => ({
312-
key: item.TagKey,
313-
value: item.TagValue!,
314-
}));
313+
if (tags.length > 0) {
314+
outputs.tags = tags;
315+
}
315316
}
316317

317318
// return this.formatApigwOutputs(outputs);

src/modules/cdn/index.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -240,15 +240,17 @@ export default class Cdn {
240240
}
241241

242242
try {
243-
const { tags = [] } = inputs;
244-
await this.tagClient.deployResourceTags({
245-
tags: tags.map(({ key, value }) => ({ TagKey: key, TagValue: value })),
246-
resourceId: Domain,
247-
serviceType: ApiServiceType.cdn,
248-
resourcePrefix: 'domain',
249-
});
250-
if (tags.length > 0) {
251-
outputs.tags = tags;
243+
const { tags } = inputs;
244+
if (tags) {
245+
await this.tagClient.deployResourceTags({
246+
tags: tags.map(({ key, value }) => ({ TagKey: key, TagValue: value })),
247+
resourceId: Domain,
248+
serviceType: ApiServiceType.cdn,
249+
resourcePrefix: 'domain',
250+
});
251+
if (tags.length > 0) {
252+
outputs.tags = tags;
253+
}
252254
}
253255
} catch (e) {
254256
console.log(`[TAG] ${e.message}`);

src/modules/cfs/index.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,18 @@ export default class CFS {
102102
}
103103

104104
try {
105-
const { tags = [] } = inputs;
106-
await this.tagClient.deployResourceTags({
107-
tags: tags.map((item) => ({ TagKey: item.key, TagValue: item.value })),
108-
serviceType: ApiServiceType.cfs,
109-
resourcePrefix: 'filesystem',
110-
resourceId: outputs.fileSystemId!,
111-
});
112-
113-
if (tags.length > 0) {
114-
outputs.tags = tags;
105+
const { tags } = inputs;
106+
if (tags) {
107+
await this.tagClient.deployResourceTags({
108+
tags: tags.map((item) => ({ TagKey: item.key, TagValue: item.value })),
109+
serviceType: ApiServiceType.cfs,
110+
resourcePrefix: 'filesystem',
111+
resourceId: outputs.fileSystemId!,
112+
});
113+
114+
if (tags.length > 0) {
115+
outputs.tags = tags;
116+
}
115117
}
116118
} catch (e) {
117119
console.log(`[TAG] ${e.message}`);

src/modules/cynosdb/index.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -160,16 +160,18 @@ export default class Cynosdb {
160160
}));
161161

162162
try {
163-
const { tags = [] } = inputs;
164-
await this.tagClient.deployResourceTags({
165-
tags: tags.map(({ key, value }) => ({ TagKey: key, TagValue: value })),
166-
resourceId: outputs.clusterId!,
167-
serviceType: ApiServiceType.cynosdb,
168-
resourcePrefix: 'instance',
169-
});
170-
171-
if (tags.length > 0) {
172-
outputs.tags = tags;
163+
const { tags } = inputs;
164+
if (tags) {
165+
await this.tagClient.deployResourceTags({
166+
tags: tags.map(({ key, value }) => ({ TagKey: key, TagValue: value })),
167+
resourceId: outputs.clusterId!,
168+
serviceType: ApiServiceType.cynosdb,
169+
resourcePrefix: 'instance',
170+
});
171+
172+
if (tags.length > 0) {
173+
outputs.tags = tags;
174+
}
173175
}
174176
} catch (e) {
175177
console.log(`[TAG] ${e.message}`);

src/modules/postgresql/index.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -131,16 +131,18 @@ export default class Postgresql {
131131
}
132132

133133
try {
134-
const { tags = [] } = inputs;
135-
await this.tagClient.deployResourceTags({
136-
tags: tags.map(({ key, value }) => ({ TagKey: key, TagValue: value })),
137-
resourceId: dbDetail.DBInstanceId,
138-
serviceType: ApiServiceType.postgres,
139-
resourcePrefix: 'DBInstanceId',
140-
});
141-
142-
if (tags.length > 0) {
143-
outputs.tags = tags;
134+
const { tags } = inputs;
135+
if (tags) {
136+
await this.tagClient.deployResourceTags({
137+
tags: tags.map(({ key, value }) => ({ TagKey: key, TagValue: value })),
138+
resourceId: dbDetail.DBInstanceId,
139+
serviceType: ApiServiceType.postgres,
140+
resourcePrefix: 'DBInstanceId',
141+
});
142+
143+
if (tags.length > 0) {
144+
outputs.tags = tags;
145+
}
144146
}
145147
} catch (e) {
146148
console.log(`[TAG] ${e.message}`);

src/modules/vpc/index.ts

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ export default class Vpc {
3434
enableMulticast,
3535
dnsServers,
3636
domainName,
37-
tags = [],
38-
subnetTags = [],
37+
tags,
38+
subnetTags,
3939
enableSubnetBroadcast,
4040
} = inputs;
4141

@@ -78,15 +78,17 @@ export default class Vpc {
7878
vId = res.VpcId;
7979
}
8080

81-
try {
82-
await this.tagClient.deployResourceTags({
83-
tags: tags.map(({ key, value }) => ({ TagKey: key, TagValue: value })),
84-
resourceId: vId,
85-
serviceType: ApiServiceType.vpc,
86-
resourcePrefix: 'vpc',
87-
});
88-
} catch (e) {
89-
console.log(`[TAG] ${e.message}`);
81+
if (tags) {
82+
try {
83+
await this.tagClient.deployResourceTags({
84+
tags: tags.map(({ key, value }) => ({ TagKey: key, TagValue: value })),
85+
resourceId: vId,
86+
serviceType: ApiServiceType.vpc,
87+
resourcePrefix: 'vpc',
88+
});
89+
} catch (e) {
90+
console.log(`[TAG] ${e.message}`);
91+
}
9092
}
9193

9294
return vId;
@@ -139,16 +141,18 @@ export default class Vpc {
139141
}
140142
}
141143

142-
const subnetTagList = subnetTags.length > 0 ? subnetTags : tags;
143-
try {
144-
await this.tagClient.deployResourceTags({
145-
tags: subnetTagList.map(({ key, value }) => ({ TagKey: key, TagValue: value })),
146-
resourceId: sId,
147-
serviceType: ApiServiceType.vpc,
148-
resourcePrefix: 'subnet',
149-
});
150-
} catch (e) {
151-
console.log(`[TAG] ${e.message}`);
144+
const subnetTagList = subnetTags ? subnetTags : tags;
145+
if (subnetTagList) {
146+
try {
147+
await this.tagClient.deployResourceTags({
148+
tags: subnetTagList.map(({ key, value }) => ({ TagKey: key, TagValue: value })),
149+
resourceId: sId,
150+
serviceType: ApiServiceType.vpc,
151+
resourcePrefix: 'subnet',
152+
});
153+
} catch (e) {
154+
console.log(`[TAG] ${e.message}`);
155+
}
152156
}
153157
return sId;
154158
};
@@ -170,7 +174,7 @@ export default class Vpc {
170174
subnetName,
171175
};
172176

173-
if (tags.length > 0) {
177+
if (tags && tags.length > 0) {
174178
outputs.tags = tags;
175179
}
176180

0 commit comments

Comments
 (0)