8000 Migrate legacy distribution concerns (v1-5 schemas) by wagoodman · Pull Request #2144 · anchore/grype · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Migrate legacy distribution concerns (v1-5 schemas) #2144

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

Merged
merged 1 commit into from
Sep 30, 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
8000 Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/grype/cli/commands/db_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/anchore/clio"
"github.com/anchore/grype/cmd/grype/cli/options"
"github.com/anchore/grype/grype/db"
"github.com/anchore/grype/grype/db/legacy/distribution"
)

const (
Expand All @@ -30,7 +30,7 @@ func DBCheck(app clio.Application) *cobra.Command {
}

func runDBCheck(opts options.Database) error {
dbCurator, err := db.NewCurator(opts.ToCuratorConfig())
dbCurator, err := distribution.NewCurator(opts.ToCurato 10000 rConfig())
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/grype/cli/commands/db_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/anchore/clio"
"github.com/anchore/grype/cmd/grype/cli/options"
"github.com/anchore/grype/grype/db"
"github.com/anchore/grype/grype/db/legacy/distribution"
)

func DBDelete(app clio.Application) *cobra.Command {
Expand All @@ -25,7 +25,7 @@ func DBDelete(app clio.Application) *cobra.Command {
}

func runDBDelete(opts options.Database) error {
dbCurator, err := db.NewCurator(opts.ToCuratorConfig())
dbCurator, err := distribution.NewCurator(opts.ToCuratorConfig())
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/grype/cli/commands/db_diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/anchore/clio"
"github.com/anchore/grype/cmd/grype/cli/options"
"github.com/anchore/grype/grype/db"
"github.com/anchore/grype/grype/db/legacy/distribution"
"github.com/anchore/grype/grype/differ"
"github.com/anchore/grype/internal/bus"
"github.com/anchore/grype/internal/log"
Expand Down Expand Up @@ -104,7 +104,7 @@ func runDBDiff(opts *dbDiffOptions, base string, target string) (errs error) {
}

func getDefaultURLs(opts options.Database) (baseURL string, targetURL string, err error) {
dbCurator, err := db.NewCurator(opts.ToCuratorConfig())
dbCurator, err := distribution.NewCurator(opts.ToCuratorConfig())
if err != nil {
return "", "", err
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/grype/cli/commands/db_import.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/anchore/clio"
"github.com/anchore/grype/cmd/grype/cli/options"
"github.com/anchore/grype/grype/db"
"github.com/anchore/grype/grype/db/legacy/distribution"
"github.com/anchore/grype/internal"
)

Expand All @@ -27,7 +27,7 @@ func DBImport(app clio.Application) *cobra.Command {
}

func runDBImport(opts options.Database, dbArchivePath string) error {
dbCurator, err := db.NewCurator(opts.ToCuratorConfig())
dbCurator, err := distribution.NewCurator(opts.ToCuratorConfig())
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/grype/cli/commands/db_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/spf13/cobra"

"github.com/anchore/clio"
"github.com/anchore/grype/grype/db"
"github.com/anchore/grype/grype/db/legacy/distribution"
)

type dbListOptions struct {
Expand Down Expand Up @@ -40,7 +40,7 @@ func DBList(app clio.Application) *cobra.Command {
}

func runDBList(opts *dbListOptions) error {
dbCurator, err := db.NewCurator(opts.DB.ToCuratorConfig())
dbCurator, err := distribution.NewCurator(opts.DB.ToCuratorConfig())
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/grype/cli/commands/db_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/anchore/clio"
"github.com/anchore/grype/cmd/grype/cli/options"
"github.com/anchore/grype/grype/db"
"github.com/anchore/grype/grype/db/legacy/distribution"
)

func DBStatus(app clio.Application) *cobra.Command {
Expand All @@ -25,7 +25,7 @@ func DBStatus(app clio.Application) *cobra.Command {
}

func runDBStatus(opts options.Database) error {
dbCurator, err := db.NewCurator(opts.ToCuratorConfig())
dbCurator, err := distribution.NewCurator(opts.ToCuratorConfig())
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/grype/cli/commands/db_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/anchore/clio"
"github.com/anchore/grype/cmd/grype/cli/options"
"github.com/anchore/grype/grype/db"
"github.com/anchore/grype/grype/db/legacy/distribution"
"github.com/anchore/grype/internal/bus"
"github.com/anchore/grype/internal/log"
)
Expand All @@ -26,7 +26,7 @@ func DBUpdate(app clio.Application) *cobra.Command {
}

func runDBUpdate(opts options.Database) error {
dbCurator, err := db.NewCurator(opts.ToCuratorConfig())
dbCurator, err := distribution.NewCurator(opts.ToCuratorConfig())
if err != nil {
return err
}
Expand Down
5 changes: 3 additions & 2 deletions cmd/grype/cli/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/anchore/grype/cmd/grype/cli/options"
"github.com/anchore/grype/grype"
"github.com/anchore/grype/grype/db"
"github.com/anchore/grype/grype/db/legacy/distribution"
grypeDb "github.com/anchore/grype/grype/db/v5"
"github.com/anchore/grype/grype/event"
"github.com/anchore/grype/grype/event/parsers"
Expand Down Expand Up @@ -117,7 +118,7 @@ func runGrype(app clio.Application, opts *options.Grype, userInput string) (errs
}

var str *store.Store
var status *db.Status
var status *distribution.Status
var dbCloser *db.Closer
var packages []pkg.Package
var s *sbom.SBOM
Expand Down Expand Up @@ -320,7 +321,7 @@ func getProviderConfig(opts *options.Grype) pkg.ProviderConfig {
}
}

func validateDBLoad(loadErr error, status *db.Status) error {
func validateDBLoad(loadErr error, status *distribution.Status) error {
if loadErr != nil {
return fmt.Errorf("failed to load vulnerability db: %w", loadErr)
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/grype/cli/options/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/adrg/xdg"

"github.com/anchore/clio"
"github.com/anchore/grype/grype/db"
"github.com/anchore/grype/grype/db/legacy/distribution"
"github.com/anchore/grype/internal"
)

Expand Down Expand Up @@ -50,8 +50,8 @@ func DefaultDatabase(id clio.Identification) Database {
}
}

func (cfg Database) ToCuratorConfig() db.Config {
return db.Config{
func (cfg Database) ToCuratorConfig() distribution.Config {
return distribution.Config{
ID: cfg.ID,
DBRootDir: cfg.Dir,
ListingURL: cfg.UpdateURL,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package db
package distribution

import (
"crypto/tls"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package db
package distribution

import (
"archive/tar"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package db
package distribution

import (
"encoding/json"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package db
package distribution

import (
"crypto/sha256"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package db
package distribution

import (
"net/url"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package db
package distribution

import (
"encoding/json"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package db
package distribution

import (
"testing"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package db
package distribution

import "time"

Expand Down
1 change: 0 additions & 1 deletion grype/db/test-fixtures/archives/metadata.json

This file was deleted.

20 changes: 10 additions & 10 deletions grype/differ/differ.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ import (
"github.com/wagoodman/go-partybus"
"github.com/wagoodman/go-progress"

"github.com/anchore/grype/grype/db"
"github.com/anchore/grype/grype/db/legacy/distribution"
v5 "github.com/anchore/grype/grype/db/v5"
"github.com/anchore/grype/grype/event"
"github.com/anchore/grype/internal/bus"
)

type Differ struct {
baseCurator db.Curator
targetCurator db.Curator
baseCurator distribution.Curator
targetCurator distribution.Curator
}

func NewDiffer(config db.Config) (*Differ, error) {
baseCurator, err := db.NewCurator(db.Config{
func NewDiffer(config distribution.Config) (*Differ, error) {
baseCurator, err := distribution.NewCurator(distribution.Config{
DBRootDir: path.Join(config.DBRootDir, "diff", "base"),
ListingURL: config.ListingURL,
CACert: config.CACert,
Expand All @@ -33,7 +33,7 @@ func NewDiffer(config db.Config) (*Differ, error) {
return nil, err
}

targetCurator, err := db.NewCurator(db.Config{
targetCurator, err := distribution.NewCurator(distribution.Config{
DBRootDir: path.Join(config.DBRootDir, "diff", "target"),
ListingURL: config.ListingURL,
CACert: config.CACert,
Expand All @@ -57,11 +57,11 @@ func (d *Differ) SetTargetDB(target string) error {
return d.setOrDownload(&d.targetCurator, target)
}

func (d *Differ) setOrDownload(curator *db.Curator, filenameOrURL string) error {
func (d *Differ) setOrDownload(curator *distribution.Curator, filenameOrURL string) error {
u, err := url.ParseRequestURI(filenameOrURL)

if err != nil || u.Scheme == "" {
*curator, err = db.NewCurator(db.Config{
*curator, err = distribution.NewCurator(distribution.Config{
DBRootDir: filenameOrURL,
})
if err != nil {
Expand All @@ -76,7 +76,7 @@ func (d *Differ) setOrDownload(curator *db.Curator, filenameOrURL string) error
available := listings.Available
dbs := available[v5.SchemaVersion]

var listing *db.ListingEntry
var listing *distribution.ListingEntry

for _, d := range dbs {
database := d
Expand All @@ -97,7 +97,7 @@ func (d *Differ) setOrDownload(curator *db.Curator, filenameOrURL string) error
return nil
}

func download(curator *db.Curator, listing *db.ListingEntry) error {
func download(curator *distribution.Curator, listing *distribution.ListingEntry) error {
// let consumers know of a monitorable event (download + import stages)
importProgress := progress.NewManual(1)
stage := progress.NewAtomicStage("checking available databases")
Expand Down
6 changes: 3 additions & 3 deletions grype/differ/differ_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/stretchr/testify/require"

"github.com/anchore/go-testutils"
"github.com/anchore/grype/grype/db"
"github.com/anchore/grype/grype/db/legacy/distribution"
v5 "github.com/anchore/grype/grype/db/v5"
"github.com/anchore/grype/grype/vulnerability"
)
Expand All @@ -19,7 +19,7 @@ var update = flag.Bool("update", false, "update the *.golden files for diff pres

func TestNewDiffer(t *testing.T) {
//GIVEN
config := db.Config{}
config := distribution.Config{}

//WHEN
differ, err := NewDiffer(config)
Expand All @@ -30,7 +30,7 @@ func TestNewDiffer(t *testing.T) {
}

func Test_DifferDirectory(t *testing.T) {
d, err := NewDiffer(db.Config{
d, err := NewDiffer(distribution.Config{
DBRootDir: "root-dir",
})
require.NoError(t, err)
Expand Down
5 changes: 3 additions & 2 deletions grype/load_vulnerability_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package grype

import (
"github.com/anchore/grype/grype/db"
"github.com/anchore/grype/grype/db/legacy/distribution"
"github.com/anchore/grype/grype/store"
"github.com/anchore/grype/internal/log"
)

func LoadVulnerabilityDB(cfg db.Config, update bool) (*store.Store, *db.Status, *db.Closer, error) {
dbCurator, err := db.NewCurator(cfg)
func LoadVulnerabilityDB(cfg distribution.Config, update bool) (*store.Store, *distribution.Status, *db.Closer, error) {
dbCurator, err := distribution.NewCurator(cfg)
if err != nil {
return nil, nil, nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions grype/load_vulnerability_db_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import (
"path/filepath"
"testing"

"github.com/anchore/grype/grype/db"
"github.com/anchore/grype/grype/db/legacy/distribution"
"github.com/anchore/grype/internal"
)

// this benchmark was added to measure the performance
// of LoadVulnerabilityDB, specifically in regards to hash validation.
// https://github.com/anchore/grype/issues/1502
func BenchmarkLoadVulnerabilityDB(b *testing.B) {
cfg := db.Config{
cfg := distribution.Config{
DBRootDir: filepath.Join(".tmp", "grype-db"),
ListingURL: internal.DBUpdateURL,
ValidateByHashOnGet: true,
Expand Down
4 changes: 2 additions & 2 deletions test/integration/compare_sbom_input_vs_lib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/stretchr/testify/assert"

"github.com/anchore/grype/grype"
"github.com/anchore/grype/grype/db"
"github.com/anchore/grype/grype/db/legacy/distribution"
"github.com/anchore/grype/internal"
"github.com/anchore/syft/syft/format/spdxjson"
"github.com/anchore/syft/syft/format/spdxtagvalue"
Expand All @@ -35,7 +35,7 @@ func must(e sbom.FormatEncoder, err error) sbom.FormatEncoder {

func TestCompareSBOMInputToLibResults(t *testing.T) {
// get a grype DB
store, _, closer, err := grype.LoadVulnerabilityDB(db.Config{
store, _, closer, err := grype.LoadVulnerabilityDB(distribution.Config{
DBRootDir: "test-fixtures/grype-db",
ListingURL: getListingURL(),
ValidateByHashOnGet: false,
Expand Down
Loading
0