From 490ba9cd4b79f4ed64835fa906eba99c01adef74 Mon Sep 17 00:00:00 2001 From: Alex Goodman Date: Mon, 1 Jun 2020 10:43:58 -0400 Subject: [PATCH] rename os -> distro --- cmd/root.go | 6 +++--- vulnscan/find.go | 6 +++--- vulnscan/match/match.go | 2 +- vulnscan/matcher/controller.go | 10 +++++----- vulnscan/matcher/{os => distro}/matcher.go | 10 +++++----- vulnscan/matcher/matcher.go | 4 ++-- vulnscan/version/constraint.go | 6 +++--- vulnscan/vulnerability/provider.go | 8 ++++---- 8 files changed, 26 insertions(+), 26 deletions(-) rename vulnscan/matcher/{os => distro}/matcher.go (85%) diff --git a/cmd/root.go b/cmd/root.go index a09df763..ac765b0b 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -5,7 +5,7 @@ import ( "os" "github.com/anchore/imgbom/imgbom" - imgbomOS "github.com/anchore/imgbom/imgbom/os" + "github.com/anchore/imgbom/imgbom/distro" "github.com/anchore/imgbom/imgbom/pkg" "github.com/anchore/imgbom/imgbom/scope" "github.com/anchore/stereoscope" @@ -87,8 +87,8 @@ func runDefaultCmd(cmd *cobra.Command, args []string) int { // TODO: remove me (replace with imgbom os.Identify call) - osObj := imgbomOS.OS{ - Type: imgbomOS.DebianOS, + osObj := distro.Distro{ + Type: distro.Debian, Version: ver, } diff --git a/vulnscan/find.go b/vulnscan/find.go index 0a4ea0bb..405235db 100644 --- a/vulnscan/find.go +++ b/vulnscan/find.go @@ -1,14 +1,14 @@ package vulnscan import ( - "github.com/anchore/imgbom/imgbom/os" + "github.com/anchore/imgbom/imgbom/distro" "github.com/anchore/imgbom/imgbom/pkg" "github.com/anchore/vulnscan/vulnscan/matcher" "github.com/anchore/vulnscan/vulnscan/result" "github.com/anchore/vulnscan/vulnscan/vulnerability" ) -func FindAllVulnerabilities(store vulnerability.Provider, o os.OS, catalog *pkg.Catalog) result.Result { +func FindAllVulnerabilities(store vulnerability.Provider, o distro.Distro, catalog *pkg.Catalog) result.Result { res := result.NewResult() for p := range catalog.Enumerate() { res.Merge(FindVulnerabilities(store, o, p)) @@ -16,7 +16,7 @@ func FindAllVulnerabilities(store vulnerability.Provider, o os.OS, catalog *pkg. return res } -func FindVulnerabilities(store vulnerability.Provider, o os.OS, packages ...*pkg.Package) result.Result { +func FindVulnerabilities(store vulnerability.Provider, o distro.Distro, packages ...*pkg.Package) result.Result { res := result.NewResult() for _, p := range packages { res.Merge(matcher.FindMatches(store, o, p)) diff --git a/vulnscan/match/match.go b/vulnscan/match/match.go index 00190608..93a2f1d5 100644 --- a/vulnscan/match/match.go +++ b/vulnscan/match/match.go @@ -17,5 +17,5 @@ type Match struct { } func (m Match) String() string { - return fmt.Sprintf("Match(pkg=%s vuln=%s key='%s' confidence=%f)", m.Package.String(), m.Vulnerability.String(), m.SearchKey, m.Confidence) + return fmt.Sprintf("Match(pkg=%s vuln=%s key='%s' confidence=%f)", m.Package, m.Vulnerability.String(), m.SearchKey, m.Confidence) } diff --git a/vulnscan/matcher/controller.go b/vulnscan/matcher/controller.go index f4a5a1c3..b427ce1f 100644 --- a/vulnscan/matcher/controller.go +++ b/vulnscan/matcher/controller.go @@ -1,10 +1,10 @@ package matcher import ( - imgbomOS "github.com/anchore/imgbom/imgbom/os" + "github.com/anchore/imgbom/imgbom/distro" "github.com/anchore/imgbom/imgbom/pkg" "github.com/anchore/vulnscan/internal/log" - "github.com/anchore/vulnscan/vulnscan/matcher/os" + _distro "github.com/anchore/vulnscan/vulnscan/matcher/distro" "github.com/anchore/vulnscan/vulnscan/result" "github.com/anchore/vulnscan/vulnscan/vulnerability" ) @@ -15,7 +15,7 @@ func init() { controllerInstance = controller{ matchers: make(map[pkg.Type][]Matcher), } - controllerInstance.add(&os.Matcher{}) + controllerInstance.add(&_distro.Matcher{}) } type controller struct { @@ -35,7 +35,7 @@ func (c *controller) add(matchers ...Matcher) { } } -func (c *controller) findMatches(s vulnerability.Provider, o imgbomOS.OS, packages ...*pkg.Package) result.Result { +func (c *controller) findMatches(s vulnerability.Provider, o distro.Distro, packages ...*pkg.Package) result.Result { res := result.NewResult() for _, p := range packages { for _, matchers := range c.matchers { @@ -52,6 +52,6 @@ func (c *controller) findMatches(s vulnerability.Provider, o imgbomOS.OS, packag return res } -func FindMatches(s vulnerability.Provider, o imgbomOS.OS, packages ...*pkg.Package) result.Result { +func FindMatches(s vulnerability.Provider, o distro.Distro, packages ...*pkg.Package) result.Result { return controllerInstance.findMatches(s, o, packages...) } diff --git a/vulnscan/matcher/os/matcher.go b/vulnscan/matcher/distro/matcher.go similarity index 85% rename from vulnscan/matcher/os/matcher.go rename to vulnscan/matcher/distro/matcher.go index 5e0a44f5..c50c6a63 100644 --- a/vulnscan/matcher/os/matcher.go +++ b/vulnscan/matcher/distro/matcher.go @@ -1,9 +1,9 @@ -package os +package distro import ( "fmt" - "github.com/anchore/imgbom/imgbom/os" + "github.com/anchore/imgbom/imgbom/distro" "github.com/anchore/imgbom/imgbom/pkg" "github.com/anchore/vulnscan/vulnscan/match" "github.com/anchore/vulnscan/vulnscan/version" @@ -19,18 +19,18 @@ func (m *Matcher) Types() []pkg.Type { return []pkg.Type{pkg.DebPkg} } -func (m *Matcher) Match(store vulnerability.Provider, o os.OS, p *pkg.Package) ([]match.Match, error) { +func (m *Matcher) Match(store vulnerability.Provider, o distro.Distro, p *pkg.Package) ([]match.Match, error) { // TODO: add other kinds of matches? fuzzy matches, etc... return m.exactPackageNameMatch(store, o, p) } -func (m *Matcher) exactPackageNameMatch(store vulnerability.Provider, o os.OS, p *pkg.Package) ([]match.Match, error) { +func (m *Matcher) exactPackageNameMatch(store vulnerability.Provider, o distro.Distro, p *pkg.Package) ([]match.Match, error) { matches := make([]match.Match, 0) // TODO: there should be a vulnerability object in the vulnscan-db/db/vulnerability for mondel serialization and one here in vulnerability for rich objects - allPkgVulns, err := store.GetByOs(o, p) + allPkgVulns, err := store.GetByDistro(o, p) if err != nil { return nil, fmt.Errorf("matcher failed to fetch os=%s pkg=%s: %w", o, p.Name, err) } diff --git a/vulnscan/matcher/matcher.go b/vulnscan/matcher/matcher.go index dcd3b92f..b99a5a99 100644 --- a/vulnscan/matcher/matcher.go +++ b/vulnscan/matcher/matcher.go @@ -1,7 +1,7 @@ package matcher import ( - "github.com/anchore/imgbom/imgbom/os" + "github.com/anchore/imgbom/imgbom/distro" "github.com/anchore/imgbom/imgbom/pkg" "github.com/anchore/vulnscan/vulnscan/match" "github.com/anchore/vulnscan/vulnscan/vulnerability" @@ -9,5 +9,5 @@ import ( type Matcher interface { Types() []pkg.Type - Match(vulnerability.Provider, os.OS, *pkg.Package) ([]match.Match, error) + Match(vulnerability.Provider, distro.Distro, *pkg.Package) ([]match.Match, error) } diff --git a/vulnscan/version/constraint.go b/vulnscan/version/constraint.go index 1b042925..b245cb2c 100644 --- a/vulnscan/version/constraint.go +++ b/vulnscan/version/constraint.go @@ -3,7 +3,7 @@ package version import ( "fmt" - "github.com/anchore/imgbom/imgbom/os" + "github.com/anchore/imgbom/imgbom/distro" ) type Constraint interface { @@ -22,10 +22,10 @@ func GetConstraint(constStr string, format Format) (Constraint, error) { return nil, fmt.Errorf("could not find constraint for given format: %s", format) } -func GetConstraintByOS(constStr string, o os.OS) (Constraint, error) { +func GetConstraintByDisto(constStr string, o distro.Distro) (Constraint, error) { var format Format switch o.Type { - case os.DebianOS: + case distro.Debian: format = DpkgFormat //... default: diff --git a/vulnscan/vulnerability/provider.go b/vulnscan/vulnerability/provider.go index d0366757..1c02b519 100644 --- a/vulnscan/vulnerability/provider.go +++ b/vulnscan/vulnerability/provider.go @@ -4,14 +4,14 @@ import ( "fmt" "strings" - "github.com/anchore/imgbom/imgbom/os" + "github.com/anchore/imgbom/imgbom/distro" "github.com/anchore/imgbom/imgbom/pkg" "github.com/anchore/vulnscan-db/pkg/db" "github.com/anchore/vulnscan/vulnscan/version" ) type Provider interface { - GetByOs(os.OS, *pkg.Package) ([]*Vulnerability, error) + GetByDistro(distro.Distro, *pkg.Package) ([]*Vulnerability, error) } type StoreProvider struct { @@ -26,7 +26,7 @@ func NewProviderFromStore(store db.VulnStore) *StoreProvider { } } -func (pr *StoreProvider) GetByOs(o os.OS, p *pkg.Package) ([]*Vulnerability, error) { +func (pr *StoreProvider) GetByDistro(o distro.Distro, p *pkg.Package) ([]*Vulnerability, error) { vulns := make([]*Vulnerability, 0) namespace := pr.osNamespace(o) @@ -52,6 +52,6 @@ func (pr *StoreProvider) GetByOs(o os.OS, p *pkg.Package) ([]*Vulnerability, err return vulns, nil } -func (pr *StoreProvider) osNamespace(o os.OS) string { +func (pr *StoreProvider) osNamespace(o distro.Distro) string { return fmt.Sprintf("%s:%d", strings.ToLower(o.Type.String()), o.MajorVersion()) }