Skip to content

Commit 0f4825e

Browse files
committed
Parse checkov results
1 parent 4af7f32 commit 0f4825e

3 files changed

Lines changed: 56 additions & 6 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ Currently supported tools include:
7373
- semgrep (https://semgrep.dev/)
7474
- bandit (https://bandit.readthedocs.io/en/latest/)
7575
- brakeman (https://brakemanscanner.org/)
76+
- checkov (https://www.checkov.io/)
7677

7778
## Extension Settings
7879

src/parsers/checkov.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
'use strict';
2+
3+
import * as vscode from 'vscode';
4+
import { ToolFinding } from '../models/toolFinding';
5+
6+
class CheckovParser {
7+
static parse(fileContent: string) {
8+
const toolFindings: ToolFinding[] = [];
9+
10+
try {
11+
const checkovCheckTypes = JSON.parse(fileContent);
12+
checkovCheckTypes.map((checkovCheckType: any) => {
13+
const checkovFindings = checkovCheckType.results.failed_checks;
14+
checkovFindings.map((checkovFinding: any) => {
15+
// uri
16+
let fullPath = '';
17+
if (vscode.workspace.workspaceFolders) {
18+
fullPath = vscode.workspace.workspaceFolders[0].uri.fsPath + '/';
19+
}
20+
const uri = vscode.Uri.file(`${fullPath}${checkovFinding.file_path}`);
21+
22+
// range
23+
const range = new vscode.Range(
24+
checkovFinding.file_line_range[0] - 1,
25+
0,
26+
checkovFinding.file_line_range[1] - 1,
27+
0,
28+
);
29+
30+
// instantiate tool finding and add to list
31+
const toolFinding = new ToolFinding(uri, range, checkovFinding.check_name);
32+
toolFindings.push(toolFinding);
33+
});
34+
});
35+
} catch {
36+
/* empty */
37+
}
38+
39+
return toolFindings;
40+
}
41+
}
42+
43+
export { CheckovParser };

src/webviews/importToolResultsWebview.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
import * as vscode from 'vscode';
44
import { commentController } from '../controllers/comments';
55
import { BanditParser } from '../parsers/bandit';
6-
import { SemgrepParser } from '../parsers/semgrep';
76
import { BrakemanParser } from '../parsers/brakeman';
7+
import { CheckovParser } from '../parsers/checkov';
8+
import { SemgrepParser } from '../parsers/semgrep';
89
import { ToolFinding } from '../models/toolFinding';
910
import { saveNoteComment } from '../helpers';
1011
import { RemoteDb } from '../persistence/remote-db';
@@ -82,9 +83,10 @@ export class ImportToolResultsWebview implements vscode.WebviewViewProvider {
8283
<p>Select tool:</p>
8384
<p>
8485
<select id="toolSelect">
85-
<option value="semgrep">semgrep</option>
8686
<option value="bandit">bandit</option>
8787
<option value="brakeman">brakeman</option>
88+
<option value="checkov">checkov</option>
89+
<option value="semgrep">semgrep</option>
8890
</select>
8991
</p>
9092
<p>Select file:</p>
@@ -110,10 +112,6 @@ function processToolFile(
110112

111113
// parse tool findings
112114
switch (toolName) {
113-
case 'semgrep': {
114-
toolFindings = SemgrepParser.parse(fileContent);
115-
break;
116-
}
117115
case 'bandit': {
118116
toolFindings = BanditParser.parse(fileContent);
119117
break;
@@ -122,6 +120,14 @@ function processToolFile(
122120
toolFindings = BrakemanParser.parse(fileContent);
123121
break;
124122
}
123+
case 'checkov': {
124+
toolFindings = CheckovParser.parse(fileContent);
125+
break;
126+
}
127+
case 'semgrep': {
128+
toolFindings = SemgrepParser.parse(fileContent);
129+
break;
130+
}
125131
}
126132

127133
if (!toolFindings.length) {

0 commit comments

Comments
 (0)