Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
vtalas committed Sep 4, 2024
1 parent bed132d commit 74caf0b
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
1 change: 1 addition & 0 deletions src/appmixer/wiz/core/FindCloudResources/component.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"limit": {
"type": "number",
"label": "Limit",
"defaultValue": 100,
"index": 1
},
"outputType": {
Expand Down
36 changes: 28 additions & 8 deletions src/appmixer/wiz/core/UploadSecurityScan/UploadSecurityScan.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,33 +102,53 @@ 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'
}
});
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');
Expand Down
11 changes: 10 additions & 1 deletion src/appmixer/wiz/core/UploadSecurityScan/component.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
"filename": { "type": "string" },
"fileId": { "type": "string" }
},
"required": [ "fileId"]
"anyOf": [
{ "required": ["fileId"] },
{ "required": ["fileContent"] }
]
},
"inspector": {
"inputs": {
Expand All @@ -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 <b>(Ignored if 'File ID' is set)</b>."
}
}
}
Expand Down

0 comments on commit 74caf0b

Please sign in to comment.