-
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(securityGroupRule): add securityGroupRule service
- Loading branch information
Christopher Brandt
committed
May 11, 2022
1 parent
b154d3f
commit a6e7144
Showing
9 changed files
with
151 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
export default { | ||
securityGroup: 'securityGroup', | ||
securityGroupRule: 'securityGroupRule', | ||
subnet: 'subnet', | ||
vpc: 'vpc', | ||
} |
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,63 @@ | ||
import * as tencentcloud from 'tencentcloud-sdk-nodejs' | ||
import { SecurityGroupRule } from 'tencentcloud-sdk-nodejs/tencentcloud/services/cfw/v20190904/cfw_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 = 'SecurityGroupRule' | ||
const apiEndpoint = initTestEndpoint(serviceName) | ||
const MAX_ITEMS = '50' | ||
|
||
export interface RawTencentSecurityGroupRule extends SecurityGroupRule { | ||
id: string | ||
region: string | ||
} | ||
|
||
export default async ({ | ||
regions, | ||
config, | ||
}: TencentServiceInput): Promise<{ | ||
[region: string]: RawTencentSecurityGroupRule[] | ||
}> => | ||
new Promise(async resolve => { | ||
const ruleList: RawTencentSecurityGroupRule[] = [] | ||
|
||
for (const region of regions.split(',')) { | ||
/** | ||
* Get all security group rules | ||
*/ | ||
try { | ||
const CfwClient = tencentcloud.cfw.v20190904.Client | ||
const clientConfig: ClientConfig = { credential: config, region, profile: { httpProfile: { endpoint: apiEndpoint } } } | ||
const cfw = new CfwClient(clientConfig) | ||
let marker = 0 | ||
let rules = [] | ||
|
||
do { | ||
marker++ | ||
let response = await cfw.DescribeEnterpriseSecurityGroupRule({ PageNo: marker.toString(), PageSize: MAX_ITEMS }) | ||
if (response && !isEmpty(response.Rules)) { | ||
rules = response.Rules | ||
for (const instance of rules) { | ||
ruleList.push({ | ||
id: instance.Id, | ||
...instance, | ||
region, | ||
}) | ||
} | ||
} | ||
} while (!isEmpty(rules)) | ||
} catch (error) { | ||
generateTencentErrorLog(serviceName, 'cfw:DescribeEnterpriseSecurityGroupRule', error) | ||
} | ||
} | ||
|
||
logger.debug(lt.foundResources(serviceName, ruleList.length)) | ||
resolve(groupBy(ruleList, '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,43 @@ | ||
import { TencentSecurityGroupRule } from '../../types/generated' | ||
import { RawTencentSecurityGroupRule } from './data' | ||
|
||
export default ({ | ||
service, | ||
account, | ||
region, | ||
}: { | ||
service: RawTencentSecurityGroupRule | ||
account: string | ||
region: string | ||
}): TencentSecurityGroupRule => { | ||
const { | ||
id, | ||
SourceContent: sourceContent, | ||
SourceType: sourceType, | ||
DestContent: destContent, | ||
DestType: destType, | ||
RuleAction: ruleAction, | ||
Description: description, | ||
OrderIndex: orderIndex, | ||
Protocol: protocol, | ||
Port: port, | ||
ServiceTemplateId: serviceTemplateId, | ||
Enable: enable, | ||
} = service | ||
|
||
return { | ||
id, | ||
region, | ||
sourceContent, | ||
sourceType, | ||
destContent, | ||
destType, | ||
ruleAction, | ||
description, | ||
orderIndex, | ||
protocol, | ||
port, | ||
serviceTemplateId, | ||
enable, | ||
} | ||
} |
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 TencentSecurityGroupRule 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,13 @@ | ||
type tencentSecurityGroupRule implements tencentBaseService @key(fields: "id") { | ||
sourceContent: String @search(by: [hash, regexp]) | ||
sourceType: String @search(by: [hash, regexp]) | ||
destContent: String @search(by: [hash, regexp]) | ||
destType: String @search(by: [hash, regexp]) | ||
ruleAction: String @search(by: [hash, regexp]) | ||
description: String @search(by: [hash, regexp]) | ||
orderIndex: String @search(by: [hash, regexp]) | ||
protocol: String @search(by: [hash, regexp]) | ||
port: String @search(by: [hash, regexp]) | ||
serviceTemplateId: String @search(by: [hash, regexp]) | ||
enable: String @search(by: [hash, regexp]) | ||
} |
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