Skip to content

Commit be0d033

Browse files
authored
fix: remove resource tag bug (#219)
* fix: remove resource tag bug * chore: update vpc test * fix(cynosdb): password remove @
1 parent 641da88 commit be0d033

File tree

8 files changed

+57
-52
lines changed

8 files changed

+57
-52
lines changed

__tests__/tag.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ describe('Tag', () => {
88
SecretKey: process.env.TENCENT_SECRET_KEY,
99
};
1010
const functionName = 'serverless-unit-test';
11-
const tagItem = { TagKey: 'slstest1', TagValue: 'slstest1' };
11+
const tagItem = { TagKey: 'serverless-test', TagValue: 'serverless-test' };
1212
const commonInputs: TagDeployInputs = {
1313
resourceIds: [`default/function/${functionName}`],
1414
resourcePrefix: 'namespace',

src/modules/apigw/index.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,19 +123,19 @@ export default class Apigw {
123123
outputs.usagePlan = usagePlan;
124124
}
125125

126-
const { tags = [] } = inputs;
127-
if (tags.length > 0) {
128-
const deployedTags = await this.tagClient.deployResourceTags({
126+
try {
127+
const { tags = [] } = inputs;
128+
await this.tagClient.deployResourceTags({
129129
tags: tags.map(({ key, value }) => ({ TagKey: key, TagValue: value })),
130130
resourceId: serviceId,
131131
serviceType: ApiServiceType.apigw,
132132
resourcePrefix: 'service',
133133
});
134-
135-
outputs.tags = deployedTags.map((item) => ({
136-
key: item.TagKey,
137-
value: item.TagValue!,
138-
}));
134+
if (tags.length > 0) {
135+
outputs.tags = tags;
136+
}
137+
} catch (e) {
138+
console.log(`[TAG] ${e.message}`);
139139
}
140140

141141
return outputs;

src/modules/cdn/index.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export default class Cdn {
6767
/** 部署 CDN */
6868
async deploy(inputs: CdnDeployInputs) {
6969
await openCdnService(this.capi);
70-
const { oldState = {}, tags = [] } = inputs;
70+
const { oldState = {} } = inputs;
7171
delete inputs.oldState;
7272
const pascalInputs = pascalCaseProps(inputs);
7373

@@ -235,19 +235,21 @@ export default class Cdn {
235235
}
236236
}
237237

238-
if (tags.length > 0) {
239-
const deployedTags = await this.tagClient.deployResourceTags({
238+
try {
239+
const { tags = [] } = inputs;
240+
await this.tagClient.deployResourceTags({
240241
tags: tags.map(({ key, value }) => ({ TagKey: key, TagValue: value })),
241242
resourceId: Domain,
242243
serviceType: ApiServiceType.cdn,
243244
resourcePrefix: 'domain',
244245
});
245-
246-
outputs.tags = deployedTags.map((item) => ({
247-
key: item.TagKey,
248-
value: item.TagValue!,
249-
}));
246+
if (tags.length > 0) {
247+
outputs.tags = tags;
248+
}
249+
} catch (e) {
250+
console.log(`[TAG] ${e.message}`);
250251
}
252+
251253
console.log(`CDN deploy success to domain: ${pascalInputs.Domain}`);
252254
};
253255

src/modules/cfs/index.ts

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { TagData } from './../tag/interface';
21
import { RegionType } from './../interface';
32
import { CreateCfsParams } from './utils';
43
import { CapiCredentials, ApiServiceType } from '../interface';
@@ -102,22 +101,20 @@ export default class CFS {
102101
outputs.fileSystemId = FileSystemId;
103102
}
104103

105-
if (inputs.tags) {
106-
try {
107-
const tags = await this.tagClient.deployResourceTags({
108-
tags: inputs.tags.map((item) => ({ TagKey: item.key, TagValue: item.value })),
109-
serviceType: ApiServiceType.cfs,
110-
resourcePrefix: 'filesystem',
111-
resourceId: outputs.fileSystemId!,
112-
});
113-
114-
outputs.tags = tags.map((item: TagData) => ({
115-
key: item.TagKey,
116-
value: item.TagValue,
117-
}));
118-
} catch (e) {
119-
console.log(`Deploy cfs tags error: ${e.message}`);
104+
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;
120115
}
116+
} catch (e) {
117+
console.log(`[TAG] ${e.message}`);
121118
}
122119

123120
return outputs;

src/modules/cynosdb/index.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ export default class Cynosdb {
6767
autoPause = 'yes',
6868
autoPauseDelay = 3600, // default 1h
6969
enablePublicAccess,
70-
tags = [],
7170
} = inputs;
7271

7372
const outputs: CynosdbDeployOutputs = {
@@ -160,19 +159,20 @@ export default class Cynosdb {
160159
status: item.Status,
161160
}));
162161

163-
// create/update tags
164-
if (tags.length > 0) {
165-
const deployedTags = await this.tagClient.deployResourceTags({
162+
try {
163+
const { tags = [] } = inputs;
164+
await this.tagClient.deployResourceTags({
166165
tags: tags.map(({ key, value }) => ({ TagKey: key, TagValue: value })),
167166
resourceId: outputs.clusterId!,
168167
serviceType: ApiServiceType.cynosdb,
169168
resourcePrefix: 'instance',
170169
});
171170

172-
outputs.tags = deployedTags.map((item) => ({
173-
key: item.TagKey,
174-
value: item.TagValue!,
175-
}));
171+
if (tags.length > 0) {
172+
outputs.tags = tags;
173+
}
174+
} catch (e) {
175+
console.log(`[TAG] ${e.message}`);
176176
}
177177

178178
return outputs;

src/modules/cynosdb/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const PWD_CHARS =
1515
export function generatePwd(length = 8) {
1616
const ALPHABET = 'abcdefghijklmnopqrstuvwxyz';
1717
const NUMBER = '0123456789';
18-
const SPECIAL = '~!@#$%^&*_-';
18+
const SPECIAL = '~!#$%^&*_-';
1919

2020
let password = '';
2121
let character = '';
@@ -52,7 +52,7 @@ export function isValidPwd(password: string) {
5252
const numStr = '0123456789';
5353
const lowerCaseLetter = 'abcdefghijklmnopqrstuvwxyz';
5454
const upperCaseLetter = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
55-
const specStr = "~!@#$%^&*_-+=`|\\(){}[]:;'<>,.?/";
55+
const specStr = "~!#$%^&*_-+=`|\\(){}[]:;'<>,.?/";
5656

5757
let numFlag = 0;
5858
let lowerCaseFlag = 0;

src/modules/postgresql/index.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ export default class Postgresql {
4949
dBCharset,
5050
extranetAccess,
5151
vpcConfig,
52-
tags = [],
5352
} = inputs;
5453

5554
const outputs: PostgresqlDeployOutputs = {
@@ -131,18 +130,20 @@ export default class Postgresql {
131130
outputs.public = formatPgUrl(extranetInfo, accountInfo, dbName);
132131
}
133132

134-
if (tags.length > 0) {
135-
const deployedTags = await this.tagClient.deployResourceTags({
133+
try {
134+
const { tags = [] } = inputs;
135+
await this.tagClient.deployResourceTags({
136136
tags: tags.map(({ key, value }) => ({ TagKey: key, TagValue: value })),
137137
resourceId: dbDetail.DBInstanceId,
138138
serviceType: ApiServiceType.postgres,
139139
resourcePrefix: 'DBInstanceId',
140140
});
141141

142-
outputs.tags = deployedTags.map((item) => ({
143-
key: item.TagKey,
144-
value: item.TagValue!,
145-
}));
142+
if (tags.length > 0) {
143+
outputs.tags = tags;
144+
}
145+
} catch (e) {
146+
console.log(`[TAG] ${e.message}`);
146147
}
147148

148149
return outputs;

src/modules/vpc/index.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,17 @@ export default class Vpc {
7878
vId = res.VpcId;
7979
}
8080

81-
if (tags.length > 0) {
81+
try {
8282
await this.tagClient.deployResourceTags({
8383
tags: tags.map(({ key, value }) => ({ TagKey: key, TagValue: value })),
8484
resourceId: vId,
8585
serviceType: ApiServiceType.vpc,
8686
resourcePrefix: 'vpc',
8787
});
88+
} catch (e) {
89+
console.log(`[TAG] ${e.message}`);
8890
}
91+
8992
return vId;
9093
};
9194

@@ -137,13 +140,15 @@ export default class Vpc {
137140
}
138141

139142
const subnetTagList = subnetTags.length > 0 ? subnetTags : tags;
140-
if (subnetTagList.length > 0) {
143+
try {
141144
await this.tagClient.deployResourceTags({
142145
tags: subnetTagList.map(({ key, value }) => ({ TagKey: key, TagValue: value })),
143146
resourceId: sId,
144147
serviceType: ApiServiceType.vpc,
145148
resourcePrefix: 'subnet',
146149
});
150+
} catch (e) {
151+
console.log(`[TAG] ${e.message}`);
147152
}
148153
return sId;
149154
};

0 commit comments

Comments
 (0)