Skip to content

Commit 6a957b3

Browse files
committed
update
1 parent abb33f6 commit 6a957b3

File tree

2 files changed

+80
-68
lines changed

2 files changed

+80
-68
lines changed

Diff for: src/appmixer/wiz/core/UploadSecurityScan/UploadSecurityScan.js

+35-37
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,6 @@ const requestUpload = async function(context, { filename }) {
9191
return data.data.requestSecurityScanUpload.upload;
9292
};
9393

94-
async function streamToString(stream) {
95-
// lets have a ReadableStream as a stream variable
96-
const chunks = [];
97-
98-
for await (const chunk of stream) {
99-
chunks.push(Buffer.from(chunk));
100-
}
101-
102-
return Buffer.concat(chunks).toString('utf-8');
103-
}
104-
10594
const uploadFile = async function(context, { url, fileContent }) {
10695

10796
const upload = await context.httpRequest({
@@ -112,43 +101,52 @@ const uploadFile = async function(context, { url, fileContent }) {
112101
'Content-Type': 'application/json'
113102
}
114103
});
115-
context.log({ stage: 'upload finished', uploadData: upload.statusCode });
104+
await context.log({ stage: 'upload finished', uploadData: upload.statusCode, fileContent });
116105
};
117106

118-
const getFile = async function(context) {
119-
120-
const { filename, fileId, fileContent } = context.messages.in.content;
121-
122-
let json;
123-
let name;
124-
if (fileId) {
125-
const fileInfo = await context.getFileInfo(fileId);
126-
const stream = await context.getFileReadStream(fileId);
127-
json = await streamToString(stream);
128-
name = filename || fileInfo.filename;
129-
} else {
130-
try {
131-
json = JSON.parse(fileContent);
132-
name = filename || 'incident-report.json';
133-
} catch (e) {
134-
throw new context.CancelError('Invalid Input: FileContent', e);
135-
}
136-
}
137-
138-
return { content: json, name };
107+
const createDocument = function(context) {
108+
109+
const {
110+
integrationId,
111+
dataSourceId: id,
112+
dataSourceAnalysisDate: analysisDate,
113+
cloudPlatform,
114+
providerId,
115+
vulnerabilityFindings
116+
} = context.messages.in.content;
117+
118+
return {
119+
120+
integrationId,
121+
'dataSources': [{
122+
id,
123+
analysisDate,
124+
'assets': [
125+
{
126+
'assetIdentifier': {
127+
cloudPlatform,
128+
providerId
129+
},
130+
'vulnerabilityFindings': vulnerabilityFindings.AND.map(finding => {
131+
return { ...finding };
132+
})
133+
}
134+
]
135+
}]
136+
};
139137
};
140138

141139
module.exports = {
142140

143141
// docs: https://win.wiz.io/reference/pull-cloud-resources
144142
async receive(context) {
145143

146-
const { name, fileContent } = await getFile(context);
144+
const { filename } = context.messages.in.content;
147145

148-
const { url, systemActivityId } = await requestUpload(context, { filename: name });
149-
context.log({ stage: 'requestUpload response ', url, systemActivityId });
146+
const { url, systemActivityId } = await requestUpload(context, { filename });
147+
await context.log({ stage: 'requestUpload response ', url, systemActivityId });
150148

151-
await uploadFile(context, { url, fileContent });
149+
await uploadFile(context, { url, fileContent: createDocument(context) });
152150

153151
const status = await getStatus(context, systemActivityId);
154152
return context.sendJson(status, 'out');

Diff for: src/appmixer/wiz/core/UploadSecurityScan/component.json

+45-31
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
"schema": {
1818
"type": "object",
1919
"properties": {
20+
"filename": {
21+
"type": "string"
22+
},
2023
"integrationId": {
2124
"type": "string"
2225
},
@@ -29,11 +32,10 @@
2932
"providerId": {
3033
"type": "string"
3134
},
32-
"vulnerabilityFindings": {
33-
"type": "array"
34-
}
35+
"vulnerabilityFindings": { }
3536
},
3637
"required": [
38+
"filename",
3739
"integrationId",
3840
"dataSourceId",
3941
"cloudPlatform",
@@ -43,6 +45,11 @@
4345
},
4446
"inspector": {
4547
"inputs": {
48+
"filename": {
49+
"type": "text",
50+
"label": "File Name",
51+
"index": 0
52+
},
4653
"integrationId": {
4754
"type": "text",
4855
"label": "Integration ID",
@@ -55,10 +62,19 @@
5562
"tooltip": "The ID that uniquely identifies asset findings within a tenant and integration ID. Can be a subscription ID.",
5663
"index": 1
5764
},
65+
"dataSourceAnalysisDate": {
66+
"type": "date-time",
67+
"label": "Analysis Date",
68+
"tooltip": "The date the scan was performed.",
69+
"config": {
70+
"enableTime": true
71+
},
72+
"index": 1
73+
},
5874
"providerId": {
5975
"type": "text",
6076
"label": "Provider ID",
61-
"tooltip": "A unique identifier assigned to a specific cloud asset by the cloud service provider when the asset is created, allowing for the identification and differentiation of the asset within the cloud computing ecosystem. ARN—AWS, Resource group—Azure.",
77+
"tooltip": "A unique identifier assigned to a specific cloud asset by the cloud service provider when the asset is created, allowing for the identification and differentiation of the asset within the cloud computing ecosystem.",
6278
"index": 2
6379
},
6480
"cloudPlatform": {
@@ -113,21 +129,29 @@
113129
"externalDetectionSource": {
114130
"type": "select",
115131
"index": 2,
116-
"label": "Severity",
117-
"defaultValue": "Medium",
132+
"label": "External Detection Source",
133+
"defaultValue": "Package",
118134
"tooltip": "The severity of the vulnerability. Default is Medium",
119135
"required": true,
120136
"options": [
121137
{ "label": "Package", "value": "Package" },
122-
{ "label": "Default Package", "value": "Default Package" },
138+
{ "label": "Default Package", "value": "DefaultPackage" },
123139
{ "label": "Library", "value": "Library" },
124-
{ "label": "Operating System", ",value": "Operating System" },
125-
{ "label": "Installed Program (Windows)", "value": "Installed Program (Windows)" },
126-
{
127-
"label": "Installed Program By Service (Windows)",
128-
"value": "Installed Program By Service (Windows)"
129-
},
130-
{ "label": "File Path", "value": "File Path" }
140+
{ "label": "Config File", "value": "ConfigFile" },
141+
{ "label": "Open Port", "value": "OpenPort" },
142+
{ "label": "Startup Service", "value": "StartupService" },
143+
{ "label": "Configuration", "value": "Configuration" },
144+
{ "label": "Cloned Repository", "value": "ClonedRepository" },
145+
{ "label": "OS", "value": "OS" },
146+
{ "label": "Artifacts On Disk", "value": "ArtifactsOnDisk" },
147+
{ "label": "Windows Registry", "value": "WindowsRegistry" },
148+
{ "label": "Installed Program", "value": "InstalledProgram" },
149+
{ "label": "File Path", "value": "FilePath" },
150+
{ "label": "Windows Service", "value": "WindowsService" },
151+
{ "label": "Installed Program By Service", "value": "InstalledProgramByService" },
152+
{ "label": "Hosted Database Scan", "value": "HostedDatabaseScan" },
153+
{ "label": "External Network Scan", "value": "ExternalNetworkScan" },
154+
{ "label": "Cloud API", "value": "CloudAPI" }
131155
]
132156
},
133157
"externalFindingLink": {
@@ -136,10 +160,10 @@
136160
"label": "External Finding Link",
137161
"tooltip": "A link to the source of the external finding."
138162
},
139-
"detailsName": {
163+
"detailedName": {
140164
"type": "text",
141165
"index": 1,
142-
"label": "Details Name",
166+
"label": "Detailed Name",
143167
"tooltip": "The details of the externalDetectionSource, such as \"Package,\" should include relevant information about the package. For instance, if the externalDetectionSource is \"libncurses6,\" the \"Details Name\" should reflect details about the package, such as \"libncurses6 package.\"."
144168
},
145169
"version": {
@@ -154,37 +178,27 @@
154178
"label": "Description",
155179
"tooltip": "A description of the finding."
156180
},
157-
"sourceName": {
181+
"source": {
158182
"type": "text",
159183
"index": 1,
160-
"label": "Source Name",
184+
"label": "Source",
161185
"tooltip": "The name of the product that detected the vulnerability."
162186
},
163187
"remediation": {
164188
"type": "text",
165189
"index": 1,
166190
"label": "Remediation",
191+
"required": true,
167192
"tooltip": "The remediation for the vulnerability."
168193
},
169-
"validatedInRuntime": {
194+
"validatedAtRuntime": {
170195
"type": "toggle",
171196
"index": 1,
172-
"label": "Validated In Runtime",
197+
"label": "Validated At Runtime",
173198
"defaultValue": false,
174199
"tooltip": "Indicates if the finding was detected during runtime (true), or if it was detected during offline or static scanning (false)."
175200
}
176201
}
177-
},
178-
"filename": {
179-
"type": "text",
180-
"label": "File Name",
181-
"index": 0
182-
},
183-
"fileContent": {
184-
"type": "textarea",
185-
"index": 1,
186-
"label": "File Content",
187-
"tooltip": "Specify the file content in JSON format <b>(Ignored if 'File ID' is set)</b>."
188202
}
189203
}
190204
}

0 commit comments

Comments
 (0)