Skip to content

Commit 6c3fe54

Browse files
feat(vpnConnection) add vpnConnection service
2 parents f2b0072 + 50e31a2 commit 6c3fe54

16 files changed

Lines changed: 242 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
# [1.0.0-alpha.5](https://github.com/cloudgraphdev/cloudgraph-provider-tencent/compare/1.0.0-alpha.4...1.0.0-alpha.5) (2022-05-26)
2+
3+
4+
### Features
5+
6+
* **networkAcl:** add networkAcl service ([3665d1e](https://github.com/cloudgraphdev/cloudgraph-provider-tencent/commit/3665d1e14782040d601152a252bd889e64fdef98))
7+
* **securityGroup:** add security group service ([5be1232](https://github.com/cloudgraphdev/cloudgraph-provider-tencent/commit/5be123281dca7d37e29e91617f03ece3b6a2b07c))
8+
* **securityGroupRule:** add securityGroupRule service ([c436eb8](https://github.com/cloudgraphdev/cloudgraph-provider-tencent/commit/c436eb8a15269f6738527a415421638f22e95193))
9+
110
# [1.0.0-alpha.4](https://github.com/cloudgraphdev/cloudgraph-provider-tencent/compare/1.0.0-alpha.3...1.0.0-alpha.4) (2022-05-24)
211

312

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,10 @@ CloudGraph Tencent Provider will ask you what regions you would like to crawl an
6262
| securityGroupRule | |
6363
| ccn | ccnAttachment |
6464
| ccnAttachment | ccn |
65-
| subnet | vpc, routeTable |
66-
| vpc | subnet, vpnGateway, routeTable, vpnConnection |
65+
| networkAcl | subnet, vpc |
66+
| subnet | networkAcl, vpc, routeTable |
67+
| vpc | networkAcl, subnet, vpnGateway, routeTable, vpnConnection |
6768
| vpnConnection | vpc, vpnGateway, customerGateway |
6869
| vpnGateway | vpc, vpnGatewayRoute, vpnConnection |
6970
| vpnGatewayRoute | vpnGateway |
71+
| securityGroup | |

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.4",
3+
"version": "1.0.0-alpha.5",
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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ export default {
1010
[services.securityGroupRule]: 'tencentSecurityGroupRule',
1111
[services.ccn]: 'tencentCcn',
1212
[services.ccnAttachment]: 'tencentCcnAttachment',
13+
[services.networkAcl]: 'tencentNetworkAcl',
14+
[services.securityGroup]: 'tencentSecurityGroup',
15+
[services.securityGroupRule]: 'tencentSecurityGroupRule',
1316
[services.subnet]: 'tencentSubnet',
1417
[services.vpc]: 'tencentVpc',
1518
[services.vpnConnection]: 'tencentVpnConnection',

src/enums/serviceMap.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import services from './services'
2+
import TencentNetworkAcl from '../services/networkAcl'
23
import TencentSecurityGroup from '../services/securityGroup'
34
import TencentSecurityGroupRule from '../services/securityGroupRule'
45
import TencentCcn from '../services/ccn'
@@ -20,6 +21,7 @@ export default {
2021
[services.ccn]: TencentCcn,
2122
[services.ccnAttachment]: TencentCcnAttachment,
2223
[services.customerGateway]: TencentCustomerGateway,
24+
[services.networkAcl]: TencentNetworkAcl,
2325
[services.routeTable]: TencentRouteTable,
2426
[services.securityGroup]: TencentSecurityGroup,
2527
[services.securityGroupRule]: TencentSecurityGroupRule,

src/enums/services.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export default {
33
ccnAttachment: 'ccnAttachment',
44
customerGateway: 'customerGateway',
55
routeTable: 'routeTable',
6+
networkAcl: 'networkAcl',
67
securityGroup: 'securityGroup',
78
securityGroupRule: 'securityGroupRule',
89
subnet: 'subnet',

src/services/networkAcl/data.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import * as tencentcloud from 'tencentcloud-sdk-nodejs'
2+
import { NetworkAcl } 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 = 'NetworkAcl'
14+
const apiEndpoint = initTestEndpoint(serviceName)
15+
16+
export interface RawTencentNetworkAcl extends NetworkAcl {
17+
id: string
18+
region: string
19+
subnets: string[]
20+
}
21+
22+
export default async ({
23+
regions,
24+
config,
25+
}: TencentServiceInput): Promise<{
26+
[region: string]: RawTencentNetworkAcl[]
27+
}> =>
28+
new Promise(async resolve => {
29+
const naclList: RawTencentNetworkAcl[] = []
30+
31+
for (const region of regions.split(',')) {
32+
/**
33+
* Get all NetworkACLs
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.DescribeNetworkAcls(null)
40+
41+
if (response && !isEmpty(response.NetworkAclSet)) {
42+
for (const instance of response.NetworkAclSet) {
43+
naclList.push({
44+
id: instance.NetworkAclId,
45+
...instance,
46+
subnets: instance?.SubnetSet?.map(subnet => subnet.SubnetId),
47+
region,
48+
})
49+
}
50+
}
51+
} catch (error) {
52+
generateTencentErrorLog(serviceName, 'vpc:DescribeNetworkAcls', error)
53+
}
54+
}
55+
56+
logger.debug(lt.foundResources(serviceName, naclList.length))
57+
resolve(groupBy(naclList, 'region'))
58+
})

src/services/networkAcl/format.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import cuid from 'cuid'
2+
import { TencentNetworkAcl } from '../../types/generated'
3+
import { RawTencentNetworkAcl } from './data'
4+
5+
export default ({
6+
service,
7+
account,
8+
region,
9+
}: {
10+
service: RawTencentNetworkAcl
11+
account: string
12+
region: string
13+
}): TencentNetworkAcl => {
14+
const {
15+
id,
16+
NetworkAclName: name,
17+
VpcId: vpcId,
18+
CreatedTime: createdTime,
19+
IngressEntries,
20+
EgressEntries,
21+
} = service
22+
23+
return {
24+
id,
25+
region,
26+
name,
27+
vpcId,
28+
createdTime,
29+
ingressEntries: IngressEntries?.map(naclEntry => ({
30+
id: cuid(),
31+
...naclEntry,
32+
})),
33+
egressEntries: EgressEntries?.map(naclEntry => ({
34+
id: cuid(),
35+
...naclEntry,
36+
})),
37+
}
38+
}

src/services/networkAcl/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 TencentNetworkAcl extends BaseService implements Service {
8+
format = format.bind(this)
9+
10+
getData = getData.bind(this)
11+
12+
mutation = getMutation(serviceName)
13+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
type tencentNetworkAcl implements tencentBaseService @key(fields: "id") {
2+
vpcId: String @search(by: [hash, regexp])
3+
name: String @search(by: [hash, regexp])
4+
createdTime: String @search(by: [hash, regexp])
5+
ingressEntries: [tencentNetworkAclEntry]
6+
egressEntries: [tencentNetworkAclEntry]
7+
subnets: [tencentSubnet] @hasInverse(field: networkAcl)
8+
vpcInstance: [tencentVpc] @hasInverse(field: networkAcl)
9+
}
10+
11+
type tencentNetworkAclEntry
12+
@generate(
13+
query: { get: false, query: true, aggregate: false }
14+
mutation: { add: false, delete: false }
15+
subscription: false
16+
)
17+
@key(fields: "id") {
18+
id: String! @id @search(by: [hash, regexp])
19+
modifyTime: String @search(by: [hash, regexp])
20+
protocol: String @search(by: [hash, regexp])
21+
port: String @search(by: [hash, regexp])
22+
cidrBlock: String @search(by: [hash, regexp])
23+
ipv6CidrBlock: String @search(by: [hash, regexp])
24+
action: String @search(by: [hash, regexp])
25+
description: String @search(by: [hash, regexp])
26+
}

0 commit comments

Comments
 (0)