Skip to content

Commit 2a42aed

Browse files
committed
fix(rebase): fastforward alpha to main
2 parents fd2def1 + ed87d28 commit 2a42aed

16 files changed

Lines changed: 354 additions & 0 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,7 @@ CloudGraph Tencent Provider will ask you what regions you would like to crawl an
5858
| ------------------- | ------------------- |
5959
| securityGroup | |
6060
| securityGroupRule | |
61+
| ccn | ccnAttachment |
62+
| ccnAttachment | ccn |
6163
| subnet | vpc |
6264
| vpc | subnet |

src/enums/schemasMap.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import services from './services'
66
export default {
77
[services.securityGroup]: 'tencentSecurityGroup',
88
[services.securityGroupRule]: 'tencentSecurityGroupRule',
9+
[services.ccn]: 'tencentCcn',
10+
[services.ccnAttachment]: 'tencentCcnAttachment',
911
[services.subnet]: 'tencentSubnet',
1012
[services.vpc]: 'tencentVpc',
1113
tag: 'tencentTag',

src/enums/serviceAliases.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
export default {
22
securityGroup: 'securityGroups',
3+
ccn: 'ccns',
4+
ccnAttachment: 'ccnAttachments',
35
subnet: 'subnets',
46
vpc: 'vpcInstances',
57
}

src/enums/serviceMap.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import services from './services'
22
import TencentSecurityGroup from '../services/securityGroup'
33
import TencentSecurityGroupRule from '../services/securityGroupRule'
4+
import TencentCcn from '../services/ccn'
5+
import TencentCcnAttachment from '../services/ccnAttachment'
46
import TencentSubnet from '../services/subnet'
57
import TencentVpc from '../services/vpc'
68
import TencentTag from '../services/tag'
@@ -12,6 +14,8 @@ import TencentTag from '../services/tag'
1214
export default {
1315
[services.securityGroup]: TencentSecurityGroup,
1416
[services.securityGroupRule]: TencentSecurityGroupRule,
17+
[services.ccn]: TencentCcn,
18+
[services.ccnAttachment]: TencentCcnAttachment,
1519
[services.subnet]: TencentSubnet,
1620
[services.vpc]: TencentVpc,
1721
tag: TencentTag,

src/enums/services.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
export default {
22
securityGroup: 'securityGroup',
33
securityGroupRule: 'securityGroupRule',
4+
ccn: 'ccn',
5+
ccnAttachment: 'ccnAttachment',
46
subnet: 'subnet',
57
vpc: 'vpc',
68
}

src/services/ccn/connections.ts

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 { RawTencentCcn } from './data'
3+
import services from '../../enums/services'
4+
import aliases from '../../enums/serviceAliases'
5+
6+
const serviceName = 'ccn'
7+
8+
export default ({
9+
service,
10+
data,
11+
region,
12+
}: {
13+
service: RawTencentCcn
14+
data: { name: string; data: { [property: string]: any[] } }[]
15+
region: string
16+
}): {
17+
[property: string]: ServiceConnection[]
18+
} => {
19+
const { id } = service
20+
const connections: ServiceConnection[] = []
21+
22+
const instances: {
23+
name: string
24+
data: { [property: string]: any[] }
25+
} = data.find(({ name }) => name === services.ccnAttachment)
26+
27+
if (instances?.data?.[region]) {
28+
for (const service of instances.data[region]) {
29+
if (id === service.CcnId) {
30+
connections.push({
31+
id: service.id,
32+
resourceType: serviceName,
33+
relation: 'child',
34+
field: aliases[serviceName] ? aliases[serviceName] : serviceName,
35+
})
36+
}
37+
}
38+
}
39+
40+
const result = {
41+
[id]: connections,
42+
}
43+
return result
44+
}

src/services/ccn/data.ts

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

src/services/ccn/format.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { TencentCcn } from '../../types/generated'
2+
import { formatTagSet } from '../../utils/format'
3+
import { RawTencentCcn } from './data'
4+
5+
export default ({
6+
service,
7+
region,
8+
}: {
9+
service: RawTencentCcn
10+
region: string
11+
}): TencentCcn => {
12+
const {
13+
id,
14+
CcnName: ccnName,
15+
CcnDescription: ccnDescription,
16+
InstanceCount: instanceCount,
17+
CreateTime: createTime,
18+
State: state,
19+
QosLevel: qosLevel,
20+
InstanceChargeType: instanceChargeType,
21+
BandwidthLimitType: bandwidthLimitType,
22+
TagSet,
23+
RoutePriorityFlag: routePriorityFlag,
24+
RouteTableCount: routeTableCount,
25+
RouteTableFlag: routeTableFlag,
26+
} = service
27+
28+
return {
29+
id,
30+
region,
31+
ccnName,
32+
ccnDescription,
33+
instanceCount,
34+
createTime,
35+
state,
36+
qosLevel,
37+
instanceChargeType,
38+
bandwidthLimitType,
39+
tags: formatTagSet(TagSet),
40+
routePriorityFlag,
41+
routeTableCount,
42+
routeTableFlag,
43+
}
44+
}

src/services/ccn/index.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import {Service} from '@cloudgraph/sdk'
2+
import BaseService from '../base'
3+
import format from './format'
4+
import getData, { serviceName } from './data'
5+
import getConnections from './connections'
6+
import { getMutation } from '../../utils'
7+
8+
export default class TencentCcn extends BaseService implements Service {
9+
format = format.bind(this)
10+
11+
getData = getData.bind(this)
12+
13+
getConnections = getConnections.bind(this)
14+
15+
mutation = getMutation(serviceName)
16+
}

src/services/ccn/schema.graphql

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
type tencentCcn implements tencentBaseService @key(fields: "id") {
2+
ccnName: String @search(by: [hash, regexp])
3+
ccnDescription: String @search(by: [hash, regexp])
4+
instanceCount: Int @search
5+
createTime: String @search(by: [hash, regexp])
6+
state: String @search(by: [hash, regexp])
7+
qosLevel: String @search(by: [hash, regexp])
8+
instanceChargeType: String @search(by: [hash, regexp])
9+
bandwidthLimitType: String @search(by: [hash, regexp])
10+
tags: [tencentRawTag]
11+
routePriorityFlag: Boolean @search
12+
routeTableCount: Int @search
13+
routeTableFlag: Boolean @search
14+
ccnAttachments: [tencentCcnAttachment] @hasInverse(field: ccns)
15+
}

0 commit comments

Comments
 (0)