mirror of
https://github.com/anchore/syft.git
synced 2026-10-30 22:12:28 +01:00
Refactor source API (#1846)
* refactor source API and syft json source block Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * update source detection and format test utils Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * generate list of all source metadata types Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * extract base and root normalization into helper functions Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * preserve syftjson model package name import ref Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * alias should not be a pointer Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> --------- Signed-off-by: Alex Goodman <alex.goodman@anchore.com> Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
This commit is contained in:
@@ -26,13 +26,15 @@ func BenchmarkImagePackageCatalogers(b *testing.B) {
|
||||
for _, c := range cataloger.ImageCatalogers(cataloger.DefaultConfig()) {
|
||||
// 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, "")
|
||||
detection, err := source.Detect(userInput, source.DefaultDetectConfig())
|
||||
require.NoError(b, err)
|
||||
theSource, cleanupSource, err := source.New(*sourceInput, nil, nil)
|
||||
b.Cleanup(cleanupSource)
|
||||
theSource, err := detection.NewSource(source.DefaultDetectionSourceConfig())
|
||||
if err != nil {
|
||||
b.Fatalf("unable to get source: %+v", err)
|
||||
}
|
||||
b.Cleanup(func() {
|
||||
theSource.Close()
|
||||
})
|
||||
|
||||
resolver, err := theSource.FileResolver(source.SquashedScope)
|
||||
if err != nil {
|
||||
|
||||
@@ -12,15 +12,17 @@ import (
|
||||
"github.com/anchore/syft/syft/source"
|
||||
)
|
||||
|
||||
func catalogFixtureImage(t *testing.T, fixtureImageName string, scope source.Scope, catalogerCfg []string) (sbom.SBOM, *source.Source) {
|
||||
func catalogFixtureImage(t *testing.T, fixtureImageName string, scope source.Scope, catalogerCfg []string) (sbom.SBOM, source.Source) {
|
||||
imagetest.GetFixtureImage(t, "docker-archive", fixtureImageName)
|
||||
tarPath := imagetest.GetFixtureImageTarPath(t, fixtureImageName)
|
||||
userInput := "docker-archive:" + tarPath
|
||||
sourceInput, err := source.ParseInput(userInput, "")
|
||||
detection, err := source.Detect(userInput, source.DefaultDetectConfig())
|
||||
require.NoError(t, err)
|
||||
theSource, cleanupSource, err := source.New(*sourceInput, nil, nil)
|
||||
t.Cleanup(cleanupSource)
|
||||
theSource, err := detection.NewSource(source.DefaultDetectionSourceConfig())
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
theSource.Close()
|
||||
})
|
||||
|
||||
c := cataloger.DefaultConfig()
|
||||
c.Catalogers = catalogerCfg
|
||||
@@ -37,7 +39,7 @@ func catalogFixtureImage(t *testing.T, fixtureImageName string, scope source.Sco
|
||||
LinuxDistribution: actualDistro,
|
||||
},
|
||||
Relationships: relationships,
|
||||
Source: theSource.Metadata,
|
||||
Source: theSource.Describe(),
|
||||
Descriptor: sbom.Descriptor{
|
||||
Name: "syft",
|
||||
Version: "v0.42.0-bogus",
|
||||
@@ -50,13 +52,15 @@ func catalogFixtureImage(t *testing.T, fixtureImageName string, scope source.Sco
|
||||
}, theSource
|
||||
}
|
||||
|
||||
func catalogDirectory(t *testing.T, dir string) (sbom.SBOM, *source.Source) {
|
||||
func catalogDirectory(t *testing.T, dir string) (sbom.SBOM, source.Source) {
|
||||
userInput := "dir:" + dir
|
||||
sourceInput, err := source.ParseInput(userInput, "")
|
||||
detection, err := source.Detect(userInput, source.DefaultDetectConfig())
|
||||
require.NoError(t, err)
|
||||
theSource, cleanupSource, err := source.New(*sourceInput, nil, nil)
|
||||
t.Cleanup(cleanupSource)
|
||||
theSource, err := detection.NewSource(source.DefaultDetectionSourceConfig())
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
theSource.Close()
|
||||
})
|
||||
|
||||
// TODO: this would be better with functional options (after/during API refactor)
|
||||
c := cataloger.DefaultConfig()
|
||||
@@ -72,6 +76,6 @@ func catalogDirectory(t *testing.T, dir string) (sbom.SBOM, *source.Source) {
|
||||
LinuxDistribution: actualDistro,
|
||||
},
|
||||
Relationships: relationships,
|
||||
Source: theSource.Metadata,
|
||||
Source: theSource.Describe(),
|
||||
}, theSource
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user