forked from secureCodeBox/secureCodeBox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser-wrapper.js
More file actions
72 lines (59 loc) · 1.65 KB
/
parser-wrapper.js
File metadata and controls
72 lines (59 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
const axios = require("axios");
const { parse } = require("./parser/parser");
const { v4: uuid } = require('uuid');
const k8s = require("@kubernetes/client-node");
const {
uploadFile,
NAMESPACE,
SCAN_NAME,
updateScanStatus
} = require("../../scb-sdk/nodejs/scb-sdk");
const kc = new k8s.KubeConfig();
kc.loadFromCluster();
const k8sApi = kc.makeApiClient(k8s.CustomObjectsApi);
async function extractScan() {
try {
const { body } = await k8sApi.getNamespacedCustomObject(
"execution.securecodebox.io",
"v1",
NAMESPACE,
"scans",
SCAN_NAME
);
return body;
} catch (err) {
console.error("Failed to get Scan from the kubernetes api");
console.error(err);
process.exit(1);
}
}
async function main() {
console.log("Starting Parser");
let scan = await extractScan();
const resultFileUrl = process.argv[2];
const resultUploadUrl = process.argv[3];
console.log("Fetching result file");
const { data } = await axios.get(resultFileUrl);
console.log("Fetched result file");
let findings = [];
try {
findings = await parse(data, scan);
} catch (error) {
console.error("Parser failed with error:");
console.error(error);
process.exit(1);
}
console.log(`Transformed raw result file into ${findings.length} findings`);
console.log("Adding UUIDs to the findings");
const findingsWithIds = findings.map((finding) => {
return {
...finding,
id: uuid(),
};
});
await updateScanStatus(findings);
console.log(`Uploading results to the file storage service`);
await uploadFile(resultUploadUrl, findingsWithIds)
console.log(`Completed parser`);
}
main();