Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: move v5-specific interfaces and implementations to the v5 package #2322

Merged
merged 6 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/grype/cli/commands/db_diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/anchore/clio"
"github.com/anchore/grype/cmd/grype/cli/options"
"github.com/anchore/grype/grype/db/legacy/distribution"
"github.com/anchore/grype/grype/differ"
"github.com/anchore/grype/grype/db/v5/differ"
"github.com/anchore/grype/internal/bus"
"github.com/anchore/grype/internal/log"
)
Expand Down
20 changes: 10 additions & 10 deletions cmd/grype/cli/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ import (
"github.com/anchore/grype/cmd/grype/cli/options"
"github.com/anchore/grype/grype"
"github.com/anchore/grype/grype/db/legacy/distribution"
v5 "github.com/anchore/grype/grype/db/v5"
"github.com/anchore/grype/grype/db/v5/matcher"
"github.com/anchore/grype/grype/db/v5/matcher/dotnet"
"github.com/anchore/grype/grype/db/v5/matcher/golang"
"github.com/anchore/grype/grype/db/v5/matcher/java"
"github.com/anchore/grype/grype/db/v5/matcher/javascript"
"github.com/anchore/grype/grype/db/v5/matcher/python"
"github.com/anchore/grype/grype/db/v5/matcher/ruby"
"github.com/anchore/grype/grype/db/v5/matcher/stock"
"github.com/anchore/grype/grype/event"
"github.com/anchore/grype/grype/event/parsers"
"github.com/anchore/grype/grype/grypeerr"
"github.com/anchore/grype/grype/match"
"github.com/anchore/grype/grype/matcher"
"github.com/anchore/grype/grype/matcher/dotnet"
"github.com/anchore/grype/grype/matcher/golang"
"github.com/anchore/grype/grype/matcher/java"
"github.com/anchore/grype/grype/matcher/javascript"
"github.com/anchore/grype/grype/matcher/python"
"github.com/anchore/grype/grype/matcher/ruby"
"github.com/anchore/grype/grype/matcher/stock"
"github.com/anchore/grype/grype/pkg"
"github.com/anchore/grype/grype/presenter/models"
"github.com/anchore/grype/grype/store"
"github.com/anchore/grype/grype/vex"
"github.com/anchore/grype/grype/vulnerability"
"github.com/anchore/grype/internal"
Expand Down Expand Up @@ -118,7 +118,7 @@ func runGrype(app clio.Application, opts *options.Grype, userInput string) (errs
return err
}

var str *store.Store
var str *v5.ProviderStore
var status *distribution.Status
var packages []pkg.Package
var s *sbom.SBOM
Expand Down
2 changes: 1 addition & 1 deletion cmd/grype/cli/options/datasources.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package options

import (
"github.com/anchore/clio"
"github.com/anchore/grype/grype/matcher/java"
"github.com/anchore/grype/grype/db/v5/matcher/java"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion grype/db/v5/advisory.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package v5

// Advisory represents published statements regarding a vulnerability (and potentially about it's resolution).
// Advisory represents published statements regarding a vulnerability (and potentially about its resolution).
type Advisory struct {
ID string `json:"id"`
Link string `json:"link"`
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import (
"errors"
"fmt"

v5 "github.com/anchore/grype/grype/db/v5"
"github.com/anchore/grype/grype/db/v5/search"
"github.com/anchore/grype/grype/distro"
"github.com/anchore/grype/grype/match"
"github.com/anchore/grype/grype/pkg"
"github.com/anchore/grype/grype/search"
"github.com/anchore/grype/grype/version"
"github.com/anchore/grype/grype/vulnerability"
"github.com/anchore/grype/internal/log"
Expand All @@ -25,7 +26,7 @@ func (m *Matcher) Type() match.MatcherType {
return match.ApkMatcher
}

func (m *Matcher) Match(store vulnerability.Provider, d *distro.Distro, p pkg.Package) ([]match.Match, error) {
func (m *Matcher) Match(store v5.VulnerabilityProvider, d *distro.Distro, p pkg.Package) ([]match.Match, error) {
var matches = make([]match.Match, 0)

// direct matches with package itself
Expand All @@ -46,7 +47,7 @@ func (m *Matcher) Match(store vulnerability.Provider, d *distro.Distro, p pkg.Pa
}

//nolint:funlen
func (m *Matcher) cpeMatchesWithoutSecDBFixes(store vulnerability.Provider, d *distro.Distro, p pkg.Package) ([]match.Match, error) {
func (m *Matcher) cpeMatchesWithoutSecDBFixes(store v5.VulnerabilityProvider, d *distro.Distro, p pkg.Package) ([]match.Match, error) {
// find CPE-indexed vulnerability matches specific to the given package name and version
cpeMatches, err := search.ByPackageCPE(store, d, p, m.Type())
if err != nil {
Expand Down Expand Up @@ -157,7 +158,7 @@ func vulnerabilitiesByID(vulns []vulnerability.Vulnerability) map[string][]vulne
return results
}

func (m *Matcher) findMatchesForPackage(store vulnerability.Provider, d *distro.Distro, p pkg.Package) ([]match.Match, error) {
func (m *Matcher) findMatchesForPackage(store v5.VulnerabilityProvider, d *distro.Distro, p pkg.Package) ([]match.Match, error) {
// find SecDB matches for the given package name and version
secDBMatches, err := search.ByPackageDistro(store, d, p, m.Type())
if err != nil {
Expand All @@ -181,7 +182,7 @@ func (m *Matcher) findMatchesForPackage(store vulnerability.Provider, d *distro.
return matches, nil
}

func (m *Matcher) findMatchesForOriginPackage(store vulnerability.Provider, d *distro.Distro, p pkg.Package) ([]match.Match, error) {
func (m *Matcher) findMatchesForOriginPackage(store v5.VulnerabilityProvider, d *distro.Distro, p pkg.Package) ([]match.Match, error) {
var matches []match.Match

for _, indirectPackage := range pkg.UpstreamPackages(p) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import (
"github.com/stretchr/testify/require"

v5 "github.com/anchore/grype/grype/db/v5"
"github.com/anchore/grype/grype/db/v5/search"
"github.com/anchore/grype/grype/distro"
"github.com/anchore/grype/grype/match"
"github.com/anchore/grype/grype/pkg"
"github.com/anchore/grype/grype/search"
"github.com/anchore/grype/grype/vulnerability"
"github.com/anchore/syft/syft/cpe"
syftPkg "github.com/anchore/syft/syft/pkg"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package dotnet

import (
v5 "github.com/anchore/grype/grype/db/v5"
"github.com/anchore/grype/grype/db/v5/search"
"github.com/anchore/grype/grype/distro"
"github.com/anchore/grype/grype/match"
"github.com/anchore/grype/grype/pkg"
"github.com/anchore/grype/grype/search"
"github.com/anchore/grype/grype/vulnerability"
syftPkg "github.com/anchore/syft/syft/pkg"
)

Expand All @@ -31,7 +31,7 @@ func (m *Matcher) Type() match.MatcherType {
return match.DotnetMatcher
}

func (m *Matcher) Match(store vulnerability.Provider, d *distro.Distro, p pkg.Package) ([]match.Match, error) {
func (m *Matcher) Match(store v5.VulnerabilityProvider, d *distro.Distro, p pkg.Package) ([]match.Match, error) {
criteria := search.CommonCriteria
if m.cfg.UseCPEs {
criteria = append(criteria, search.ByCPE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package dpkg
import (
"fmt"

v5 "github.com/anchore/grype/grype/db/v5"
"github.com/anchore/grype/grype/db/v5/search"
"github.com/anchore/grype/grype/distro"
"github.com/anchore/grype/grype/match"
"github.com/anchore/grype/grype/pkg"
"github.com/anchore/grype/grype/search"
"github.com/anchore/grype/grype/vulnerability"
syftPkg "github.com/anchore/syft/syft/pkg"
)

Expand All @@ -22,7 +22,7 @@ func (m *Matcher) Type() match.MatcherType {
return match.DpkgMatcher
}

func (m *Matcher) Match(store vulnerability.Provider, d *distro.Distro, p pkg.Package) ([]match.Match, error) {
func (m *Matcher) Match(store v5.VulnerabilityProvider, d *distro.Distro, p pkg.Package) ([]match.Match, error) {
matches := make([]match.Match, 0)

sourceMatches, err := m.matchUpstreamPackages(store, d, p)
Expand All @@ -40,7 +40,7 @@ func (m *Matcher) Match(store vulnerability.Provider, d *distro.Distro, p pkg.Pa
return matches, nil
}

func (m *Matcher) matchUpstreamPackages(store vulnerability.ProviderByDistro, d *distro.Distro, p pkg.Package) ([]match.Match, error) {
func (m *Matcher) matchUpstreamPackages(store v5.ProviderByDistro, d *distro.Distro, p pkg.Package) ([]match.Match, error) {
var matches []match.Match

for _, indirectPackage := range pkg.UpstreamPackages(p) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,24 @@ func (pr *mockProvider) stub() {
"neutron": {
{
Constraint: version.MustGetConstraint("< 2014.1.3-6", version.DebFormat),
ID: "CVE-2014-fake-1",
Reference: vulnerability.Reference{ID: "CVE-2014-fake-1"},
},
},
// indirect...
"neutron-devel": {
// expected...
{
Constraint: version.MustGetConstraint("< 2014.1.4-5", version.DebFormat),
ID: "CVE-2014-fake-2",
Reference: vulnerability.Reference{ID: "CVE-2014-fake-2"},
},
{
Constraint: version.MustGetConstraint("< 2015.0.0-1", version.DebFormat),
ID: "CVE-2013-fake-3",
Reference: vulnerability.Reference{ID: "CVE-2013-fake-3"},
},
// unexpected...
{
Constraint: version.MustGetConstraint("< 2014.0.4-1", version.DebFormat),
ID: "CVE-2013-fake-BAD",
Reference: vulnerability.Reference{ID: "CVE-2013-fake-BAD"},
},
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package golang
import (
"strings"

v5 "github.com/anchore/grype/grype/db/v5"
"github.com/anchore/grype/grype/db/v5/search"
"github.com/anchore/grype/grype/distro"
"github.com/anchore/grype/grype/match"
"github.com/anchore/grype/grype/pkg"
"github.com/anchore/grype/grype/search"
"github.com/anchore/grype/grype/vulnerability"
syftPkg "github.com/anchore/syft/syft/pkg"
)

Expand Down Expand Up @@ -35,7 +35,7 @@ func (m *Matcher) Type() match.MatcherType {
return match.GoModuleMatcher
}

func (m *Matcher) Match(store vulnerability.Provider, d *distro.Distro, p pkg.Package) ([]match.Match, error) {
func (m *Matcher) Match(store v5.VulnerabilityProvider, d *distro.Distro, p pkg.Package) ([]match.Match, error) {
matches := make([]match.Match, 0)

mainModule := ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func (mp *mockProvider) populateData() {
"istio.io/istio": {
{
Constraint: version.MustGetConstraint("< 5.0.7", version.UnknownFormat),
ID: "CVE-2013-fake-BAD",
Reference: vulnerability.Reference{ID: "CVE-2013-fake-BAD"},
},
},
}
Expand All @@ -230,7 +230,7 @@ func (mp *mockProvider) populateData() {
"cpe:2.3:a:golang:go:1.18.3:-:*:*:*:*:*:*": {
{
Constraint: version.MustGetConstraint("< 1.18.6 || = 1.19.0", version.UnknownFormat),
ID: "CVE-2022-27664",
Reference: vulnerability.Reference{ID: "CVE-2022-27664"},
},
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import (
"fmt"
"net/http"

v5 "github.com/anchore/grype/grype/db/v5"
"github.com/anchore/grype/grype/db/v5/search"
"github.com/anchore/grype/grype/distro"
"github.com/anchore/grype/grype/match"
"github.com/anchore/grype/grype/pkg"
"github.com/anchore/grype/grype/search"
"github.com/anchore/grype/grype/vulnerability"
"github.com/anchore/grype/internal/log"
syftPkg "github.com/anchore/syft/syft/pkg"
)
Expand Down Expand Up @@ -50,7 +50,7 @@ func (m *Matcher) Type() match.MatcherType {
return match.JavaMatcher
}

func (m *Matcher) Match(store vulnerability.Provider, d *distro.Distro, p pkg.Package) ([]match.Match, error) {
func (m *Matcher) Match(store v5.VulnerabilityProvider, d *distro.Distro, p pkg.Package) ([]match.Match, error) {
var matches []match.Match
if m.cfg.SearchMavenUpstream {
upstreamMatches, err := m.matchUpstreamMavenPackages(store, d, p)
Expand All @@ -73,7 +73,7 @@ func (m *Matcher) Match(store vulnerability.Provider, d *distro.Distro, p pkg.Pa
return matches, nil
}

func (m *Matcher) matchUpstreamMavenPackages(store vulnerability.Provider, d *distro.Distro, p pkg.Package) ([]match.Match, error) {
func (m *Matcher) matchUpstreamMavenPackages(store v5.VulnerabilityProvider, d *distro.Distro, p pkg.Package) ([]match.Match, error) {
var matches []match.Match

if metadata, ok := p.Metadata.(pkg.JavaMetadata); ok {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ func (mp *mockProvider) populateData() {
"org.springframework.spring-webmvc": {
{
Constraint: version.MustGetConstraint(">=5.0.0,<5.1.7", version.UnknownFormat),
ID: "CVE-2014-fake-2",
Reference: vulnerability.Reference{ID: "CVE-2014-fake-2"},
},
{
Constraint: version.MustGetConstraint(">=5.0.1,<5.1.7", version.UnknownFormat),
ID: "CVE-2013-fake-3",
Reference: vulnerability.Reference{ID: "CVE-2013-fake-3"},
},
// unexpected...
{
Constraint: version.MustGetConstraint(">=5.0.0,<5.0.7", version.UnknownFormat),
ID: "CVE-2013-fake-BAD",
Reference: vulnerability.Reference{ID: "CVE-2013-fake-BAD"},
},
},
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package javascript

import (
v5 "github.com/anchore/grype/grype/db/v5"
"github.com/anchore/grype/grype/db/v5/search"
"github.com/anchore/grype/grype/distro"
"github.com/anchore/grype/grype/match"
"github.com/anchore/grype/grype/pkg"
"github.com/anchore/grype/grype/search"
"github.com/anchore/grype/grype/vulnerability"
syftPkg "github.com/anchore/syft/syft/pkg"
)

Expand All @@ -31,7 +31,7 @@ func (m *Matcher) Type() match.MatcherType {
return match.JavascriptMatcher
}

func (m *Matcher) Match(store vulnerability.Provider, d *distro.Distro, p pkg.Package) ([]match.Match, error) {
func (m *Matcher) Match(store v5.VulnerabilityProvider, d *distro.Distro, p pkg.Package) ([]match.Match, error) {
criteria := search.CommonCriteria
if m.cfg.UseCPEs {
criteria = append(criteria, search.ByCPE)
Expand Down
4 changes: 2 additions & 2 deletions grype/matcher/matcher.go → grype/db/v5/matcher/matcher.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package matcher

import (
v5 "github.com/anchore/grype/grype/db/v5"
"github.com/anchore/grype/grype/distro"
"github.com/anchore/grype/grype/match"
"github.com/anchore/grype/grype/pkg"
"github.com/anchore/grype/grype/vulnerability"
syftPkg "github.com/anchore/syft/syft/pkg"
)

type Matcher interface {
PackageTypes() []syftPkg.Type
Type() match.MatcherType
Match(vulnerability.Provider, *distro.Distro, pkg.Package) ([]match.Match, error)
Match(v5.VulnerabilityProvider, *distro.Distro, pkg.Package) ([]match.Match, error)
}
26 changes: 13 additions & 13 deletions grype/matcher/matchers.go → grype/db/v5/matcher/matchers.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package matcher

import (
"github.com/anchore/grype/grype/matcher/apk"
"github.com/anchore/grype/grype/matcher/dotnet"
"github.com/anchore/grype/grype/matcher/dpkg"
"github.com/anchore/grype/grype/matcher/golang"
"github.com/anchore/grype/grype/matcher/java"
"github.com/anchore/grype/grype/matcher/javascript"
"github.com/anchore/grype/grype/matcher/msrc"
"github.com/anchore/grype/grype/matcher/portage"
"github.com/anchore/grype/grype/matcher/python"
"github.com/anchore/grype/grype/matcher/rpm"
"github.com/anchore/grype/grype/matcher/ruby"
"github.com/anchore/grype/grype/matcher/rust"
"github.com/anchore/grype/grype/matcher/stock"
"github.com/anchore/grype/grype/db/v5/matcher/apk"
"github.com/anchore/grype/grype/db/v5/matcher/dotnet"
"github.com/anchore/grype/grype/db/v5/matcher/dpkg"
"github.com/anchore/grype/grype/db/v5/matcher/golang"
"github.com/anchore/grype/grype/db/v5/matcher/java"
"github.com/anchore/grype/grype/db/v5/matcher/javascript"
"github.com/anchore/grype/grype/db/v5/matcher/msrc"
"github.com/anchore/grype/grype/db/v5/matcher/portage"
"github.com/anchore/grype/grype/db/v5/matcher/python"
"github.com/anchore/grype/grype/db/v5/matcher/rpm"
"github.com/anchore/grype/grype/db/v5/matcher/ruby"
"github.com/anchore/grype/grype/db/v5/matcher/rust"
"github.com/anchore/grype/grype/db/v5/matcher/stock"
)

// Config contains values used by individual matcher structs for advanced configuration
Expand Down
Loading
Loading