-
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.
feat(customerGateway): add customerGateway service
- Loading branch information
1 parent
9cfc772
commit cdee2e8
Showing
9 changed files
with
118 additions
and
0 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
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