Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,5 @@ CloudGraph Tencent Provider will ask you what regions you would like to crawl an
| ccnAttachment | ccn |
| subnet | vpc, routeTable |
| vpc | subnet, vpnGateway, routeTable |
| vpnGateway | vpc |
| vpnGateway | vpc, vpnGatewayRoute |
| vpnGatewayRoute | vpnGateway |
1 change: 1 addition & 0 deletions src/enums/schemasMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ export default {
[services.subnet]: 'tencentSubnet',
[services.vpc]: 'tencentVpc',
[services.vpnGateway]: 'tencentVpnGateway',
[services.vpnGatewayRoute]: 'tencentVpnGatewayRoute',
tag: 'tencentTag',
}
1 change: 1 addition & 0 deletions src/enums/serviceAliases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ export default {
subnet: 'subnets',
vpc: 'vpcInstances',
vpnGateway: 'vpnGateways',
vpnGatewayRoute: 'vpnGatewayRoutes',
}
2 changes: 2 additions & 0 deletions src/enums/serviceMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import TencentVpc from '../services/vpc'
import TencentTag from '../services/tag'
import TencentRouteTable from '../services/routeTable'
import TencentVpnGateway from '../services/vpnGateway'
import TencentVpnGatewayRoute from '../services/vpnGatewayRoute'
import TencentCustomerGateway from '../services/customerGateway'

/**
Expand All @@ -24,5 +25,6 @@ export default {
[services.subnet]: TencentSubnet,
[services.vpc]: TencentVpc,
[services.vpnGateway]: TencentVpnGateway,
[services.vpnGatewayRoute]: TencentVpnGatewayRoute,
tag: TencentTag,
}
1 change: 1 addition & 0 deletions src/enums/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ export default {
subnet: 'subnet',
vpc: 'vpc',
vpnGateway: 'vpnGateway',
vpnGatewayRoute: 'vpnGatewayRoute',
}
44 changes: 44 additions & 0 deletions src/services/vpnGateway/connections.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { ServiceConnection } from '@cloudgraph/sdk'
import { RawTencentVpnGateway } from './data'
import services from '../../enums/services'
import aliases from '../../enums/serviceAliases'
import { RawTencentVpnGatewayRoute } from '../vpnGatewayRoute/data'

const serviceName = services.vpnGatewayRoute

export default ({
service,
data,
region,
}: {
service: RawTencentVpnGateway
data: { name: string; data: { [property: string]: any[] } }[]
region: string
}): {
[property: string]: ServiceConnection[]
} => {
const { id } = service
const connections: ServiceConnection[] = []

const vpnGatewayRouteInstances: {
name: string
data: { [region: string]: RawTencentVpnGatewayRoute[] }
} = data.find(({ name }) => name === services.vpnGatewayRoute)
if (vpnGatewayRouteInstances?.data?.[region]) {
for (const vpnGatewayRouteInstanceInstance of vpnGatewayRouteInstances.data[region]) {
if (id === vpnGatewayRouteInstanceInstance.vpnGatewayId) {
connections.push({
id: vpnGatewayRouteInstanceInstance.id,
resourceType: serviceName,
relation: 'child',
field: aliases[serviceName] ? aliases[serviceName] : serviceName,
})
}
}
}

const result = {
[id]: connections,
}
return result
}
3 changes: 3 additions & 0 deletions src/services/vpnGateway/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ import { Service } from '@cloudgraph/sdk'
import BaseService from '../base'
import format from './format'
import getData, { serviceName } from './data'
import getConnections from './connections'
import { getMutation } from '../../utils'

export default class TencentVpnGateway extends BaseService implements Service {
format = format.bind(this)

getData = getData.bind(this)

getConnections = getConnections.bind(this)

mutation = getMutation(serviceName)
}
1 change: 1 addition & 0 deletions src/services/vpnGateway/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ type tencentVpnGateway implements tencentBaseService @key(fields: "id") {
cdcId: String @search(by: [hash, regexp])
maxConnection: Int @search
vpcInstances: [tencentVpc] @hasInverse(field: vpnGateways)
vpnGatewayRoutes: [tencentVpnGatewayRoute] @hasInverse(field: vpnGateways)
}
72 changes: 72 additions & 0 deletions src/services/vpnGatewayRoute/data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import * as tencentcloud from 'tencentcloud-sdk-nodejs'
import { VpnGatewayRoute } from 'tencentcloud-sdk-nodejs/tencentcloud/services/vpc/v20170312/vpc_models'
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 loggerText from '../../properties/logger'
import { TencentServiceInput } from '../../types'
import { initTestEndpoint, generateTencentErrorLog } from '../../utils'
import services from '../../enums/services'
import { RawTencentVpnGateway } from '../vpnGateway/data'

const lt = { ...loggerText }
const { logger } = CloudGraph
export const serviceName = 'VpnGatewayRoute'
const apiEndpoint = initTestEndpoint(serviceName)

export interface RawTencentVpnGatewayRoute extends VpnGatewayRoute {
id: string
vpnGatewayId: string
region: string
}

export default async ({
regions,
config,
rawData,
}: TencentServiceInput): Promise<{
[region: string]: RawTencentVpnGatewayRoute[]
}> =>
new Promise(async resolve => {
const vpnGatewayRouteList: RawTencentVpnGatewayRoute[] = []

const allVpnGateways: RawTencentVpnGateway[] =
rawData.find(({ name }) => name === services.vpnGateway)?.data

for (const region of regions.split(',')) {
const vpnGatewaysInRegion = allVpnGateways[region] || []

for (const vpnGateway of vpnGatewaysInRegion) {
const vpnGatewayId = vpnGateway.id

/**
* Get all the VPN Gateway Route
*/
try {
const VpcClient = tencentcloud.vpc.v20170312.Client
const clientConfig: ClientConfig = { credential: config, region, profile: { httpProfile: { endpoint: apiEndpoint } } }
const vpc = new VpcClient(clientConfig)
const response = await vpc.DescribeVpnGatewayRoutes({
VpnGatewayId: vpnGatewayId,
})

if (response && !isEmpty(response.Routes)) {
for (const instance of response.Routes) {
vpnGatewayRouteList.push({
id: instance.RouteId,
vpnGatewayId,
...instance,
region,
})
}
}
} catch (error) {
generateTencentErrorLog(serviceName, 'vpc:DescribeVpnGatewayRoutes', error)
}
}
}

logger.debug(lt.foundResources(serviceName, vpnGatewayRouteList.length))
resolve(groupBy(vpnGatewayRouteList, 'region'))
})
35 changes: 35 additions & 0 deletions src/services/vpnGatewayRoute/format.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { TencentVpnGatewayRoute } from '../../types/generated'
import { RawTencentVpnGatewayRoute } from './data'

export default ({
service,
region,
}: {
service: RawTencentVpnGatewayRoute
region: string
}): TencentVpnGatewayRoute => {
const {
id,
DestinationCidrBlock: destinationCidrBlock,
InstanceType: instanceType,
InstanceId: instanceId,
Priority: priority,
Status: status,
Type: type,
CreateTime: createTime,
UpdateTime: updateTime,
} = service

return {
id,
region,
destinationCidrBlock,
instanceType,
instanceId,
priority,
status,
type,
createTime,
updateTime,
}
}
13 changes: 13 additions & 0 deletions src/services/vpnGatewayRoute/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Service } from '@cloudgraph/sdk'
import BaseService from '../base'
import format from './format'
import getData, { serviceName } from './data'
import { getMutation } from '../../utils'

export default class TencentVpnGatewayRoute extends BaseService implements Service {
format = format.bind(this)

getData = getData.bind(this)

mutation = getMutation(serviceName)
}
11 changes: 11 additions & 0 deletions src/services/vpnGatewayRoute/schema.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
type tencentVpnGatewayRoute implements tencentBaseService @key(fields: "id") {
destinationCidrBlock: String @search(by: [hash, regexp])
instanceType: String @search(by: [hash, regexp])
instanceId: String @search(by: [hash, regexp])
priority: Int @search
status: String @search(by: [hash, regexp])
type: String @search(by: [hash, regexp])
createTime: String @search(by: [hash, regexp])
updateTime: String @search(by: [hash, regexp])
vpnGateways: [tencentVpnGateway] @hasInverse(field: vpnGatewayRoutes)
}
13 changes: 13 additions & 0 deletions src/types/generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ export type TencentVpnGateway = TencentBaseService & {
version?: Maybe<Scalars['String']>;
vpcInstances?: Maybe<Array<Maybe<TencentVpc>>>;
vpnGatewayQuotaSet?: Maybe<Array<Maybe<TencentVpnGatewayQuota>>>;
vpnGatewayRoutes?: Maybe<Array<Maybe<TencentVpnGatewayRoute>>>;
zone?: Maybe<Scalars['String']>;
};

Expand All @@ -216,3 +217,15 @@ export type TencentVpnGatewayQuota = {
id: Scalars['String'];
name?: Maybe<Scalars['String']>;
};

export type TencentVpnGatewayRoute = TencentBaseService & {
createTime?: Maybe<Scalars['String']>;
destinationCidrBlock?: Maybe<Scalars['String']>;
instanceId?: Maybe<Scalars['String']>;
instanceType?: Maybe<Scalars['String']>;
priority?: Maybe<Scalars['Int']>;
status?: Maybe<Scalars['String']>;
type?: Maybe<Scalars['String']>;
updateTime?: Maybe<Scalars['String']>;
vpnGateways?: Maybe<Array<Maybe<TencentVpnGateway>>>;
};