-
Notifications
You must be signed in to change notification settings - Fork 558
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4566 from snyk/fix/align-container-sarif-output
fix: align container sarif output
- Loading branch information
Showing
7 changed files
with
247 additions
and
126 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
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 sarif from 'sarif'; | ||
import * as groupBy from 'lodash.groupby'; | ||
import * as map from 'lodash.map'; | ||
|
||
import { SEVERITY, AnnotatedIssue } from '../snyk-test/legacy'; | ||
|
||
export function getResults(testResult): sarif.Result[] { | ||
const groupedVulnerabilities = groupBy(testResult.vulnerabilities, 'id'); | ||
return map( | ||
groupedVulnerabilities, | ||
([vuln]): sarif.Result => ({ | ||
ruleId: vuln.id, | ||
level: getLevel(vuln), | ||
message: { | ||
text: `This file introduces a vulnerable ${vuln.packageName} package with a ${vuln.severity} severity vulnerability.`, | ||
}, | ||
locations: [ | ||
{ | ||
physicalLocation: { | ||
artifactLocation: { | ||
uri: testResult.displayTargetFile, | ||
}, | ||
region: { | ||
startLine: vuln.lineNumber || 1, | ||
}, | ||
}, | ||
}, | ||
], | ||
}), | ||
); | ||
} | ||
|
||
export function getLevel(vuln: AnnotatedIssue) { | ||
switch (vuln.severity) { | ||
case SEVERITY.CRITICAL: | ||
case SEVERITY.HIGH: | ||
return 'error'; | ||
case SEVERITY.MEDIUM: | ||
return 'warning'; | ||
case SEVERITY.LOW: | ||
default: | ||
return 'note'; | ||
} | ||
} |
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
Oops, something went wrong.