-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
449 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import * as tencentcloud from 'tencentcloud-sdk-nodejs' | ||
import { CustomerGateway, Tag } 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' | ||
|
||
const lt = { ...loggerText } | ||
const { logger } = CloudGraph | ||
export const serviceName = 'CustomerGateway' | ||
const apiEndpoint = initTestEndpoint(serviceName) | ||
|
||
export interface RawTencentCustomerGateway extends CustomerGateway { | ||
id: string | ||
region: string | ||
TagSet: Array<Tag> | ||
} | ||
|
||
export default async ({ | ||
regions, | ||
config, | ||
}: TencentServiceInput): Promise<{ | ||
[region: string]: RawTencentCustomerGateway[] | ||
}> => | ||
new Promise(async resolve => { | ||
const customerGatewayList: RawTencentCustomerGateway[] = [] | ||
|
||
for (const region of regions.split(',')) { | ||
/** | ||
* Get all the vpn gateways | ||
*/ | ||
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.DescribeCustomerGateways(null) | ||
|
||
if (response && !isEmpty(response.CustomerGatewaySet)) { | ||
for (const instance of response.CustomerGatewaySet) { | ||
customerGatewayList.push({ | ||
id: instance.CustomerGatewayId, | ||
...instance, | ||
region, | ||
TagSet: (instance as any).TagSet, | ||
}) | ||
} | ||
} | ||
|
||
} catch (error) { | ||
generateTencentErrorLog(serviceName, 'vpc:DescribeCustomerGateways', error) | ||
} | ||
} | ||
|
||
logger.debug(lt.foundResources(serviceName, customerGatewayList.length)) | ||
resolve(groupBy(customerGatewayList, 'region')) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { TencentCustomerGateway } from '../../types/generated' | ||
import { formatTagSet } from '../../utils/format' | ||
import { RawTencentCustomerGateway } from './data' | ||
|
||
export default ({ | ||
service, | ||
region, | ||
}: { | ||
service: RawTencentCustomerGateway | ||
region: string | ||
}): TencentCustomerGateway=> { | ||
const { | ||
id, | ||
CustomerGatewayName: name, | ||
IpAddress: ipAddress, | ||
CreatedTime: createdTime, | ||
TagSet, | ||
} = service | ||
|
||
return { | ||
id, | ||
region, | ||
name, | ||
ipAddress, | ||
createdTime, | ||
tags: formatTagSet(TagSet), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 TencentCustomerGateway extends BaseService implements Service { | ||
format = format.bind(this) | ||
|
||
getData = getData.bind(this) | ||
|
||
mutation = getMutation(serviceName) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
type tencentCustomerGateway implements tencentBaseService @key(fields: "id") { | ||
name: String @search(by: [hash, regexp]) | ||
ipAddress: String @search(by: [hash, regexp]) | ||
createdTime: String @search(by: [hash, regexp]) | ||
tags: [tencentRawTag] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { ServiceConnection } from '@cloudgraph/sdk' | ||
import { RawTencentRouteTable } from './data' | ||
import services from '../../enums/services' | ||
import aliases from '../../enums/serviceAliases' | ||
|
||
export default ({ | ||
service, | ||
data, | ||
region, | ||
}: { | ||
service: RawTencentRouteTable | ||
data: { name: string; data: { [property: string]: any[] } }[] | ||
region: string | ||
}): { | ||
[property: string]: ServiceConnection[] | ||
} => { | ||
const { id } = service | ||
const connections: ServiceConnection[] = [] | ||
|
||
const subnetSets = service.AssociationSet.map(({SubnetId}) => SubnetId) | ||
|
||
const instances: { | ||
name: string | ||
data: { [property: string]: any[] } | ||
} = data.find(({ name }) => name === services.subnet) | ||
|
||
if (instances?.data?.[region]) { | ||
for (const service of instances.data[region]) { | ||
if (subnetSets.includes(service.id)) { | ||
connections.push({ | ||
id: service.id, | ||
resourceType: services.subnet, | ||
relation: 'child', | ||
field: aliases[services.subnet] | ||
}) | ||
} | ||
} | ||
} | ||
|
||
const result = { | ||
[id]: connections, | ||
} | ||
return result | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import * as tencentcloud from 'tencentcloud-sdk-nodejs' | ||
import CloudGraph from '@cloudgraph/sdk' | ||
import groupBy from 'lodash/groupBy' | ||
import isEmpty from 'lodash/isEmpty' | ||
|
||
import { ClientConfig } from 'tencentcloud-sdk-nodejs/tencentcloud/common/interface' | ||
import { RouteTable } from 'tencentcloud-sdk-nodejs/tencentcloud/services/vpc/v20170312/vpc_models' | ||
import loggerText from '../../properties/logger' | ||
import { TencentServiceInput } from '../../types' | ||
import { initTestEndpoint, generateTencentErrorLog } from '../../utils' | ||
|
||
export const serviceName = 'RouteTable' | ||
|
||
const lt = { ...loggerText } | ||
const apiEndpoint = initTestEndpoint(serviceName) | ||
const { logger } = CloudGraph | ||
|
||
export interface RawTencentRouteTable extends RouteTable { | ||
id: string | ||
region: string | ||
} | ||
|
||
export default async ({ | ||
regions, | ||
config, | ||
}: TencentServiceInput): Promise<{ | ||
[region: string]: RawTencentRouteTable[] | ||
}> => | ||
new Promise(async resolve => { | ||
const routeTableList: RawTencentRouteTable[] = [] | ||
|
||
for (const region of regions.split(',')) { | ||
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.DescribeRouteTables({}) | ||
|
||
if (response && !isEmpty(response.RouteTableSet)) { | ||
for (const instance of response.RouteTableSet) { | ||
routeTableList.push({ | ||
id: instance.RouteTableId, | ||
...instance, | ||
region, | ||
}) | ||
} | ||
} | ||
} catch (error) { | ||
generateTencentErrorLog(serviceName, 'vpc:DescribeRouteTables', error) | ||
} | ||
} | ||
|
||
logger.debug(lt.foundResources(serviceName, routeTableList.length)) | ||
|
||
resolve(groupBy(routeTableList, 'region')) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import cuid from 'cuid' | ||
import { Route } from 'tencentcloud-sdk-nodejs/tencentcloud/services/vpc/v20170312/vpc_models' | ||
import { TencentRouteTable, TencentRouteTableRoute } from '../../types/generated' | ||
import { formatTagSet } from '../../utils/format' | ||
import { RawTencentRouteTable } from './data' | ||
|
||
const formatRouteTableRoute = (route: Route): TencentRouteTableRoute => { | ||
const { | ||
DestinationCidrBlock: destinationCidrBlock, | ||
GatewayType: gatewayType, | ||
GatewayId: gatewayId, | ||
RouteId: routeId = 0, | ||
RouteDescription: routeDescription = '', | ||
Enabled: enabled = false, | ||
RouteType: routeType = '', | ||
RouteTableId: routeTableId = '', | ||
DestinationIpv6CidrBlock: destinationIpv6CidrBlock = '', | ||
RouteItemId: routeItemId = '', | ||
PublishedToVbc: publishedToVbc = false, | ||
CreatedTime: createdTime = '', | ||
} = route | ||
|
||
return { | ||
id: cuid(), | ||
destinationCidrBlock, | ||
gatewayType, | ||
gatewayId, | ||
routeId, | ||
routeDescription, | ||
enabled, | ||
routeType, | ||
routeTableId, | ||
destinationIpv6CidrBlock, | ||
routeItemId, | ||
publishedToVbc, | ||
createdTime, | ||
} | ||
} | ||
|
||
|
||
export default ({ | ||
service, | ||
region, | ||
}: { | ||
service: RawTencentRouteTable | ||
region: string | ||
}): TencentRouteTable=> { | ||
const { | ||
id, | ||
RouteTableId: routeTableId, | ||
RouteTableName: routeTableName, | ||
AssociationSet = [], | ||
RouteSet = [], | ||
Main: main, | ||
CreatedTime: createdTime = '', | ||
TagSet, | ||
LocalCidrForCcn = [], | ||
} = service | ||
|
||
return { | ||
id, | ||
region, | ||
routeTableId, | ||
routeTableName, | ||
associationSet: AssociationSet.map(({SubnetId: subnetId, RouteTableId: associationRouteTableId}) => { | ||
return { | ||
id: cuid(), | ||
subnetId, | ||
routeTableId: associationRouteTableId, | ||
} | ||
}), | ||
routeSet: RouteSet.map(formatRouteTableRoute), | ||
main, | ||
createdTime, | ||
tags: formatTagSet(TagSet), | ||
localCidrForCcn: LocalCidrForCcn.map(({Cidr: cidr, PublishedToVbc: publishedToVbc}) => { | ||
return { | ||
id: cuid(), | ||
cidr, | ||
publishedToVbc, | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.