Skip to content

Commit c6162a6

Browse files
feat(camUser): add camUser service add region global
1 parent fa2c3b8 commit c6162a6

3 files changed

Lines changed: 20 additions & 19 deletions

File tree

src/enums/regions.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export const regionMap = {
2+
global: 'global',
23
southeastAsiaPacific1: 'ap-bangkok',
34
southeastAsiaPacific2: 'ap-jakarta',
45
northChina: 'ap-beijing',
@@ -23,6 +24,7 @@ export const regionMap = {
2324
}
2425

2526
const {
27+
global,
2628
southeastAsiaPacific1,
2729
southeastAsiaPacific2,
2830
northChina,
@@ -47,6 +49,7 @@ const {
4749
} = regionMap
4850

4951
export default [
52+
global,
5053
southeastAsiaPacific1,
5154
southeastAsiaPacific2,
5255
northChina,

src/services/camUser/data.ts

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { SubAccountInfo } from 'tencentcloud-sdk-nodejs/tencentcloud/services/ca
77
import loggerText from '../../properties/logger'
88
import { TencentServiceInput } from '../../types'
99
import { initTestEndpoint, generateTencentErrorLog } from '../../utils'
10+
import { regionMap } from '../../enums/regions'
1011

1112
const lt = { ...loggerText }
1213
const { logger } = CloudGraph
@@ -19,35 +20,33 @@ export interface RawTencentCamUser extends SubAccountInfo {
1920
}
2021

2122
export default async ({
22-
regions,
2323
config,
2424
}: TencentServiceInput): Promise<{
2525
[region: string]: RawTencentCamUser[]
2626
}> =>
2727
new Promise(async resolve => {
2828
const camUserList: RawTencentCamUser[] = []
2929

30-
for (const region of regions.split(',')) {
31-
try {
32-
const CamClient = tencentcloud.cam.v20190116.Client
33-
const clientConfig: ClientConfig = { credential: config, region, profile: { httpProfile: { endpoint: apiEndpoint } } }
34-
const cam = new CamClient(clientConfig)
30+
try {
31+
const CamClient = tencentcloud.cam.v20190116.Client
32+
const clientConfig: ClientConfig = { credential: config, profile: { httpProfile: { endpoint: apiEndpoint } } }
33+
const cam = new CamClient(clientConfig)
3534

36-
const response = await cam.ListUsers(null)
35+
const response = await cam.ListUsers(null)
3736

38-
if (response && !isEmpty(response.Data)) {
39-
for (const instance of response.Data) {
40-
camUserList.push({
41-
id: `${region}-${instance.Uid}`,
42-
...instance,
43-
region,
44-
})
45-
}
37+
if (response && !isEmpty(response.Data)) {
38+
for (const instance of response.Data) {
39+
camUserList.push({
40+
id: `${instance.Uid}`,
41+
...instance,
42+
region: regionMap.global,
43+
})
4644
}
47-
} catch (error) {
48-
generateTencentErrorLog(serviceName, 'cam:ListUsers', error)
4945
}
46+
} catch (error) {
47+
generateTencentErrorLog(serviceName, 'cam:ListUsers', error)
5048
}
49+
5150
logger.debug(lt.foundResources(serviceName, camUserList.length))
5251
resolve(groupBy(camUserList, 'region'))
5352
})

src/services/camUser/format.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@ import { RawTencentCamUser } from './data'
33

44
export default ({
55
service,
6-
region,
76
}: {
87
service: RawTencentCamUser
9-
region: string
108
}): TencentCamUser=> {
119
const {
1210
id,
11+
region,
1312
Uin: uin,
1413
Name: name,
1514
NickName: nickName,

0 commit comments

Comments
 (0)