[wip] api refactor

Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
This commit is contained in:
Alex Goodman
2022-03-11 21:26:33 -05:00
parent 003d28ad48
commit 3323ce2b6b
84 changed files with 1047 additions and 769 deletions
+3 -3
View File
@@ -1,11 +1,11 @@
package integration
import (
"github.com/anchore/syft/syft/pkg/cataloger/packages"
"github.com/stretchr/testify/require"
"testing"
"github.com/anchore/syft/syft/linux"
"github.com/anchore/syft/syft/pkg/cataloger"
"github.com/google/go-cmp/cmp"
"github.com/anchore/stereoscope/pkg/imagetest"
@@ -21,7 +21,7 @@ func BenchmarkImagePackageCatalogers(b *testing.B) {
tarPath := imagetest.GetFixtureImageTarPath(b, fixtureImageName)
var pc *pkg.Catalog
for _, c := range cataloger.ImageCatalogers(cataloger.DefaultConfig()) {
for _, c := range packages.InstalledCatalogers(packages.DefaultSearchConfig()) {
// in case of future alteration where state is persisted, assume no dependency is safe to reuse
userInput := "docker-archive:" + tarPath
sourceInput, err := source.ParseInput(userInput, "", false)
@@ -41,7 +41,7 @@ func BenchmarkImagePackageCatalogers(b *testing.B) {
b.Run(c.Name(), func(b *testing.B) {
for i := 0; i < b.N; i++ {
pc, _, err = cataloger.Catalog(resolver, theDistro, c)
pc, _, err = packages.Catalog(resolver, theDistro, c)
if err != nil {
b.Fatalf("failure during benchmark: %+v", err)
}
+13 -12
View File
@@ -1,15 +1,14 @@
package integration
import (
"github.com/anchore/syft/syft/linux"
"github.com/anchore/syft/syft/pkg/cataloger/packages"
"github.com/stretchr/testify/require"
"testing"
"github.com/anchore/syft/syft/pkg/cataloger"
"github.com/anchore/syft/syft/sbom"
"github.com/anchore/stereoscope/pkg/imagetest"
"github.com/anchore/syft/syft"
"github.com/anchore/syft/syft/source"
)
@@ -23,10 +22,11 @@ func catalogFixtureImage(t *testing.T, fixtureImageName string) (sbom.SBOM, *sou
t.Cleanup(cleanupSource)
require.NoError(t, err)
// TODO: this would be better with functional options (after/during API refactor)
c := cataloger.DefaultConfig()
c.Search.Scope = source.SquashedScope
pkgCatalog, relationships, actualDistro, err := syft.CatalogPackages(theSource, c)
// TODO: this would be better with functional options (after/during API refactor)... this should be replaced
resolver, err := theSource.FileResolver(source.SquashedScope)
require.NoError(t, err)
release := linux.IdentifyRelease(resolver)
pkgCatalog, relationships, err := packages.Catalog(resolver, release, packages.CatalogersBySourceScheme(theSource.Metadata.Scheme, packages.DefaultSearchConfig())...)
if err != nil {
t.Fatalf("failed to catalog image: %+v", err)
}
@@ -34,7 +34,7 @@ func catalogFixtureImage(t *testing.T, fixtureImageName string) (sbom.SBOM, *sou
return sbom.SBOM{
Artifacts: sbom.Artifacts{
PackageCatalog: pkgCatalog,
LinuxDistribution: actualDistro,
LinuxDistribution: release,
},
Relationships: relationships,
Source: theSource.Metadata,
@@ -59,9 +59,10 @@ func catalogDirectory(t *testing.T, dir string) (sbom.SBOM, *source.Source) {
require.NoError(t, err)
// TODO: this would be better with functional options (after/during API refactor)
c := cataloger.DefaultConfig()
c.Search.Scope = source.AllLayersScope
pkgCatalog, relationships, actualDistro, err := syft.CatalogPackages(theSource, c)
resolver, err := theSource.FileResolver(source.AllLayersScope)
require.NoError(t, err)
release := linux.IdentifyRelease(resolver)
pkgCatalog, relationships, err := packages.Catalog(resolver, release, packages.CatalogersBySourceScheme(theSource.Metadata.Scheme, packages.DefaultSearchConfig())...)
if err != nil {
t.Fatalf("failed to catalog image: %+v", err)
}
@@ -69,7 +70,7 @@ func catalogDirectory(t *testing.T, dir string) (sbom.SBOM, *source.Source) {
return sbom.SBOM{
Artifacts: sbom.Artifacts{
PackageCatalog: pkgCatalog,
LinuxDistribution: actualDistro,
LinuxDistribution: release,
},
Relationships: relationships,
Source: theSource.Metadata,