Skip to content

Commit

Permalink
Merge pull request #34 from aquasecurity/owenr-add-problems-tab
Browse files Browse the repository at this point in the history
feat: Add issues to problems tab
  • Loading branch information
Owen Rumney authored Aug 3, 2022
2 parents 6d9adb2 + e86557a commit a0bbdcc
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

All notable changes to the "tfsec" extension will be documented in this file.

### 1.11.0
- Add findings to the Problems tab

### 1.10.1
- Fix Windows filepaths

Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ To remove ignores, edit the `tfsec.excludedPath` in the `.vscode/settings.json`

## Release Notes

### 1.11.0
- Add findings to the Problems tab

### 1.10.1
- Fix Windows filepaths

Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "tfsec",
"publisher": "tfsec",
"description": "tfsec integration for Visual Studio Code",
"version": "1.10.1",
"version": "1.11.0",
"engines": {
"vscode": "^1.54.0"
},
Expand Down Expand Up @@ -235,6 +235,7 @@
"@types/uuid": "^8.3.4",
"semver": "^7.3.5",
"typescipt": "^1.0.0",
"uuid": "^8.3.2"
"uuid": "^8.3.2",
"vsce": "^2.10.0"
}
}
}
26 changes: 24 additions & 2 deletions src/explorer/issues_treeview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as path from 'path';
import { sortByCode, sortBySeverity, sortResults, uniqueLocations } from './utils';
import { CheckResult, CheckSeverity } from './check_result';
import { TfsecTreeItem, TfsecTreeItemType } from './tfsec_treeitem';
import { checkServerIdentity } from 'tls';

export class TfsecIssueProvider implements vscode.TreeDataProvider<TfsecTreeItem> {

Expand All @@ -14,8 +15,9 @@ export class TfsecIssueProvider implements vscode.TreeDataProvider<TfsecTreeItem
public rootpath: string = "";
private storagePath: string = "";
public readonly resultsStoragePath: string = "";
private diagCollection: vscode.DiagnosticCollection;

constructor(context: vscode.ExtensionContext) {
constructor(context: vscode.ExtensionContext, diagCollection: vscode.DiagnosticCollection) {
if (context.storageUri) {
this.storagePath = context.storageUri.fsPath;
console.log(`storage path is ${this.storagePath}`);
Expand All @@ -27,6 +29,8 @@ export class TfsecIssueProvider implements vscode.TreeDataProvider<TfsecTreeItem
fs.mkdirSync(this.resultsStoragePath);
}
}

this.diagCollection = diagCollection;
}

refresh(): void {
Expand All @@ -45,6 +49,9 @@ export class TfsecIssueProvider implements vscode.TreeDataProvider<TfsecTreeItem
const resultFile = path.join(this.resultsStoragePath, file);
if (fs.existsSync(resultFile)) {
let content = fs.readFileSync(resultFile, 'utf8');

let diagnostics = new Map<string, vscode.Diagnostic[]>();

try {
const data = JSON.parse(content);
if (data === null || data.results === null) {
Expand All @@ -53,12 +60,22 @@ export class TfsecIssueProvider implements vscode.TreeDataProvider<TfsecTreeItem
let results = data.results.sort(sortResults);
for (let i = 0; i < results.length; i++) {
const element = results[i];
_self.resultData.push(new CheckResult(element));
let result = new CheckResult(element);
_self.resultData.push(result);

if (diagnostics.get(result.filename) === undefined) {
diagnostics.set(result.filename, []);
}
diagnostics.get(result.filename)?.push(this.processProblem(result));
}
}
catch {
console.debug(`Error loading results file ${file}`);
}

for (let [key, value] of diagnostics) {
this.diagCollection.set(vscode.Uri.file(key), value)
}
}
})).then(() => {
_self.taintResults = !_self.taintResults;
Expand Down Expand Up @@ -165,4 +182,9 @@ export class TfsecIssueProvider implements vscode.TreeDataProvider<TfsecTreeItem
]
};
}

private processProblem(check: CheckResult): vscode.Diagnostic {
let severity = check.severity === "Critical" || check.severity === "High" || check.severity === "Medium" ? vscode.DiagnosticSeverity.Error : vscode.DiagnosticSeverity.Warning
return new vscode.Diagnostic(new vscode.Range(new vscode.Position(check.startLine -1, 0), new vscode.Position(check.endLine -1, 0)), check.summary, severity);
}
}
3 changes: 2 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ import { TfsecWrapper } from './tfsec_wrapper';
export function activate(context: vscode.ExtensionContext) {
let activeEditor = vscode.window.activeTextEditor;
var outputChannel = vscode.window.createOutputChannel("tfsec");
let diagCollection = vscode.languages.createDiagnosticCollection();

const helpProvider = new TfsecHelpProvider();
const issueProvider = new TfsecIssueProvider(context);
const issueProvider = new TfsecIssueProvider(context, diagCollection);
const tfsecWrapper = new TfsecWrapper(outputChannel, issueProvider.resultsStoragePath);

// creating the issue tree explicitly to allow access to events
Expand Down

0 comments on commit a0bbdcc

Please sign in to comment.