Skip to content

Commit

Permalink
add and fix tests from rebase
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
  • Loading branch information
wagoodman committed Jun 11, 2024
1 parent cf78dc9 commit 27689fe
Show file tree
Hide file tree
Showing 9 changed files with 430 additions and 99 deletions.
9 changes: 5 additions & 4 deletions cmd/grype/cli/commands/root.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package commands

import (
"context"
"errors"
"fmt"
"strings"
Expand Down Expand Up @@ -73,12 +74,12 @@ You can also pipe in Syft JSON directly:
Args: validateRootArgs,
SilenceUsage: true,
SilenceErrors: true,
RunE: func(_ *cobra.Command, args []string) error {
RunE: func(cmd *cobra.Command, args []string) error {
userInput := ""
if len(args) > 0 {
userInput = args[0]
}
return runGrype(app, opts, userInput)
return runGrype(cmd.Context(), app, opts, userInput)
},
ValidArgsFunction: dockerImageValidArgsFunction,
}, opts)
Expand Down Expand Up @@ -106,7 +107,7 @@ var ignoreLinuxKernelHeaders = []match.IgnoreRule{
}

//nolint:funlen
func runGrype(app clio.Application, opts *options.Grype, userInput string) (errs error) {
func runGrype(ctx context.Context, app clio.Application, opts *options.Grype, userInput string) (errs error) {
writer, err := format.MakeScanResultWriter(opts.Outputs, opts.File, format.PresentationConfig{
TemplateFilePath: opts.OutputTemplateFile,
ShowSuppressed: opts.ShowSuppressed,
Expand Down Expand Up @@ -194,7 +195,7 @@ func runGrype(app clio.Application, opts *options.Grype, userInput string) (errs
}),
}

remainingMatches, ignoredMatches, err := vulnMatcher.FindMatches(packages, pkgContext)
remainingMatches, ignoredMatches, err := vulnMatcher.FindMatches(ctx, packages, pkgContext)
if err != nil {
if !errors.Is(err, grypeerr.ErrAboveSeverityThreshold) {
return err
Expand Down
8 changes: 5 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ require (
github.com/glebarez/sqlite v1.11.0
github.com/go-test/deep v1.1.0
github.com/google/go-cmp v0.6.0
github.com/google/go-containerregistry v0.19.1
github.com/google/go-containerregistry v0.19.1 // indirect
github.com/google/uuid v1.6.0
github.com/gookit/color v1.5.4
github.com/hako/durafmt v0.0.0-20210608085754-5c1018a4e16b
Expand Down Expand Up @@ -61,7 +61,10 @@ require (
gorm.io/gorm v1.25.10
)

require github.com/openvex/discovery v0.1.0
require (
github.com/openvex/discovery v0.1.0
golang.org/x/sync v0.7.0
)

require (
cloud.google.com/go v0.110.10 // indirect
Expand Down Expand Up @@ -285,7 +288,6 @@ require (
golang.org/x/mod v0.17.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/oauth2 v0.19.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/term v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
Expand Down
4 changes: 3 additions & 1 deletion grype/deprecated.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package grype

import (
"context"

"github.com/anchore/grype/grype/match"
"github.com/anchore/grype/grype/matcher"
"github.com/anchore/grype/grype/pkg"
Expand Down Expand Up @@ -40,7 +42,7 @@ func FindVulnerabilitiesForPackage(store store.Store, d *linux.Release, matchers
NormalizeByCVE: false,
}

actualResults, _, err := runner.FindMatches(packages, pkg.Context{
actualResults, _, err := runner.FindMatches(context.Background(), packages, pkg.Context{
Distro: d,
})
if err != nil || actualResults == nil {
Expand Down
Loading

0 comments on commit 27689fe

Please sign in to comment.