mirror of
https://github.com/anchore/grype
synced 2024-09-20 14:31:59 +00:00
fix replacement of results with matches (#158)
Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
This commit is contained in:
parent
f0f8f4bf02
commit
c73a33700a
2 changed files with 6 additions and 7 deletions
|
@ -12,8 +12,8 @@ import (
|
||||||
"github.com/anchore/grype/grype"
|
"github.com/anchore/grype/grype"
|
||||||
"github.com/anchore/grype/grype/event"
|
"github.com/anchore/grype/grype/event"
|
||||||
"github.com/anchore/grype/grype/grypeerr"
|
"github.com/anchore/grype/grype/grypeerr"
|
||||||
|
"github.com/anchore/grype/grype/match"
|
||||||
"github.com/anchore/grype/grype/presenter"
|
"github.com/anchore/grype/grype/presenter"
|
||||||
"github.com/anchore/grype/grype/result"
|
|
||||||
"github.com/anchore/grype/grype/vulnerability"
|
"github.com/anchore/grype/grype/vulnerability"
|
||||||
"github.com/anchore/grype/internal"
|
"github.com/anchore/grype/internal"
|
||||||
"github.com/anchore/grype/internal/bus"
|
"github.com/anchore/grype/internal/bus"
|
||||||
|
@ -190,7 +190,7 @@ func startWorker(userInput string, failOnSeverity *vulnerability.Severity) <-cha
|
||||||
// determine if there are any severities >= to the max allowable severity (which is optional).
|
// determine if there are any severities >= to the max allowable severity (which is optional).
|
||||||
// note: until the shared file lock in sqlittle is fixed the sqlite DB cannot be access concurrently,
|
// note: until the shared file lock in sqlittle is fixed the sqlite DB cannot be access concurrently,
|
||||||
// implying that the fail-on-severity check must be done before sending the presenter object.
|
// implying that the fail-on-severity check must be done before sending the presenter object.
|
||||||
if hitSeverityThreshold(failOnSeverity, results, metadataProvider) {
|
if hitSeverityThreshold(failOnSeverity, matches, metadataProvider) {
|
||||||
errs <- grypeerr.ErrAboveSeverityThreshold
|
errs <- grypeerr.ErrAboveSeverityThreshold
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -210,10 +210,10 @@ func runDefaultCmd(_ *cobra.Command, args []string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// hitSeverityThreshold indicates if there are any severities >= to the max allowable severity (which is optional)
|
// hitSeverityThreshold indicates if there are any severities >= to the max allowable severity (which is optional)
|
||||||
func hitSeverityThreshold(thresholdSeverity *vulnerability.Severity, results result.Result, metadataProvider vulnerability.MetadataProvider) bool {
|
func hitSeverityThreshold(thresholdSeverity *vulnerability.Severity, matches match.Matches, metadataProvider vulnerability.MetadataProvider) bool {
|
||||||
if thresholdSeverity != nil {
|
if thresholdSeverity != nil {
|
||||||
var maxDiscoveredSeverity vulnerability.Severity
|
var maxDiscoveredSeverity vulnerability.Severity
|
||||||
for m := range results.Enumerate() {
|
for m := range matches.Enumerate() {
|
||||||
metadata, err := metadataProvider.GetMetadata(m.Vulnerability.ID, m.Vulnerability.RecordSource)
|
metadata, err := metadataProvider.GetMetadata(m.Vulnerability.ID, m.Vulnerability.RecordSource)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -2,7 +2,6 @@ package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/anchore/grype/grype/match"
|
"github.com/anchore/grype/grype/match"
|
||||||
"github.com/anchore/grype/grype/result"
|
|
||||||
"github.com/anchore/grype/grype/vulnerability"
|
"github.com/anchore/grype/grype/vulnerability"
|
||||||
"github.com/anchore/syft/syft/pkg"
|
"github.com/anchore/syft/syft/pkg"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -42,7 +41,7 @@ func TestAboveAllowableSeverity(t *testing.T) {
|
||||||
Type: pkg.RpmPkg,
|
Type: pkg.RpmPkg,
|
||||||
}
|
}
|
||||||
|
|
||||||
matches := result.NewResult()
|
matches := match.NewMatches()
|
||||||
matches.Add(thePkg, match.Match{
|
matches.Add(thePkg, match.Match{
|
||||||
Type: match.ExactDirectMatch,
|
Type: match.ExactDirectMatch,
|
||||||
Vulnerability: vulnerability.Vulnerability{
|
Vulnerability: vulnerability.Vulnerability{
|
||||||
|
@ -55,7 +54,7 @@ func TestAboveAllowableSeverity(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
failOnSeverity string
|
failOnSeverity string
|
||||||
matches result.Result
|
matches match.Matches
|
||||||
expectedResult bool
|
expectedResult bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue