From 7e7d0acfb5df07177705dcec8b00f7f8b10e110a Mon Sep 17 00:00:00 2001 From: Torsten Cannell <38391283+Torsten1014@users.noreply.github.com> Date: Mon, 13 May 2024 10:32:12 -0700 Subject: [PATCH 1/6] fix: json output to console --- .gitignore | 1 + lib/snyk-filter.js | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index ea67ddc..2080dd8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ node_modules .dccache dist +.vscode diff --git a/lib/snyk-filter.js b/lib/snyk-filter.js index 709b608..f4f1497 100644 --- a/lib/snyk-filter.js +++ b/lib/snyk-filter.js @@ -20,17 +20,20 @@ var options = { path: path.dirname(__dirname).split(path.sep).pop(), }; +var results = [] + function onDataCallback(data, reportCallback) { const jqFilterString = customFilters.filter; const jqPassString = customFilters.pass; const failMsg = customFilters.msg; - data = JSON.parse(data); + const data = JSON.parse(data); + const inputLen = data.length; if (Array.isArray(data)) { data.map((dataItem) => { - processResults(dataItem, jqFilterString, jqPassString, failMsg); + processResults(dataItem, jqFilterString, jqPassString, failMsg, inputLen); }); } else { - processResults(data, jqFilterString, jqPassString, failMsg); + processResults(data, jqFilterString, jqPassString, failMsg, inputLen); } } @@ -81,14 +84,18 @@ function run(source, reportCallback, filters, cliOptions = null) { } } -function processResults(data, filterString, passString, failMsg) { +function processResults(data, filterString, passString, failMsg, inputLen) { filter(data, filterString) //.then((filteredData) => aggregate(filteredData)) //.then((processedData) => {reportCallback(processedData)}) .then((processedData) => { if (options && options.json) { console.warn("json output enabled"); - console.log(JSON.stringify(processedData, null, 2)); + // console.log(JSON.stringify(processedData, null, 2)); + results.push(processedData); + if (results.length == inputLen || !inputLen) { + console.log(JSON.stringify(results)); + } } else if (data.infrastructureAsCodeIssues) { var response = snykDisplay.displayIACResult( processedData, @@ -154,7 +161,7 @@ function pass(data, passString, passFailMsg) { jq.run(query, data, options) .then((output) => { if (output == 0) { - console.info( + console.warn( `${chalk.yellow( data.projectName || data.path )} - No issues found after custom filtering` From ced516b990d2f045b68ecc828f85d85493cf879f Mon Sep 17 00:00:00 2001 From: Torsten Cannell <38391283+Torsten1014@users.noreply.github.com> Date: Mon, 13 May 2024 11:16:56 -0700 Subject: [PATCH 2/6] fix: syntax error --- lib/snyk-filter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/snyk-filter.js b/lib/snyk-filter.js index f4f1497..250fcec 100644 --- a/lib/snyk-filter.js +++ b/lib/snyk-filter.js @@ -26,8 +26,8 @@ function onDataCallback(data, reportCallback) { const jqFilterString = customFilters.filter; const jqPassString = customFilters.pass; const failMsg = customFilters.msg; - const data = JSON.parse(data); const inputLen = data.length; + data = JSON.parse(data); if (Array.isArray(data)) { data.map((dataItem) => { processResults(dataItem, jqFilterString, jqPassString, failMsg, inputLen); From 89aff5290cae627db417da617befaaa54a873532 Mon Sep 17 00:00:00 2001 From: Torsten Cannell <38391283+Torsten1014@users.noreply.github.com> Date: Mon, 13 May 2024 11:37:43 -0700 Subject: [PATCH 3/6] use 'Prettier' format --- lib/snyk-filter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/snyk-filter.js b/lib/snyk-filter.js index 250fcec..81e46b3 100644 --- a/lib/snyk-filter.js +++ b/lib/snyk-filter.js @@ -20,7 +20,7 @@ var options = { path: path.dirname(__dirname).split(path.sep).pop(), }; -var results = [] +var results = []; function onDataCallback(data, reportCallback) { const jqFilterString = customFilters.filter; From 5e36f7fc0cd8150e95b15694533371acb4007786 Mon Sep 17 00:00:00 2001 From: Torsten Cannell <38391283+Torsten1014@users.noreply.github.com> Date: Wed, 15 May 2024 15:41:35 -0700 Subject: [PATCH 4/6] fix: parse data before getting length --- lib/snyk-filter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/snyk-filter.js b/lib/snyk-filter.js index 81e46b3..a9e14c6 100644 --- a/lib/snyk-filter.js +++ b/lib/snyk-filter.js @@ -26,8 +26,8 @@ function onDataCallback(data, reportCallback) { const jqFilterString = customFilters.filter; const jqPassString = customFilters.pass; const failMsg = customFilters.msg; - const inputLen = data.length; data = JSON.parse(data); + const inputLen = data.length; if (Array.isArray(data)) { data.map((dataItem) => { processResults(dataItem, jqFilterString, jqPassString, failMsg, inputLen); From 3cc62841fa4d72c398441661ab6f8e15c9aa6623 Mon Sep 17 00:00:00 2001 From: Torsten Cannell <38391283+Torsten1014@users.noreply.github.com> Date: Wed, 15 May 2024 16:04:56 -0700 Subject: [PATCH 5/6] fix: promise state should be 'resolve' when an object is filtered --- lib/snyk-filter.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/snyk-filter.js b/lib/snyk-filter.js index a9e14c6..6c455ea 100644 --- a/lib/snyk-filter.js +++ b/lib/snyk-filter.js @@ -168,9 +168,10 @@ function pass(data, passString, passFailMsg) { ); resolve(true); } else { - reject( + console.warn( `${chalk.yellow(data.projectName || data.path)} - ${passFailMsg}` ); + resolve(true); } }) .catch((err) => { From 73fc200fb46cf6758be7772a9d35dcde3191d563 Mon Sep 17 00:00:00 2001 From: Torsten Cannell <38391283+Torsten1014@users.noreply.github.com> Date: Wed, 22 May 2024 08:44:18 -0700 Subject: [PATCH 6/6] fix: json output to console BREAKING CHANGE: fix json output --- lib/snyk-filter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/snyk-filter.js b/lib/snyk-filter.js index 6c455ea..67a3193 100644 --- a/lib/snyk-filter.js +++ b/lib/snyk-filter.js @@ -164,7 +164,7 @@ function pass(data, passString, passFailMsg) { console.warn( `${chalk.yellow( data.projectName || data.path - )} - No issues found after custom filtering` + )} - No issues found after custom filtering.` ); resolve(true); } else {