mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 08:23:15 +01:00
rename binary cataloger to be more unique (#2633)
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
This commit is contained in:
parent
9803db2949
commit
98b700e83c
@ -126,7 +126,7 @@ func (cfg Catalog) ToPackagesConfig() pkgcataloging.Config {
|
|||||||
IncludeUnindexedArchives: cfg.Package.SearchUnindexedArchives,
|
IncludeUnindexedArchives: cfg.Package.SearchUnindexedArchives,
|
||||||
}
|
}
|
||||||
return pkgcataloging.Config{
|
return pkgcataloging.Config{
|
||||||
Binary: binary.DefaultCatalogerConfig(),
|
Binary: binary.DefaultClassifierCatalogerConfig(),
|
||||||
Golang: golang.DefaultCatalogerConfig().
|
Golang: golang.DefaultCatalogerConfig().
|
||||||
WithSearchLocalModCacheLicenses(cfg.Golang.SearchLocalModCacheLicenses).
|
WithSearchLocalModCacheLicenses(cfg.Golang.SearchLocalModCacheLicenses).
|
||||||
WithLocalModCacheDir(cfg.Golang.LocalModCacheDir).
|
WithLocalModCacheDir(cfg.Golang.LocalModCacheDir).
|
||||||
|
|||||||
@ -112,7 +112,7 @@ func DefaultPackageTaskFactories() PackageTaskFactories {
|
|||||||
// other package catalogers ///////////////////////////////////////////////////////////////////////////
|
// other package catalogers ///////////////////////////////////////////////////////////////////////////
|
||||||
newPackageTaskFactory(
|
newPackageTaskFactory(
|
||||||
func(cfg CatalogingFactoryConfig) pkg.Cataloger {
|
func(cfg CatalogingFactoryConfig) pkg.Cataloger {
|
||||||
return binary.NewCataloger(cfg.PackagesConfig.Binary)
|
return binary.NewClassifierCataloger(cfg.PackagesConfig.Binary)
|
||||||
},
|
},
|
||||||
pkgcataloging.DeclaredTag, pkgcataloging.DirectoryTag, pkgcataloging.InstalledTag, pkgcataloging.ImageTag, "binary",
|
pkgcataloging.DeclaredTag, pkgcataloging.DirectoryTag, pkgcataloging.InstalledTag, pkgcataloging.ImageTag, "binary",
|
||||||
),
|
),
|
||||||
|
|||||||
@ -10,7 +10,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Binary binary.CatalogerConfig `yaml:"binary" json:"binary" mapstructure:"binary"`
|
Binary binary.ClassifierCatalogerConfig `yaml:"binary" json:"binary" mapstructure:"binary"`
|
||||||
Golang golang.CatalogerConfig `yaml:"golang" json:"golang" mapstructure:"golang"`
|
Golang golang.CatalogerConfig `yaml:"golang" json:"golang" mapstructure:"golang"`
|
||||||
JavaArchive java.ArchiveCatalogerConfig `yaml:"java-archive" json:"java-archive" mapstructure:"java-archive"`
|
JavaArchive java.ArchiveCatalogerConfig `yaml:"java-archive" json:"java-archive" mapstructure:"java-archive"`
|
||||||
JavaScript javascript.CatalogerConfig `yaml:"javascript" json:"javascript" mapstructure:"javascript"`
|
JavaScript javascript.CatalogerConfig `yaml:"javascript" json:"javascript" mapstructure:"javascript"`
|
||||||
@ -20,7 +20,7 @@ type Config struct {
|
|||||||
|
|
||||||
func DefaultConfig() Config {
|
func DefaultConfig() Config {
|
||||||
return Config{
|
return Config{
|
||||||
Binary: binary.DefaultCatalogerConfig(),
|
Binary: binary.DefaultClassifierCatalogerConfig(),
|
||||||
Golang: golang.DefaultCatalogerConfig(),
|
Golang: golang.DefaultCatalogerConfig(),
|
||||||
LinuxKernel: kernel.DefaultLinuxKernelCatalogerConfig(),
|
LinuxKernel: kernel.DefaultLinuxKernelCatalogerConfig(),
|
||||||
Python: python.DefaultCatalogerConfig(),
|
Python: python.DefaultCatalogerConfig(),
|
||||||
@ -28,7 +28,7 @@ func DefaultConfig() Config {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Config) WithBinaryConfig(cfg binary.CatalogerConfig) Config {
|
func (c Config) WithBinaryConfig(cfg binary.ClassifierCatalogerConfig) Config {
|
||||||
c.Binary = cfg
|
c.Binary = cfg
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,23 +15,23 @@ import (
|
|||||||
|
|
||||||
const catalogerName = "binary-cataloger"
|
const catalogerName = "binary-cataloger"
|
||||||
|
|
||||||
type CatalogerConfig struct {
|
type ClassifierCatalogerConfig struct {
|
||||||
Classifiers []Classifier `yaml:"classifiers" json:"classifiers" mapstructure:"classifiers"`
|
Classifiers []Classifier `yaml:"classifiers" json:"classifiers" mapstructure:"classifiers"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func DefaultCatalogerConfig() CatalogerConfig {
|
func DefaultClassifierCatalogerConfig() ClassifierCatalogerConfig {
|
||||||
return CatalogerConfig{
|
return ClassifierCatalogerConfig{
|
||||||
Classifiers: DefaultClassifiers(),
|
Classifiers: DefaultClassifiers(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCataloger(cfg CatalogerConfig) pkg.Cataloger {
|
func NewClassifierCataloger(cfg ClassifierCatalogerConfig) pkg.Cataloger {
|
||||||
return &cataloger{
|
return &cataloger{
|
||||||
classifiers: cfg.Classifiers,
|
classifiers: cfg.Classifiers,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cfg CatalogerConfig) MarshalJSON() ([]byte, error) {
|
func (cfg ClassifierCatalogerConfig) MarshalJSON() ([]byte, error) {
|
||||||
// only keep the class names
|
// only keep the class names
|
||||||
var names []string
|
var names []string
|
||||||
for _, cls := range cfg.Classifiers {
|
for _, cls := range cfg.Classifiers {
|
||||||
|
|||||||
@ -888,7 +888,7 @@ func Test_Cataloger_PositiveCases(t *testing.T) {
|
|||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
t.Run(test.logicalFixture, func(t *testing.T) {
|
t.Run(test.logicalFixture, func(t *testing.T) {
|
||||||
c := NewCataloger(DefaultCatalogerConfig())
|
c := NewClassifierCataloger(DefaultClassifierCatalogerConfig())
|
||||||
|
|
||||||
// logicalFixture is the logical path to the full binary or snippet. This is relative to the test-fixtures/classifiers/snippets
|
// logicalFixture is the logical path to the full binary or snippet. This is relative to the test-fixtures/classifiers/snippets
|
||||||
// or test-fixtures/classifiers/bin directory . Snippets are searched for first, and if not found, then existing binaries are
|
// or test-fixtures/classifiers/bin directory . Snippets are searched for first, and if not found, then existing binaries are
|
||||||
@ -933,7 +933,7 @@ func Test_Cataloger_DefaultClassifiers_PositiveCases_Image(t *testing.T) {
|
|||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
t.Run(test.name, func(t *testing.T) {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
c := NewCataloger(DefaultCatalogerConfig())
|
c := NewClassifierCataloger(DefaultClassifierCatalogerConfig())
|
||||||
|
|
||||||
img := imagetest.GetFixtureImage(t, "docker-archive", test.fixtureImage)
|
img := imagetest.GetFixtureImage(t, "docker-archive", test.fixtureImage)
|
||||||
src, err := source.NewFromStereoscopeImageObject(img, test.fixtureImage, nil)
|
src, err := source.NewFromStereoscopeImageObject(img, test.fixtureImage, nil)
|
||||||
@ -964,7 +964,7 @@ func Test_Cataloger_DefaultClassifiers_PositiveCases_Image(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestClassifierCataloger_DefaultClassifiers_NegativeCases(t *testing.T) {
|
func TestClassifierCataloger_DefaultClassifiers_NegativeCases(t *testing.T) {
|
||||||
c := NewCataloger(DefaultCatalogerConfig())
|
c := NewClassifierCataloger(DefaultClassifierCatalogerConfig())
|
||||||
|
|
||||||
src, err := source.NewFromDirectoryPath("test-fixtures/classifiers/negative")
|
src, err := source.NewFromDirectoryPath("test-fixtures/classifiers/negative")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
@ -1006,13 +1006,13 @@ func Test_Cataloger_CustomClassifiers(t *testing.T) {
|
|||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
config CatalogerConfig
|
config ClassifierCatalogerConfig
|
||||||
fixtureDir string
|
fixtureDir string
|
||||||
expected *pkg.Package
|
expected *pkg.Package
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "empty-negative",
|
name: "empty-negative",
|
||||||
config: CatalogerConfig{
|
config: ClassifierCatalogerConfig{
|
||||||
Classifiers: []Classifier{},
|
Classifiers: []Classifier{},
|
||||||
},
|
},
|
||||||
fixtureDir: "test-fixtures/custom/go-1.14",
|
fixtureDir: "test-fixtures/custom/go-1.14",
|
||||||
@ -1020,7 +1020,7 @@ func Test_Cataloger_CustomClassifiers(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "default-positive",
|
name: "default-positive",
|
||||||
config: CatalogerConfig{
|
config: ClassifierCatalogerConfig{
|
||||||
Classifiers: defaultClassifers,
|
Classifiers: defaultClassifers,
|
||||||
},
|
},
|
||||||
fixtureDir: "test-fixtures/custom/go-1.14",
|
fixtureDir: "test-fixtures/custom/go-1.14",
|
||||||
@ -1028,7 +1028,7 @@ func Test_Cataloger_CustomClassifiers(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "nodefault-negative",
|
name: "nodefault-negative",
|
||||||
config: CatalogerConfig{
|
config: ClassifierCatalogerConfig{
|
||||||
Classifiers: []Classifier{fooClassifier},
|
Classifiers: []Classifier{fooClassifier},
|
||||||
},
|
},
|
||||||
fixtureDir: "test-fixtures/custom/go-1.14",
|
fixtureDir: "test-fixtures/custom/go-1.14",
|
||||||
@ -1036,7 +1036,7 @@ func Test_Cataloger_CustomClassifiers(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "default-extended-positive",
|
name: "default-extended-positive",
|
||||||
config: CatalogerConfig{
|
config: ClassifierCatalogerConfig{
|
||||||
Classifiers: append(
|
Classifiers: append(
|
||||||
append([]Classifier{}, defaultClassifers...),
|
append([]Classifier{}, defaultClassifers...),
|
||||||
fooClassifier,
|
fooClassifier,
|
||||||
@ -1047,7 +1047,7 @@ func Test_Cataloger_CustomClassifiers(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "default-custom-negative",
|
name: "default-custom-negative",
|
||||||
config: CatalogerConfig{
|
config: ClassifierCatalogerConfig{
|
||||||
|
|
||||||
Classifiers: append(
|
Classifiers: append(
|
||||||
append([]Classifier{}, defaultClassifers...),
|
append([]Classifier{}, defaultClassifers...),
|
||||||
@ -1066,7 +1066,7 @@ func Test_Cataloger_CustomClassifiers(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "default-cutsom-positive",
|
name: "default-cutsom-positive",
|
||||||
config: CatalogerConfig{
|
config: ClassifierCatalogerConfig{
|
||||||
Classifiers: append(
|
Classifiers: append(
|
||||||
append([]Classifier{}, defaultClassifers...),
|
append([]Classifier{}, defaultClassifers...),
|
||||||
fooClassifier,
|
fooClassifier,
|
||||||
@ -1078,7 +1078,7 @@ func Test_Cataloger_CustomClassifiers(t *testing.T) {
|
|||||||
}
|
}
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
t.Run(test.name, func(t *testing.T) {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
c := NewCataloger(test.config)
|
c := NewClassifierCataloger(test.config)
|
||||||
|
|
||||||
src, err := source.NewFromDirectoryPath(test.fixtureDir)
|
src, err := source.NewFromDirectoryPath(test.fixtureDir)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
@ -1249,7 +1249,7 @@ func (p *panicyResolver) FileMetadataByLocation(_ file.Location) (file.Metadata,
|
|||||||
var _ file.Resolver = (*panicyResolver)(nil)
|
var _ file.Resolver = (*panicyResolver)(nil)
|
||||||
|
|
||||||
func Test_Cataloger_ResilientToErrors(t *testing.T) {
|
func Test_Cataloger_ResilientToErrors(t *testing.T) {
|
||||||
c := NewCataloger(DefaultCatalogerConfig())
|
c := NewClassifierCataloger(DefaultClassifierCatalogerConfig())
|
||||||
|
|
||||||
resolver := &panicyResolver{}
|
resolver := &panicyResolver{}
|
||||||
_, _, err := c.Catalog(context.Background(), resolver)
|
_, _, err := c.Catalog(context.Background(), resolver)
|
||||||
@ -1261,13 +1261,13 @@ func TestCatalogerConfig_MarshalJSON(t *testing.T) {
|
|||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
cfg CatalogerConfig
|
cfg ClassifierCatalogerConfig
|
||||||
want string
|
want string
|
||||||
wantErr assert.ErrorAssertionFunc
|
wantErr assert.ErrorAssertionFunc
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "only show names of classes",
|
name: "only show names of classes",
|
||||||
cfg: CatalogerConfig{
|
cfg: ClassifierCatalogerConfig{
|
||||||
Classifiers: []Classifier{
|
Classifiers: []Classifier{
|
||||||
{
|
{
|
||||||
Class: "class",
|
Class: "class",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user