Skip to content

Commit c0013d0

Browse files
authored
Merge pull request #10 from cloudgraphdev/feature/CG-1120-add-tencent-cam-policy
feat(camPolicy): add tencent cam policy
2 parents c3b1747 + 3b8df16 commit c0013d0

File tree

10 files changed

+163
-9
lines changed

10 files changed

+163
-9
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,16 @@ CloudGraph Tencent Provider will ask you what regions you would like to crawl an
5656

5757
| Service | Relations |
5858
| ------------------- | ------------------- |
59+
| camPolicy | |
60+
| ccn | ccnAttachment |
61+
| ccnAttachment | ccn |
5962
| customerGateway | vpnConnection |
63+
| networkAcl | subnet, vpc |
6064
| routeTable | vpc, subnet |
6165
| securityGroup | |
6266
| securityGroupRule | |
63-
| ccn | ccnAttachment |
64-
| ccnAttachment | ccn |
65-
| networkAcl | subnet, vpc |
6667
| subnet | networkAcl, vpc, routeTable |
6768
| vpc | networkAcl, subnet, vpnGateway, routeTable, vpnConnection |
6869
| vpnConnection | vpc, vpnGateway, customerGateway |
6970
| vpnGateway | vpc, vpnGatewayRoute, vpnConnection |
7071
| vpnGatewayRoute | vpnGateway |
71-
| securityGroup | |

src/enums/schemasMap.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@ import services from './services'
44
* schemasMap is an object that contains schemas name by resource
55
*/
66
export default {
7-
[services.customerGateway]: 'tencentCustomerGateway',
8-
[services.routeTable]: 'tencentRouteTable',
9-
[services.securityGroup]: 'tencentSecurityGroup',
10-
[services.securityGroupRule]: 'tencentSecurityGroupRule',
7+
[services.camPolicy]: 'tencentCamPolicy',
118
[services.ccn]: 'tencentCcn',
129
[services.ccnAttachment]: 'tencentCcnAttachment',
10+
[services.customerGateway]: 'tencentCustomerGateway',
1311
[services.networkAcl]: 'tencentNetworkAcl',
12+
[services.routeTable]: 'tencentRouteTable',
1413
[services.securityGroup]: 'tencentSecurityGroup',
1514
[services.securityGroupRule]: 'tencentSecurityGroupRule',
1615
[services.subnet]: 'tencentSubnet',

src/enums/serviceAliases.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export default {
2+
camPolicy: 'camPolicies',
23
ccn: 'ccns',
34
ccnAttachment: 'ccnAttachments',
45
customerGateway: 'customerGateways',

src/enums/serviceMap.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import TencentVpc from '../services/vpc'
99
import TencentTag from '../services/tag'
1010
import TencentRouteTable from '../services/routeTable'
1111
import TencentVpnGateway from '../services/vpnGateway'
12+
import TencentCamPolicy from '../services/camPolicy'
1213
import TencentVpnGatewayRoute from '../services/vpnGatewayRoute'
1314
import TencentCustomerGateway from '../services/customerGateway'
1415
import TencentVpnConnection from '../services/vpnConnection'
@@ -18,6 +19,7 @@ import TencentVpnConnection from '../services/vpnConnection'
1819
* serviceMap is used by the serviceFactory to produce instances of service classes
1920
*/
2021
export default {
22+
[services.camPolicy]: TencentCamPolicy,
2123
[services.ccn]: TencentCcn,
2224
[services.ccnAttachment]: TencentCcnAttachment,
2325
[services.customerGateway]: TencentCustomerGateway,

src/enums/services.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
export default {
2+
camPolicy: 'camPolicy',
23
ccn: 'ccn',
34
ccnAttachment: 'ccnAttachment',
45
customerGateway: 'customerGateway',
5-
routeTable: 'routeTable',
66
networkAcl: 'networkAcl',
7+
routeTable: 'routeTable',
78
securityGroup: 'securityGroup',
89
securityGroupRule: 'securityGroupRule',
910
subnet: 'subnet',

src/services/camPolicy/data.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import * as tencentcloud from 'tencentcloud-sdk-nodejs'
2+
import { ClientConfig } from 'tencentcloud-sdk-nodejs/tencentcloud/common/interface'
3+
import CloudGraph from '@cloudgraph/sdk'
4+
import groupBy from 'lodash/groupBy'
5+
import isEmpty from 'lodash/isEmpty'
6+
import { StrategyInfo } from 'tencentcloud-sdk-nodejs/tencentcloud/services/cam/v20190116/cam_models'
7+
import cuid from 'cuid'
8+
import loggerText from '../../properties/logger'
9+
import { TencentServiceInput } from '../../types'
10+
import { initTestEndpoint, generateTencentErrorLog } from '../../utils'
11+
12+
const lt = { ...loggerText }
13+
const { logger } = CloudGraph
14+
export const serviceName = 'CamPolicy'
15+
const apiEndpoint = initTestEndpoint(serviceName)
16+
17+
export interface RawTencentCamPolicy extends StrategyInfo {
18+
id: string
19+
region: string
20+
}
21+
22+
export default async ({
23+
regions,
24+
config,
25+
}: TencentServiceInput): Promise<{
26+
[region: string]: RawTencentCamPolicy[]
27+
}> =>
28+
new Promise(async resolve => {
29+
const camPolicyList: RawTencentCamPolicy[] = []
30+
31+
for (const region of regions.split(',')) {
32+
try {
33+
const CamClient = tencentcloud.cam.v20190116.Client
34+
const clientConfig: ClientConfig = { credential: config, region, profile: { httpProfile: { endpoint: apiEndpoint } } }
35+
const cam = new CamClient(clientConfig)
36+
37+
const response = await cam.ListPolicies(null)
38+
39+
if (response && !isEmpty(response.List)) {
40+
for (const instance of response.List) {
41+
camPolicyList.push({
42+
id: cuid(),
43+
...instance,
44+
region,
45+
})
46+
}
47+
}
48+
} catch (error) {
49+
generateTencentErrorLog(serviceName, 'cam:ListPolicies', error)
50+
}
51+
}
52+
logger.debug(lt.foundResources(serviceName, camPolicyList.length))
53+
resolve(groupBy(camPolicyList, 'region'))
54+
})

src/services/camPolicy/format.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { TencentCamPolicy } from '../../types/generated'
2+
import { RawTencentCamPolicy } from './data'
3+
4+
export default ({
5+
service,
6+
region,
7+
}: {
8+
service: RawTencentCamPolicy
9+
region: string
10+
}): TencentCamPolicy => {
11+
const {
12+
id,
13+
PolicyId: policyId,
14+
PolicyName: name,
15+
AddTime: addTime,
16+
Type: type,
17+
Description: description,
18+
CreateMode: createMode,
19+
Attachments: attachments,
20+
ServiceType: serviceType,
21+
IsAttached: isAttached = 0,
22+
Deactived: deactived,
23+
DeactivedDetail: deactivedDetail,
24+
IsServiceLinkedPolicy: isServiceLinkedPolicy,
25+
AttachEntityCount: attachEntityCount,
26+
AttachEntityBoundaryCount: attachEntityBoundaryCount,
27+
UpdateTime: updateTime,
28+
} = service
29+
30+
return {
31+
id: `${id}`,
32+
policyId,
33+
region,
34+
name,
35+
addTime,
36+
type,
37+
description,
38+
createMode,
39+
attachments,
40+
serviceType,
41+
isAttached,
42+
deactived,
43+
deactivedDetail,
44+
isServiceLinkedPolicy,
45+
attachEntityCount,
46+
attachEntityBoundaryCount,
47+
updateTime,
48+
}
49+
}

src/services/camPolicy/index.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import {Service} from '@cloudgraph/sdk'
2+
import BaseService from '../base'
3+
import format from './format'
4+
import getData, { serviceName } from './data'
5+
import { getMutation } from '../../utils'
6+
7+
export default class TencentCamPolicy extends BaseService implements Service {
8+
format = format.bind(this)
9+
10+
getData = getData.bind(this)
11+
12+
mutation = getMutation(serviceName)
13+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
type tencentCamPolicy implements tencentBaseService @key(fields: "id") {
2+
policyId: Int @search
3+
name: String @search(by: [hash, regexp])
4+
addTime: String @search(by: [hash, regexp])
5+
type: Int @search
6+
description: String @search(by: [hash, regexp])
7+
createMode: Int @search
8+
attachments: Int @search
9+
serviceType: String @search(by: [hash, regexp])
10+
isAttached: Int @search
11+
deactived: Int @search
12+
deactivedDetail: [String] @search(by: [hash])
13+
isServiceLinkedPolicy: Int @search
14+
attachEntityCount: Int @search
15+
attachEntityBoundaryCount: Int @search
16+
updateTime: String @search(by: [hash, regexp])
17+
}

src/types/generated.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,24 @@ export type TencentBaseService = {
1717
region?: Maybe<Scalars['String']>;
1818
};
1919

20+
export type TencentCamPolicy = TencentBaseService & {
21+
addTime?: Maybe<Scalars['String']>;
22+
attachEntityBoundaryCount?: Maybe<Scalars['Int']>;
23+
attachEntityCount?: Maybe<Scalars['Int']>;
24+
attachments?: Maybe<Scalars['Int']>;
25+
createMode?: Maybe<Scalars['Int']>;
26+
deactived?: Maybe<Scalars['Int']>;
27+
deactivedDetail?: Maybe<Array<Maybe<Scalars['String']>>>;
28+
description?: Maybe<Scalars['String']>;
29+
isAttached?: Maybe<Scalars['Int']>;
30+
isServiceLinkedPolicy?: Maybe<Scalars['Int']>;
31+
name?: Maybe<Scalars['String']>;
32+
policyId?: Maybe<Scalars['Int']>;
33+
serviceType?: Maybe<Scalars['String']>;
34+
type?: Maybe<Scalars['Int']>;
35+
updateTime?: Maybe<Scalars['String']>;
36+
};
37+
2038
export type TencentCcn = TencentBaseService & {
2139
bandwidthLimitType?: Maybe<Scalars['String']>;
2240
ccnAttachments?: Maybe<Array<Maybe<TencentCcnAttachment>>>;

0 commit comments

Comments
 (0)