From 74caf0b900013579951ed619123e11661edd7b50 Mon Sep 17 00:00:00 2001 From: vladimir talas Date: Wed, 4 Sep 2024 09:54:43 +0200 Subject: [PATCH] update --- .../FindCloudResources/FindCloudResources.js | 2 +- .../core/FindCloudResources/component.json | 1 + .../UploadSecurityScan/UploadSecurityScan.js | 36 ++++++++++++++----- .../core/UploadSecurityScan/component.json | 11 +++++- 4 files changed, 40 insertions(+), 10 deletions(-) diff --git a/src/appmixer/wiz/core/FindCloudResources/FindCloudResources.js b/src/appmixer/wiz/core/FindCloudResources/FindCloudResources.js index 5ce748d21..afe3c425b 100644 --- a/src/appmixer/wiz/core/FindCloudResources/FindCloudResources.js +++ b/src/appmixer/wiz/core/FindCloudResources/FindCloudResources.js @@ -120,7 +120,7 @@ module.exports = { let records = []; let nextPageToken = null; let totalRecordsCount = 0; - const PAGE_SIZE = 5; + const PAGE_SIZE = 500; do { const { data } = await lib.makeApiCall({ diff --git a/src/appmixer/wiz/core/FindCloudResources/component.json b/src/appmixer/wiz/core/FindCloudResources/component.json index ce055de75..711e2dc50 100644 --- a/src/appmixer/wiz/core/FindCloudResources/component.json +++ b/src/appmixer/wiz/core/FindCloudResources/component.json @@ -34,6 +34,7 @@ "limit": { "type": "number", "label": "Limit", + "defaultValue": 100, "index": 1 }, "outputType": { diff --git a/src/appmixer/wiz/core/UploadSecurityScan/UploadSecurityScan.js b/src/appmixer/wiz/core/UploadSecurityScan/UploadSecurityScan.js index b784a0d7f..58e6900e4 100644 --- a/src/appmixer/wiz/core/UploadSecurityScan/UploadSecurityScan.js +++ b/src/appmixer/wiz/core/UploadSecurityScan/UploadSecurityScan.js @@ -102,14 +102,12 @@ async function streamToString(stream) { return Buffer.concat(chunks).toString('utf-8'); } -const uploadFile = async function(context, { url, fileId }) { - - const stream = await context.getFileReadStream(fileId); +const uploadFile = async function(context, { url, fileContent }) { const upload = await context.httpRequest({ method: 'PUT', url, - data: await streamToString(stream), // stream upload is not implemented on the wiz side + data: fileContent, // stream upload is not implemented on the wiz side headers: { 'Content-Type': 'application/json' } @@ -117,18 +115,40 @@ const uploadFile = async function(context, { url, fileId }) { context.log({ stage: 'upload finished', uploadData: upload.statusCode }); }; +const getFile = async function(context) { + + const { filename, fileId, fileContent } = context.messages.in.content; + + let json; + let name; + if (fileId) { + const fileInfo = await context.getFileInfo(fileId); + const stream = await context.getFileReadStream(fileId); + json = await streamToString(stream); + name = filename || fileInfo.filename; + } else { + try { + json = JSON.parse(fileContent); + name = filename || 'incident-report.json'; + } catch (e) { + throw new context.CancelError('Invalid Input: FileContent', e); + } + } + + return { content: json, name }; +}; + module.exports = { // docs: https://win.wiz.io/reference/pull-cloud-resources async receive(context) { - const { filename, fileId } = context.messages.in.content; - const fileInfo = await context.getFileInfo(fileId); + const { name, fileContent } = await getFile(context); - const { url, systemActivityId } = await requestUpload(context, { filename: filename || fileInfo.filename }); + const { url, systemActivityId } = await requestUpload(context, { filename: name }); context.log({ stage: 'requestUpload response ', url, systemActivityId }); - await uploadFile(context, { url, fileId }); + await uploadFile(context, { url, fileContent }); const status = await getStatus(context, systemActivityId); return context.sendJson(status, 'out'); diff --git a/src/appmixer/wiz/core/UploadSecurityScan/component.json b/src/appmixer/wiz/core/UploadSecurityScan/component.json index 7017d944b..0965cccb4 100644 --- a/src/appmixer/wiz/core/UploadSecurityScan/component.json +++ b/src/appmixer/wiz/core/UploadSecurityScan/component.json @@ -20,7 +20,10 @@ "filename": { "type": "string" }, "fileId": { "type": "string" } }, - "required": [ "fileId"] + "anyOf": [ + { "required": ["fileId"] }, + { "required": ["fileContent"] } + ] }, "inspector": { "inputs": { @@ -34,6 +37,12 @@ "index": 1, "label": "File ID", "tooltip": "Select an existing file to upload. Or provide File ID of the file you want to upload." + }, + "fileContent": { + "type": "textarea", + "index": 1, + "label": "File Content", + "tooltip": "Specify the file content in JSON format (Ignored if 'File ID' is set)." } } }