Skip to content

Commit 362bf7f

Browse files
feat(vpnGateway): add tencent vpnGateway
1 parent 762dc79 commit 362bf7f

11 files changed

Lines changed: 209 additions & 1 deletion

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,5 @@ CloudGraph Tencent Provider will ask you what regions you would like to crawl an
5757
| Service | Relations |
5858
| ------------------- | ------------------- |
5959
| subnet | vpc |
60-
| vpc | subnet |
60+
| vpc | subnet, vpnGateway |
61+
| vpnGateway | vpc |

src/enums/schemasMap.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ import services from './services'
66
export default {
77
[services.subnet]: 'tencentSubnet',
88
[services.vpc]: 'tencentVpc',
9+
[services.vpnGateway]: 'tencentVpnGateway',
910
tag: 'tencentTag',
1011
}

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 {
22
subnet: 'subnets',
33
vpc: 'vpcInstances',
4+
vpnGateway: 'vpnGateways',
45
}

src/enums/serviceMap.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import services from './services'
22
import TencentSubnet from '../services/subnet'
33
import TencentVpc from '../services/vpc'
44
import TencentTag from '../services/tag'
5+
import TencentVpnGateway from '../services/vpnGateway'
56

67
/**
78
* serviceMap is an object that contains all currently supported services
@@ -10,5 +11,6 @@ import TencentTag from '../services/tag'
1011
export default {
1112
[services.subnet]: TencentSubnet,
1213
[services.vpc]: TencentVpc,
14+
[services.vpnGateway]: TencentVpnGateway,
1315
tag: TencentTag,
1416
}

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 {
22
subnet: 'subnet',
33
vpc: 'vpc',
4+
vpnGateway: 'vpnGateway',
45
}

src/services/vpc/schema.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ type tencentVpc implements tencentBaseService @key(fields: "id") {
1212
tags: [tencentRawTag]
1313
assistantCidrSet: [tencentVpcAssistantCidr]
1414
subnets: [tencentSubnet] @hasInverse(field: vpcInstances)
15+
vpnGateways: [tencentVpnGateway] @hasInverse(field: vpcInstances)
1516
}
1617

1718
type tencentVpcAssistantCidr

src/services/vpnGateway/data.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import * as tencentcloud from 'tencentcloud-sdk-nodejs'
2+
import { VpnGateway } 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 = 'VpnGateway'
14+
const apiEndpoint = initTestEndpoint(serviceName)
15+
16+
export interface RawTencentVpnGateway extends VpnGateway {
17+
id: string
18+
region: string
19+
}
20+
21+
export default async ({
22+
regions,
23+
config,
24+
}: TencentServiceInput): Promise<{
25+
[region: string]: RawTencentVpnGateway[]
26+
}> =>
27+
new Promise(async resolve => {
28+
const vpnGatewayList: RawTencentVpnGateway[] = []
29+
30+
for (const region of regions.split(',')) {
31+
/**
32+
* Get all the vpn gateways
33+
*/
34+
try {
35+
const VpcClient = tencentcloud.vpc.v20170312.Client
36+
const clientConfig: ClientConfig = { credential: config, region, profile: { httpProfile: { endpoint: apiEndpoint } } }
37+
const vpc = new VpcClient(clientConfig)
38+
const response = await vpc.DescribeVpnGateways(null)
39+
40+
if (response && !isEmpty(response.VpnGatewaySet)) {
41+
for (const instance of response.VpnGatewaySet) {
42+
vpnGatewayList.push({
43+
id: instance.VpnGatewayId,
44+
...instance,
45+
region,
46+
})
47+
}
48+
}
49+
50+
} catch (error) {
51+
generateTencentErrorLog(serviceName, 'vpc:DescribeVpnGateways', error)
52+
}
53+
}
54+
55+
logger.debug(lt.foundResources(serviceName, vpnGatewayList.length))
56+
resolve(groupBy(vpnGatewayList, 'region'))
57+
})

src/services/vpnGateway/format.ts

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import cuid from 'cuid'
2+
import { TencentVpnGateway } from '../../types/generated'
3+
import { RawTencentVpnGateway } from './data'
4+
5+
export default ({
6+
service,
7+
region,
8+
}: {
9+
service: RawTencentVpnGateway
10+
region: string
11+
}): TencentVpnGateway=> {
12+
const {
13+
id,
14+
VpnGatewayName: name,
15+
Type: type,
16+
State: state,
17+
PublicIpAddress: publicIpAddress,
18+
RenewFlag: renewFlag,
19+
InstanceChargeType: instanceChargeType,
20+
InternetMaxBandwidthOut: internetMaxBandwidthOut,
21+
CreatedTime: createdTime,
22+
ExpiredTime: expiredTime,
23+
IsAddressBlocked: isAddressBlocked,
24+
NewPurchasePlan: newPurchasePlan,
25+
RestrictState: restrictState,
26+
Zone: zone,
27+
VpnGatewayQuotaSet,
28+
Version: version,
29+
NetworkInstanceId: networkInstanceId,
30+
CdcId: cdcId,
31+
MaxConnection: maxConnection,
32+
} = service
33+
34+
return {
35+
id,
36+
region,
37+
name,
38+
type,
39+
state,
40+
publicIpAddress,
41+
renewFlag,
42+
instanceChargeType,
43+
internetMaxBandwidthOut,
44+
createdTime,
45+
expiredTime,
46+
isAddressBlocked,
47+
newPurchasePlan,
48+
restrictState,
49+
zone,
50+
vpnGatewayQuotaSet: VpnGatewayQuotaSet.map(({
51+
Bandwidth: bandwidth,
52+
Cname: chineseName,
53+
Name: englishName,
54+
}) => {
55+
return {
56+
id: cuid(),
57+
bandwidth,
58+
cname: chineseName,
59+
name: englishName,
60+
}
61+
}),
62+
version,
63+
networkInstanceId,
64+
cdcId,
65+
maxConnection,
66+
}
67+
}

src/services/vpnGateway/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 TencentVpnGateway extends BaseService implements Service {
8+
format = format.bind(this)
9+
10+
getData = getData.bind(this)
11+
12+
mutation = getMutation(serviceName)
13+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
type tencentVpnGatewayQuota
2+
@generate(
3+
query: { get: false, query: true, aggregate: false }
4+
mutation: { add: false, delete: false }
5+
subscription: false
6+
)
7+
@key(fields: "id") {
8+
id: String! @id @search(by: [hash, regexp])
9+
bandwidth: Int @search
10+
cname: String @search(by: [hash, regexp])
11+
name: String @search(by: [hash, regexp])
12+
}
13+
14+
type tencentVpnGateway implements tencentBaseService @key(fields: "id") {
15+
name: String @search(by: [hash, regexp])
16+
type: String @search(by: [hash, regexp])
17+
state: String @search(by: [hash, regexp])
18+
publicIpAddress: String @search(by: [hash, regexp])
19+
renewFlag: String @search(by: [hash, regexp])
20+
instanceChargeType: String @search(by: [hash, regexp])
21+
internetMaxBandwidthOut: Int @search
22+
createdTime: String @search(by: [hash, regexp])
23+
expiredTime: String @search(by: [hash, regexp])
24+
isAddressBlocked: Boolean @search
25+
newPurchasePlan: String @search(by: [hash, regexp])
26+
restrictState: String @search(by: [hash, regexp])
27+
zone: String @search(by: [hash, regexp])
28+
vpnGatewayQuotaSet: [tencentVpnGatewayQuota],
29+
version: String @search(by: [hash, regexp])
30+
networkInstanceId: String @search(by: [hash, regexp])
31+
cdcId: String @search(by: [hash, regexp])
32+
maxConnection: Int @search
33+
vpcInstances: [tencentVpc] @hasInverse(field: vpnGateways)
34+
}

0 commit comments

Comments
 (0)