0.4.5 • Published 11 months ago
@wangyjhh/msgr v0.4.5
@wangyjhh/msgr
A security group rule management tool for Alibaba Cloud ESC implemented based on the official SDK.
Install
# npm
npm i @wangyjhh/msgr -g
# pnpm
pnpm add @wangyjhh/msgr -gUsage
CLI
Usage: msgr [options] [command]
Alibaba Cloud security group rule management tool.
Options:
-v, --version Output version number.
-h, --help display help for command
Commands:
config <tpye> Configuration
list|ls Review the security group rules.
add|ad Add the security group rules.
remove|rm Remove the security group rules.
modify|mo Modify the security group rules.
help [command] display help for commandAPI
import MSGR from '@wangyjhh/msgr'
const region_msgr = new MSGR({
regionId: 'your regionId',
accessKeyId: 'your accessKeyId',
accessKeySecret: 'your accessKeySecret',
})regionId Supports values. For details, see regionIdMap
Example
Cli
Enter the command and fill in the necessary information according to the command line instructions
Get config
msgr config getSet config
msgr config setDefault config
msgr config defaultRemove config
msgr config removeClear config
msgr config clearGet Security group rules list
msgr list# The following commands will also work
msgr lsAdd Security group rules
msgr add# The following commands will also work
msgr ad
msgr insertRemove Security group rules
msgr remove# The following commands will also work
msgr rm
msgr deleteModify Security group rules
msgr modify# The following commands will also work
msgr mo
msgr editAPI
import MSGR from '@wangyjhh/msgr'
const region_msgr = new MSGR({
regionId: 'your regionId',
accessKeyId: 'your accessKeyId',
accessKeySecret: 'your accessKeySecret',
})
const main = async () => {
// get security group id
const security_group_id = (await region_msgr.getSecurityGroupId())[0]
// get security group rules
const security_group_test_rule_ifno = await region_msgr.getSecurityGroup(security_group_id, (item) => {
return item.portRange === '80/80'
})
// get security group rule id
const security_group_test_rule_id = security_group_test_rule_ifno[0].securityGroupRuleId
// add security group rules
await region_msgr.addSecurityGroup(security_group_id, {
policy: 'accept',
priority: '2',
ipProtocol: 'TCP',
portRange: '80/80',
sourceCidrIp: '0.0.0.0/0',
description: 'test',
})
// modify security group rules
await region_msgr.modifySecurityGroup(security_group_id, security_group_test_rule_id, {
policy: 'drop',
priority: '2',
ipProtocol: 'TCP',
portRange: '80/80',
sourceCidrIp: '0.0.0.0/0',
description: 'test',
})
// delete security group rules
await msgr.deleteSecurityGroup(security_group_id, security_group_test_rule_id)
}
main()