-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CM-38538 - Rework scan results handling (#95)
- Loading branch information
Showing
18 changed files
with
377 additions
and
392 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import * as path from 'path'; | ||
import * as vscode from 'vscode'; | ||
import {IacDetection} from '../../types/detection'; | ||
import {extensionId} from '../../utils/texts'; | ||
import {DiagnosticCode} from '../common'; | ||
import {ScanType} from '../../constants'; | ||
import {calculateUniqueDetectionId} from '../ScanResultsService'; | ||
import {FileDiagnostics} from './types'; | ||
|
||
export const createDiagnostics = async ( | ||
detections: IacDetection[], | ||
): Promise<FileDiagnostics> => { | ||
const result: FileDiagnostics = {}; | ||
|
||
for (const detection of detections) { | ||
const {detection_details} = detection; | ||
|
||
const documentPath = detection_details.file_name; | ||
const documentUri = vscode.Uri.file(documentPath); | ||
const document = await vscode.workspace.openTextDocument(documentUri); | ||
|
||
let message = `Severity: ${detection.severity}\n`; | ||
message += `Rule: ${detection.message}\n`; | ||
|
||
message += `IaC Provider: ${detection_details.infra_provider}\n`; | ||
|
||
const fileName = path.basename(detection_details.file_name); | ||
message += `In file: ${fileName}\n`; | ||
|
||
const diagnostic = new vscode.Diagnostic( | ||
document.lineAt(detection_details.line_in_file - 1).range, | ||
message, | ||
vscode.DiagnosticSeverity.Error | ||
); | ||
|
||
diagnostic.source = extensionId; | ||
diagnostic.code = new DiagnosticCode(ScanType.Iac, calculateUniqueDetectionId(detection)).toString(); | ||
|
||
result[documentPath] = result[documentPath] || []; | ||
result[documentPath].push(diagnostic); | ||
} | ||
|
||
return result; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import * as vscode from 'vscode'; | ||
import {SastDetection} from '../../types/detection'; | ||
import {extensionId} from '../../utils/texts'; | ||
import {DiagnosticCode} from '../common'; | ||
import {ScanType} from '../../constants'; | ||
import {calculateUniqueDetectionId} from '../ScanResultsService'; | ||
import {FileDiagnostics} from './types'; | ||
|
||
export const createDiagnostics = async ( | ||
detections: SastDetection[], | ||
): Promise<FileDiagnostics> => { | ||
const result: FileDiagnostics = {}; | ||
|
||
for (const detection of detections) { | ||
const {detection_details} = detection; | ||
|
||
const documentPath = detection_details.file_path; | ||
const documentUri = vscode.Uri.file(documentPath); | ||
const document = await vscode.workspace.openTextDocument(documentUri); | ||
|
||
let message = `Severity: ${detection.severity}\n`; | ||
message += `Rule: ${detection.detection_details.policy_display_name}\n`; | ||
message += `In file: ${detection.detection_details.file_name}\n`; | ||
|
||
const diagnostic = new vscode.Diagnostic( | ||
document.lineAt(detection_details.line_in_file - 1).range, | ||
message, | ||
vscode.DiagnosticSeverity.Error | ||
); | ||
|
||
diagnostic.source = extensionId; | ||
diagnostic.code = new DiagnosticCode(ScanType.Sast, calculateUniqueDetectionId(detection)).toString(); | ||
|
||
result[documentPath] = result[documentPath] || []; | ||
result[documentPath].push(diagnostic); | ||
} | ||
|
||
return result; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import * as path from 'path'; | ||
import * as vscode from 'vscode'; | ||
import {ScaDetection} from '../../types/detection'; | ||
import {getPackageFileForLockFile, isSupportedLockFile, ScanType} from '../../constants'; | ||
import {extensionId} from '../../utils/texts'; | ||
import {DiagnosticCode} from '../common'; | ||
import {calculateUniqueDetectionId} from '../ScanResultsService'; | ||
import {FileDiagnostics} from './types'; | ||
|
||
export const createDiagnostics = async ( | ||
detections: ScaDetection[] | ||
): Promise<FileDiagnostics> => { | ||
const result: FileDiagnostics = {}; | ||
|
||
for (const detection of detections) { | ||
const {detection_details} = detection; | ||
const file_name = detection_details.file_name; | ||
const uri = vscode.Uri.file(file_name); | ||
const document = await vscode.workspace.openTextDocument(uri); | ||
|
||
let message = `Severity: ${detection.severity}\n`; | ||
message += `${detection.message}\n`; | ||
if (detection_details.alert?.first_patched_version) { | ||
message += `First patched version: ${detection_details.alert?.first_patched_version}\n`; | ||
} | ||
|
||
if (isSupportedLockFile(file_name)) { | ||
const packageFileName = getPackageFileForLockFile(path.basename(file_name)); | ||
message += `\n\nAvoid manual packages upgrades in lock files. | ||
Update the ${packageFileName} file and re-generate the lock file.`; | ||
} | ||
|
||
const diagnostic = new vscode.Diagnostic( | ||
// BE of SCA counts lines from 1, while VSCode counts from 0 | ||
document.lineAt(detection_details.line_in_file - 1).range, | ||
message, | ||
vscode.DiagnosticSeverity.Error | ||
); | ||
|
||
diagnostic.source = extensionId; | ||
diagnostic.code = new DiagnosticCode(ScanType.Sca, calculateUniqueDetectionId(detection)).toString(); | ||
|
||
result[file_name] = result[file_name] || []; | ||
result[file_name].push(diagnostic); | ||
} | ||
|
||
return result; | ||
}; |
Oops, something went wrong.