Last active
May 21, 2022 22:28
-
-
Save felipecosta09/636fb28b8e4fbefaf8350013d6d7cd4f to your computer and use it in GitHub Desktop.
Moving your Group Structure from Deep Security to Cloud One Workload Security
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
const inquirer = require('inquirer'); | |
const fs = require('fs'); | |
const http = require("https"); | |
const service = 'workload.' | |
const cloudOneUrl = '.cloudone.trendmicro.com' | |
const path = "./parameters.json" | |
if (fs.existsSync(path)) { | |
const readParameters = JSON.parse(fs.readFileSync('parameters.json')) | |
const dsmApiKey = readParameters["dsmApiKey"]; | |
const dsmHost = readParameters["dsmHost"]; | |
const dsmPort = readParameters["dsmPort"]; | |
const c1ApiKey = readParameters["c1ApiKey"]; | |
const c1Region = readParameters["c1Region"]; | |
const fullCloudOneUrl = service+c1Region+cloudOneUrl | |
const options = { | |
"method": "GET", | |
"hostname": fullCloudOneUrl, | |
"port": null, | |
"path": "/api/computergroups", | |
"headers": { | |
"Authorization": "ApiKey "+c1ApiKey, | |
"api-version": "v1" | |
} | |
}; | |
const req = http.request(options, function (res) { | |
const chunks = []; | |
res.on("data", function (chunk) { | |
chunks.push(chunk); | |
}); | |
res.on("end", function () { | |
const body = Buffer.concat(chunks); | |
let groupInfoJson = JSON.parse(body.toString()); | |
// Export all groups names, description and parentId from DSM to an Array | |
const groupNames = [] | |
const groupDescritpion = [] | |
const groupParentId = [] | |
const groupNameIteraction = groupInfoJson.computerGroups.forEach(individualName => {groupNames.push(individualName.name)}); | |
const groupDescriptionIteraction = groupInfoJson.computerGroups.forEach(individualName => {groupDescritpion.push(individualName.description)}); | |
const groupParentIdIteraction = groupInfoJson.computerGroups.forEach(individualName => {groupParentId.push(individualName.parentGroupID)}); | |
// Count how many groups will be created | |
const groupCount = groupNames.length | |
}); | |
}); | |
req.end(); | |
} | |
else { | |
inquirer.prompt([ | |
{ | |
type: 'password', | |
name: 'dsmApiKey', | |
message: 'What is your DSM API KEY?', | |
}, | |
{ | |
name: 'dsmHost', | |
message: 'What is your DSM FQDN?', | |
}, | |
{ | |
type: 'number', | |
name: 'dsmPort', | |
message: 'What is your DSM port?', | |
default: '4119' | |
}, | |
{ | |
type: 'password', | |
name: 'c1ApiKey', | |
message: 'What is your Cloud One API KEY?', | |
}, | |
{ | |
type: 'list', | |
name: 'c1Region', | |
message: 'What is your Cloud One region?', | |
choices: ['us-1', 'jp-1', 'in-1', 'sg-1', 'ca-1', 'gb-1', 'de-1', 'au-1'], | |
}, | |
]).then((answer) => { | |
fs.writeFileSync('parameters.json', JSON.stringify(answer)); | |
})}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment