Revert "External sources configuration (#1158)" (#1191)

reverted as functionality is to be merged with dev branch of kubecon draft
This commit is contained in:
Christopher Angelo Phillips
2022-09-01 15:45:35 -04:00
committed by GitHub
parent 1b0cfe7246
commit 586d3fe77f
14 changed files with 16 additions and 132 deletions
+7 -38
View File
@@ -41,8 +41,6 @@ type Cataloger interface {
Name() string
// Catalog is given an object to resolve file references and content, this function returns any discovered Packages after analyzing the catalog source.
Catalog(resolver source.FileResolver) ([]pkg.Package, []artifact.Relationship, error)
// UsesExternalSources returns if the cataloger uses external sources, such as querying a database
UsesExternalSources() bool
}
// ImageCatalogers returns a slice of locally implemented catalogers that are fit for detecting installations of packages.
@@ -60,7 +58,7 @@ func ImageCatalogers(cfg Config) []Cataloger {
golang.NewGoModuleBinaryCataloger(),
dotnet.NewDotnetDepsCataloger(),
portage.NewPortageCataloger(),
}, cfg)
}, cfg.Catalogers)
}
// DirectoryCatalogers returns a slice of locally implemented catalogers that are fit for detecting packages from index files (and select installations)
@@ -86,7 +84,7 @@ func DirectoryCatalogers(cfg Config) []Cataloger {
cpp.NewConanfileCataloger(),
portage.NewPortageCataloger(),
haskell.NewHackageCataloger(),
}, cfg)
}, cfg.Catalogers)
}
// AllCatalogers returns all implemented catalogers
@@ -116,20 +114,10 @@ func AllCatalogers(cfg Config) []Cataloger {
cpp.NewConanfileCataloger(),
portage.NewPortageCataloger(),
haskell.NewHackageCataloger(),
}, cfg)
}, cfg.Catalogers)
}
// RequestedAllCatalogers returns true if all Catalogers have been requested. Takes into account cfg.ExternalSourcesEnabled
func RequestedAllCatalogers(cfg Config) bool {
// if external sources are disabled, only return false if there actually are any catalogers that use external sources
if !cfg.ExternalSourcesEnabled {
for _, cat := range AllCatalogers(Config{Catalogers: []string{"all"}, ExternalSourcesEnabled: true}) {
if cat.UsesExternalSources() {
return false
}
}
}
for _, enableCatalogerPattern := range cfg.Catalogers {
if enableCatalogerPattern == AllCatalogersPattern {
return true
@@ -138,33 +126,14 @@ func RequestedAllCatalogers(cfg Config) bool {
return false
}
func filterForExternalSources(catalogers []Cataloger, cfg Config) []Cataloger {
if cfg.ExternalSourcesEnabled {
return catalogers
}
var enabledCatalogers []Cataloger
for _, cataloger := range catalogers {
if !cataloger.UsesExternalSources() {
enabledCatalogers = append(enabledCatalogers, cataloger)
} else {
log.Infof("cataloger %v will not be used because external sources are disabled", cataloger.Name())
}
}
return enabledCatalogers
}
func filterCatalogers(catalogers []Cataloger, cfg Config) []Cataloger {
enabledCatalogerPatterns := cfg.Catalogers
func filterCatalogers(catalogers []Cataloger, enabledCatalogerPatterns []string) []Cataloger {
// if cataloger is not set, all applicable catalogers are enabled by default
if len(enabledCatalogerPatterns) == 0 {
return filterForExternalSources(catalogers, cfg)
return catalogers
}
for _, enableCatalogerPattern := range enabledCatalogerPatterns {
if enableCatalogerPattern == AllCatalogersPattern {
return filterForExternalSources(catalogers, cfg)
return catalogers
}
}
var keepCatalogers []Cataloger
@@ -175,7 +144,7 @@ func filterCatalogers(catalogers []Cataloger, cfg Config) []Cataloger {
}
log.Infof("skipping cataloger %q", cataloger.Name())
}
return filterForExternalSources(keepCatalogers, cfg)
return keepCatalogers
}
func contains(enabledPartial []string, catalogerName string) bool {