Skip to content

Commit

Permalink
fix replacement of results with matches (#158)
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Goodman <[email protected]>
  • Loading branch information
wagoodman authored Sep 22, 2020
1 parent f0f8f4b commit c73a337
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
8 changes: 4 additions & 4 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
"github.com/anchore/grype/grype"
"github.com/anchore/grype/grype/event"
"github.com/anchore/grype/grype/grypeerr"
"github.com/anchore/grype/grype/match"
"github.com/anchore/grype/grype/presenter"
"github.com/anchore/grype/grype/result"
"github.com/anchore/grype/grype/vulnerability"
"github.com/anchore/grype/internal"
"github.com/anchore/grype/internal/bus"
Expand Down Expand Up @@ -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).
// 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.
if hitSeverityThreshold(failOnSeverity, results, metadataProvider) {
if hitSeverityThreshold(failOnSeverity, matches, metadataProvider) {
errs <- grypeerr.ErrAboveSeverityThreshold
}

Expand All @@ -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)
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 {
var maxDiscoveredSeverity vulnerability.Severity
for m := range results.Enumerate() {
for m := range matches.Enumerate() {
metadata, err := metadataProvider.GetMetadata(m.Vulnerability.ID, m.Vulnerability.RecordSource)
if err != nil {
continue
Expand Down
5 changes: 2 additions & 3 deletions cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cmd

import (
"github.com/anchore/grype/grype/match"
"github.com/anchore/grype/grype/result"
"github.com/anchore/grype/grype/vulnerability"
"github.com/anchore/syft/syft/pkg"
"testing"
Expand Down Expand Up @@ -42,7 +41,7 @@ func TestAboveAllowableSeverity(t *testing.T) {
Type: pkg.RpmPkg,
}

matches := result.NewResult()
matches := match.NewMatches()
matches.Add(thePkg, match.Match{
Type: match.ExactDirectMatch,
Vulnerability: vulnerability.Vulnerability{
Expand All @@ -55,7 +54,7 @@ func TestAboveAllowableSeverity(t *testing.T) {
tests := []struct {
name string
failOnSeverity string
matches result.Result
matches match.Matches
expectedResult bool
}{
{
Expand Down

0 comments on commit c73a337

Please sign in to comment.