-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(camGroup): add camGroup service
- Loading branch information
1 parent
6a2f0a7
commit 3c64503
Showing
9 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export default { | ||
camGroup: 'camGroups', | ||
camPolicy: 'camPolicies', | ||
ccn: 'ccns', | ||
ccnAttachment: 'ccnAttachments', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export default { | ||
camGroup: 'camGroup', | ||
camPolicy: 'camPolicy', | ||
camUser: 'camUser', | ||
ccn: 'ccn', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import * as tencentcloud from 'tencentcloud-sdk-nodejs' | ||
import { ClientConfig } from 'tencentcloud-sdk-nodejs/tencentcloud/common/interface' | ||
import CloudGraph from '@cloudgraph/sdk' | ||
import groupBy from 'lodash/groupBy' | ||
import isEmpty from 'lodash/isEmpty' | ||
import { GroupInfo } from 'tencentcloud-sdk-nodejs/tencentcloud/services/cam/v20190116/cam_models' | ||
import loggerText from '../../properties/logger' | ||
import { TencentServiceInput } from '../../types' | ||
import { initTestEndpoint, generateTencentErrorLog } from '../../utils' | ||
import { GLOBAL_REGION } from '../../config/constants' | ||
|
||
const lt = { ...loggerText } | ||
const { logger } = CloudGraph | ||
export const serviceName = 'CamGroup' | ||
const apiEndpoint = initTestEndpoint(serviceName) | ||
|
||
export interface RawTencentCamGroup extends GroupInfo { | ||
id: string | ||
region: string | ||
} | ||
|
||
export default async ({ | ||
config, | ||
}: TencentServiceInput): Promise<{ | ||
[region: string]: RawTencentCamGroup[] | ||
}> => | ||
new Promise(async resolve => { | ||
const camGroupList: RawTencentCamGroup[] = [] | ||
|
||
try { | ||
const CamClient = tencentcloud.cam.v20190116.Client | ||
const clientConfig: ClientConfig = { credential: config, profile: { httpProfile: { endpoint: apiEndpoint } } } | ||
const cam = new CamClient(clientConfig) | ||
|
||
const response = await cam.ListGroups(null) | ||
|
||
if (response && !isEmpty(response.GroupInfo)) { | ||
for (const instance of response.GroupInfo) { | ||
camGroupList.push({ | ||
id: `${instance.GroupId}`, | ||
...instance, | ||
region: GLOBAL_REGION, | ||
}) | ||
} | ||
} | ||
} catch (error) { | ||
generateTencentErrorLog(serviceName, 'cam:ListGroups', error) | ||
} | ||
|
||
logger.debug(lt.foundResources(serviceName, camGroupList.length)) | ||
resolve(groupBy(camGroupList, 'region')) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { TencentCamGroup } from '../../types/generated' | ||
import { RawTencentCamGroup } from './data' | ||
|
||
export default ({ | ||
service, | ||
}: { | ||
service: RawTencentCamGroup | ||
}): TencentCamGroup => { | ||
const { | ||
id, | ||
region, | ||
GroupName: name, | ||
CreateTime: createTime, | ||
Remark: remark | ||
} = service | ||
|
||
return { | ||
id, | ||
region, | ||
name, | ||
createTime, | ||
remark, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Service } from '@cloudgraph/sdk' | ||
import BaseService from '../base' | ||
import format from './format' | ||
import getData from './data' | ||
import { getMutation } from '../../utils' | ||
import services from '../../enums/services' | ||
import schemasMap from '../../enums/schemasMap' | ||
|
||
export default class TencentCamGroup extends BaseService implements Service { | ||
format = format.bind(this) | ||
|
||
getData = getData.bind(this) | ||
|
||
mutation = getMutation(schemasMap[services.camGroup]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
type tencentCamGroup implements tencentBaseService @key(fields: "id") { | ||
name: String @search(by: [hash, regexp]) | ||
createTime: String @search(by: [hash, regexp]) | ||
remark: String @search(by: [hash, regexp]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters