Skip to content

Commit cf56c49

Browse files
authored
Merge pull request #12 from cloudgraphdev/feature/CG-1126-add-vpn-customer-gateway-service
feat(customerGateway): add customerGateway service
2 parents 9cfc772 + cdee2e8 commit cf56c49

9 files changed

Lines changed: 118 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ CloudGraph Tencent Provider will ask you what regions you would like to crawl an
5656

5757
| Service | Relations |
5858
| ------------------- | ------------------- |
59+
| customerGateway | |
5960
| routeTable | vpc, subnet |
6061
| securityGroup | |
6162
| securityGroupRule | |

src/enums/schemasMap.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import services from './services'
44
* schemasMap is an object that contains schemas name by resource
55
*/
66
export default {
7+
[services.customerGateway]: 'tencentCustomerGateway',
78
[services.routeTable]: 'tencentRouteTable',
89
[services.securityGroup]: 'tencentSecurityGroup',
910
[services.securityGroupRule]: 'tencentSecurityGroupRule',

src/enums/serviceMap.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ import TencentVpc from '../services/vpc'
88
import TencentTag from '../services/tag'
99
import TencentRouteTable from '../services/routeTable'
1010
import TencentVpnGateway from '../services/vpnGateway'
11+
import TencentCustomerGateway from '../services/customerGateway'
1112

1213
/**
1314
* serviceMap is an object that contains all currently supported services
1415
* serviceMap is used by the serviceFactory to produce instances of service classes
1516
*/
1617
export default {
18+
[services.customerGateway]: TencentCustomerGateway,
1719
[services.routeTable]: TencentRouteTable,
1820
[services.securityGroup]: TencentSecurityGroup,
1921
[services.securityGroupRule]: TencentSecurityGroupRule,

src/enums/services.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export default {
2+
customerGateway: 'customerGateway',
23
routeTable: 'routeTable',
34
securityGroup: 'securityGroup',
45
securityGroupRule: 'securityGroupRule',
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import * as tencentcloud from 'tencentcloud-sdk-nodejs'
2+
import { CustomerGateway, Tag } from 'tencentcloud-sdk-nodejs/tencentcloud/services/vpc/v20170312/vpc_models'
3+
import { ClientConfig } from 'tencentcloud-sdk-nodejs/tencentcloud/common/interface'
4+
import CloudGraph from '@cloudgraph/sdk'
5+
import groupBy from 'lodash/groupBy'
6+
import isEmpty from 'lodash/isEmpty'
7+
import loggerText from '../../properties/logger'
8+
import { TencentServiceInput } from '../../types'
9+
import { initTestEndpoint, generateTencentErrorLog } from '../../utils'
10+
11+
const lt = { ...loggerText }
12+
const { logger } = CloudGraph
13+
export const serviceName = 'CustomerGateway'
14+
const apiEndpoint = initTestEndpoint(serviceName)
15+
16+
export interface RawTencentCustomerGateway extends CustomerGateway {
17+
id: string
18+
region: string
19+
TagSet: Array<Tag>
20+
}
21+
22+
export default async ({
23+
regions,
24+
config,
25+
}: TencentServiceInput): Promise<{
26+
[region: string]: RawTencentCustomerGateway[]
27+
}> =>
28+
new Promise(async resolve => {
29+
const customerGatewayList: RawTencentCustomerGateway[] = []
30+
31+
for (const region of regions.split(',')) {
32+
/**
33+
* Get all the vpn gateways
34+
*/
35+
try {
36+
const VpcClient = tencentcloud.vpc.v20170312.Client
37+
const clientConfig: ClientConfig = { credential: config, region, profile: { httpProfile: { endpoint: apiEndpoint } } }
38+
const vpc = new VpcClient(clientConfig)
39+
const response = await vpc.DescribeCustomerGateways(null)
40+
41+
if (response && !isEmpty(response.CustomerGatewaySet)) {
42+
for (const instance of response.CustomerGatewaySet) {
43+
customerGatewayList.push({
44+
id: instance.CustomerGatewayId,
45+
...instance,
46+
region,
47+
TagSet: (instance as any).TagSet,
48+
})
49+
}
50+
}
51+
52+
} catch (error) {
53+
generateTencentErrorLog(serviceName, 'vpc:DescribeCustomerGateways', error)
54+
}
55+
}
56+
57+
logger.debug(lt.foundResources(serviceName, customerGatewayList.length))
58+
resolve(groupBy(customerGatewayList, 'region'))
59+
})
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { TencentCustomerGateway } from '../../types/generated'
2+
import { formatTagSet } from '../../utils/format'
3+
import { RawTencentCustomerGateway } from './data'
4+
5+
export default ({
6+
service,
7+
region,
8+
}: {
9+
service: RawTencentCustomerGateway
10+
region: string
11+
}): TencentCustomerGateway=> {
12+
const {
13+
id,
14+
CustomerGatewayName: name,
15+
IpAddress: ipAddress,
16+
CreatedTime: createdTime,
17+
TagSet,
18+
} = service
19+
20+
return {
21+
id,
22+
region,
23+
name,
24+
ipAddress,
25+
createdTime,
26+
tags: formatTagSet(TagSet),
27+
}
28+
}
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 TencentCustomerGateway extends BaseService implements Service {
8+
format = format.bind(this)
9+
10+
getData = getData.bind(this)
11+
12+
mutation = getMutation(serviceName)
13+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
type tencentCustomerGateway implements tencentBaseService @key(fields: "id") {
2+
name: String @search(by: [hash, regexp])
3+
ipAddress: String @search(by: [hash, regexp])
4+
createdTime: String @search(by: [hash, regexp])
5+
tags: [tencentRawTag]
6+
}

src/types/generated.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ export type TencentCcnAttachment = TencentBaseService & {
5050
state?: Maybe<Scalars['String']>;
5151
};
5252

53+
export type TencentCustomerGateway = TencentBaseService & {
54+
createdTime?: Maybe<Scalars['String']>;
55+
ipAddress?: Maybe<Scalars['String']>;
56+
name?: Maybe<Scalars['String']>;
57+
tags?: Maybe<Array<Maybe<TencentRawTag>>>;
58+
};
59+
5360
export type TencentKeyValue = {
5461
id: Scalars['String'];
5562
key: Scalars['String'];

0 commit comments

Comments
 (0)