From d3112db80a90fb45b1c84517fb3bab7851472937 Mon Sep 17 00:00:00 2001 From: DevOps Date: Tue, 29 Dec 2020 16:48:25 +0000 Subject: [PATCH] Publish next version --- PrismaCloud.js | 27 ++++++++++++++++++++++- reports/report.js | 56 ++++++++++++++++++++++++++++++----------------- 2 files changed, 62 insertions(+), 21 deletions(-) diff --git a/PrismaCloud.js b/PrismaCloud.js index 58c3b64..91bc5b6 100644 --- a/PrismaCloud.js +++ b/PrismaCloud.js @@ -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) diff --git a/reports/report.js b/reports/report.js index 618b684..fb3f2ff 100644 --- a/reports/report.js +++ b/reports/report.js @@ -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, @@ -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)