Skip to content

Commit 17d9777

Browse files
feat(gatewayRoute): merge alpha
2 parents ba42cbe + b4a985a commit 17d9777

File tree

19 files changed

+449
-4
lines changed

19 files changed

+449
-4
lines changed

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
# [1.0.0-alpha.3](https://github.com/cloudgraphdev/cloudgraph-provider-tencent/compare/1.0.0-alpha.2...1.0.0-alpha.3) (2022-05-19)
2+
3+
4+
### Features
5+
6+
* **customerGateway:** add customerGateway service ([cdee2e8](https://github.com/cloudgraphdev/cloudgraph-provider-tencent/commit/cdee2e85baa41ce5364051641345af0563e2601f))
7+
8+
# [1.0.0-alpha.2](https://github.com/cloudgraphdev/cloudgraph-provider-tencent/compare/1.0.0-alpha.1...1.0.0-alpha.2) (2022-05-18)
9+
10+
11+
### Features
12+
13+
* **routeTable:** add connection from routeTable to subnet ([6a34907](https://github.com/cloudgraphdev/cloudgraph-provider-tencent/commit/6a3490754dc5da4aa3ebe68072b2f6fe5063130b))
14+
* **routeTable:** add routeTable ([112f1d5](https://github.com/cloudgraphdev/cloudgraph-provider-tencent/commit/112f1d561208e122b36b51e842f2802cf1ee76be))
15+
* **routeTable:** add routeTable service ([76ff05a](https://github.com/cloudgraphdev/cloudgraph-provider-tencent/commit/76ff05ac8cb7cad4ccdf68b5d74633248a350aa8))
16+
* **routeTable:** update README ([f32ffec](https://github.com/cloudgraphdev/cloudgraph-provider-tencent/commit/f32ffecf3e67551826fae5025b3c2bf0e2a1feb4))
17+
* **routeTable:** update README ([3fd9c90](https://github.com/cloudgraphdev/cloudgraph-provider-tencent/commit/3fd9c9080b6ee007ec598b86b108f301e34e41af))
18+
119
# 1.0.0-alpha.1 (2022-05-16)
220

321

README.md

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

5757
| Service | Relations |
5858
| ------------------- | ------------------- |
59+
| customerGateway | |
60+
| routeTable | vpc, subnet |
5961
| securityGroup | |
6062
| securityGroupRule | |
6163
| ccn | ccnAttachment |
6264
| ccnAttachment | ccn |
63-
| subnet | vpc |
64-
| vpc | subnet, vpnGateway |
65+
| subnet | vpc, routeTable |
66+
| vpc | subnet, vpnGateway, routeTable |
6567
| vpnGateway | vpc, vpnGatewayRoute |
66-
| vpnGatewayRoute | vpnGateway |
68+
| vpnGatewayRoute | vpnGateway |

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@cloudgraph/cg-provider-tencent",
3-
"version": "1.0.0-alpha.1",
3+
"version": "1.0.0-alpha.3",
44
"description": "CloudGraph provider plugin for Tencent Cloud used to fetch Tencent Cloud data.",
55
"publishConfig": {
66
"registry": "https://registry.npmjs.org/",

src/enums/schemasMap.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ 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',
79
[services.securityGroup]: 'tencentSecurityGroup',
810
[services.securityGroupRule]: 'tencentSecurityGroupRule',
911
[services.ccn]: 'tencentCcn',

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+
routeTable: 'routeTables',
23
securityGroup: 'securityGroups',
34
ccn: 'ccns',
45
ccnAttachment: 'ccnAttachments',

src/enums/serviceMap.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,18 @@ import TencentCcnAttachment from '../services/ccnAttachment'
66
import TencentSubnet from '../services/subnet'
77
import TencentVpc from '../services/vpc'
88
import TencentTag from '../services/tag'
9+
import TencentRouteTable from '../services/routeTable'
910
import TencentVpnGateway from '../services/vpnGateway'
1011
import TencentVpnGatewayRoute from '../services/vpnGatewayRoute'
12+
import TencentCustomerGateway from '../services/customerGateway'
1113

1214
/**
1315
* serviceMap is an object that contains all currently supported services
1416
* serviceMap is used by the serviceFactory to produce instances of service classes
1517
*/
1618
export default {
19+
[services.customerGateway]: TencentCustomerGateway,
20+
[services.routeTable]: TencentRouteTable,
1721
[services.securityGroup]: TencentSecurityGroup,
1822
[services.securityGroupRule]: TencentSecurityGroupRule,
1923
[services.ccn]: TencentCcn,

src/enums/services.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
export default {
2+
customerGateway: 'customerGateway',
3+
routeTable: 'routeTable',
24
securityGroup: 'securityGroup',
35
securityGroupRule: 'securityGroupRule',
46
ccn: 'ccn',

src/services/customerGateway/data.ts

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+
}

src/services/customerGateway/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 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+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { ServiceConnection } from '@cloudgraph/sdk'
2+
import { RawTencentRouteTable } from './data'
3+
import services from '../../enums/services'
4+
import aliases from '../../enums/serviceAliases'
5+
6+
export default ({
7+
service,
8+
data,
9+
region,
10+
}: {
11+
service: RawTencentRouteTable
12+
data: { name: string; data: { [property: string]: any[] } }[]
13+
region: string
14+
}): {
15+
[property: string]: ServiceConnection[]
16+
} => {
17+
const { id } = service
18+
const connections: ServiceConnection[] = []
19+
20+
const subnetSets = service.AssociationSet.map(({SubnetId}) => SubnetId)
21+
22+
const instances: {
23+
name: string
24+
data: { [property: string]: any[] }
25+
} = data.find(({ name }) => name === services.subnet)
26+
27+
if (instances?.data?.[region]) {
28+
for (const service of instances.data[region]) {
29+
if (subnetSets.includes(service.id)) {
30+
connections.push({
31+
id: service.id,
32+
resourceType: services.subnet,
33+
relation: 'child',
34+
field: aliases[services.subnet]
35+
})
36+
}
37+
}
38+
}
39+
40+
const result = {
41+
[id]: connections,
42+
}
43+
return result
44+
}

src/services/routeTable/data.ts

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

src/services/routeTable/format.ts

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import cuid from 'cuid'
2+
import { Route } from 'tencentcloud-sdk-nodejs/tencentcloud/services/vpc/v20170312/vpc_models'
3+
import { TencentRouteTable, TencentRouteTableRoute } from '../../types/generated'
4+
import { formatTagSet } from '../../utils/format'
5+
import { RawTencentRouteTable } from './data'
6+
7+
const formatRouteTableRoute = (route: Route): TencentRouteTableRoute => {
8+
const {
9+
DestinationCidrBlock: destinationCidrBlock,
10+
GatewayType: gatewayType,
11+
GatewayId: gatewayId,
12+
RouteId: routeId = 0,
13+
RouteDescription: routeDescription = '',
14+
Enabled: enabled = false,
15+
RouteType: routeType = '',
16+
RouteTableId: routeTableId = '',
17+
DestinationIpv6CidrBlock: destinationIpv6CidrBlock = '',
18+
RouteItemId: routeItemId = '',
19+
PublishedToVbc: publishedToVbc = false,
20+
CreatedTime: createdTime = '',
21+
} = route
22+
23+
return {
24+
id: cuid(),
25+
destinationCidrBlock,
26+
gatewayType,
27+
gatewayId,
28+
routeId,
29+
routeDescription,
30+
enabled,
31+
routeType,
32+
routeTableId,
33+
destinationIpv6CidrBlock,
34+
routeItemId,
35+
publishedToVbc,
36+
createdTime,
37+
}
38+
}
39+
40+
41+
export default ({
42+
service,
43+
region,
44+
}: {
45+
service: RawTencentRouteTable
46+
region: string
47+
}): TencentRouteTable=> {
48+
const {
49+
id,
50+
RouteTableId: routeTableId,
51+
RouteTableName: routeTableName,
52+
AssociationSet = [],
53+
RouteSet = [],
54+
Main: main,
55+
CreatedTime: createdTime = '',
56+
TagSet,
57+
LocalCidrForCcn = [],
58+
} = service
59+
60+
return {
61+
id,
62+
region,
63+
routeTableId,
64+
routeTableName,
65+
associationSet: AssociationSet.map(({SubnetId: subnetId, RouteTableId: associationRouteTableId}) => {
66+
return {
67+
id: cuid(),
68+
subnetId,
69+
routeTableId: associationRouteTableId,
70+
}
71+
}),
72+
routeSet: RouteSet.map(formatRouteTableRoute),
73+
main,
74+
createdTime,
75+
tags: formatTagSet(TagSet),
76+
localCidrForCcn: LocalCidrForCcn.map(({Cidr: cidr, PublishedToVbc: publishedToVbc}) => {
77+
return {
78+
id: cuid(),
79+
cidr,
80+
publishedToVbc,
81+
}
82+
})
83+
}
84+
}

0 commit comments

Comments
 (0)