Skip to content

Commit

Permalink
Publish next version
Browse files Browse the repository at this point in the history
  • Loading branch information
DevOps committed Dec 29, 2020
1 parent e402415 commit d3112db
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 21 deletions.
27 changes: 26 additions & 1 deletion PrismaCloud.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,32 @@ const getPrismaPolicies = async (pcfgapi, cfgIndex, config, DataStore, outputWri
try {
const extras = { 'mars_tag': config.PrismaCloud[cfgIndex].tag }
const response = await axios(options)
const dataRemapped = response.data.map(entry => ({ ...entry, ...extras }))
const dataRemapped = response.data.map(entry => ({
...extras,
cloudType: entry.cloudType ? entry.cloudType : "",
createdBy: entry.createdBy ? entry.createdBy : "",
createdOn: entry.createdOn ? entry.createdOn : "",
deleted: entry.deleted,
description: entry.description ? JSON.stringify(entry.description).substring(0, 3200) + "..." : "",
enabled: entry.enabled,
labels: entry.labels && entry.labels.length > 1 ? entry.labels.slice(0, 10) : [],
lastModifiedBy: entry.lastModifiedBy ? entry.lastModifiedBy : "",
lastModifiedOn: entry.lastModifiedOn ? entry.lastModifiedOn : "",
name: entry.name ? entry.name : "",
owner: entry.owner ? entry.owner : "",
policyCategory: entry.policyCategory ? entry.policyCategory : "",
policyClass: entry.policyClass ? entry.policyClass : "",
policyId: entry.policyId ? entry.policyId : "",
policyMode: entry.policyMode ? entry.policyMode : "",
policySubTypes: entry.policySubTypes ? entry.policySubTypes : "",
policyType: entry.policyType ? entry.policyType : "",
recommendation: entry.recommendation ? JSON.stringify(entry.recommendation).substring(0, 3200) + "..." : "",
remediable: entry.remediable,
rule: entry.rule ? entry.rule : "",
ruleLastModifiedOn: entry.ruleLastModifiedOn ? entry.ruleLastModifiedOn : "",
severity: entry.severity ? entry.severity : "",
systemDefault: entry.systemDefault
}))
const dataRemappedCP = JSON.parse(JSON.stringify(dataRemapped))
await getQueryForPolicy(pcfgapi, DataStore, dataRemapped, (data) => {
ConvertTimeToHumanReadable(data)
Expand Down
56 changes: 36 additions & 20 deletions reports/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const AddDataToAggregator = async (AggregatorConfig, Data) => {
)

} else {
const csv = parse(Data.data, { header: true, encoding: 'utf8', delimiter: '\t'})
const csv = parse(Data.data, { header: true, encoding: 'utf8', delimiter: '\t' })
fs.appendFileSync(
`${entry.outputPath}/${Data.funcName}.csv`,
"\"sep=\t\"\n" + csv,
Expand All @@ -97,26 +97,42 @@ const AddDataToAggregator = async (AggregatorConfig, Data) => {
break
case SupportedTypesReport[2].toUpperCase():
try {
if (fs.existsSync(`${entry.outputPath}/${Data.funcName}.json`)) {
const jsonFile = fs.readFileSync(`${entry.outputPath}/${Data.funcName}.json`, 'UTF-8');
const JSONFILEData = JSON.parse(jsonFile)
fs.writeFileSync(
`${entry.outputPath}${Data.funcName}.json`,
JSON.stringify([...JSONFILEData, ...Data.data], null, 4),
function (err) {
if (err) return console.log(err)
console.log(`Wrote succesfully the ${entry.outputPath}${Data.funcName}.json file`)
}
)
if (Data.funcName == "getPrismaPolicies") {
if (!fs.existsSync(`${entry.outputPath}${Data.funcName}`)) {
fs.mkdirSync(`${entry.outputPath}${Data.funcName}`)
}
for (const dataEntry of Data.data) {
fs.writeFileSync(
`${entry.outputPath}${Data.funcName}/${dataEntry.name.replace(/ /g,"_").replace(/\/|\:/g,"-").substring(0, 16)+"-"+dataEntry.policyId.substr(dataEntry.policyId.length - 5)}.json`,
JSON.stringify(dataEntry, null, 4),
function (err) {
if (err) return console.log(err)
console.log(`Wrote succesfully the ${entry.outputPath}${Data.funcName}.json file`)
}
)
}
} else {
fs.appendFileSync(
`${entry.outputPath}${Data.funcName}.json`,
JSON.stringify(Data.data, null, 4),
function (err) {
if (err) return console.log(err)
console.log(`Wrote succesfully the ${entry.outputPath}${Data.funcName}.json file`)
}
)
if (fs.existsSync(`${entry.outputPath}/${Data.funcName}.json`)) {
const jsonFile = fs.readFileSync(`${entry.outputPath}/${Data.funcName}.json`, 'UTF-8');
const JSONFILEData = JSON.parse(jsonFile)
fs.writeFileSync(
`${entry.outputPath}${Data.funcName}.json`,
JSON.stringify([...JSONFILEData, ...Data.data], null, 4),
function (err) {
if (err) return console.log(err)
console.log(`Wrote succesfully the ${entry.outputPath}${Data.funcName}.json file`)
}
)
} else {
fs.appendFileSync(
`${entry.outputPath}${Data.funcName}.json`,
JSON.stringify(Data.data, null, 4),
function (err) {
if (err) return console.log(err)
console.log(`Wrote succesfully the ${entry.outputPath}${Data.funcName}.json file`)
}
)
}
}
} catch (err) {
console.log('error: ', err)
Expand Down

0 comments on commit d3112db

Please sign in to comment.