rename os -> distro

This commit is contained in:
Alex Goodman 2020-06-01 10:43:58 -04:00
parent aacc624033
commit 490ba9cd4b
No known key found for this signature in database
GPG key ID: 86E2870463D5E890
8 changed files with 26 additions and 26 deletions

View file

@ -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,
}

View file

@ -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))

View file

@ -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)
}

View file

@ -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...)
}

View file

@ -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)
}

View file

@ -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)
}

View file

@ -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:

View file

@ -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())
}