Skip to content

Commit dcc0d6d

Browse files
committed
refactor: use RequiredPlugins to decide if transitive enrichers should be enabled
1 parent a750891 commit dcc0d6d

File tree

1 file changed

+10
-22
lines changed

1 file changed

+10
-22
lines changed

pkg/osvscanner/scan.go

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ import (
1919
transitivedependencyrequirements "github.com/google/osv-scalibr/enricher/transitivedependency/requirements"
2020
"github.com/google/osv-scalibr/extractor"
2121
"github.com/google/osv-scalibr/extractor/filesystem"
22-
"github.com/google/osv-scalibr/extractor/filesystem/language/java/pomxml"
23-
"github.com/google/osv-scalibr/extractor/filesystem/language/python/requirements"
2422
"github.com/google/osv-scalibr/extractor/filesystem/simplefileapi"
2523
"github.com/google/osv-scalibr/fs"
2624
"github.com/google/osv-scalibr/inventory"
@@ -47,28 +45,20 @@ func configurePlugins(plugins []plugin.Plugin, accessors ExternalAccessors, acti
4745
}
4846
}
4947

50-
func isRequirementsExtractorEnabled(plugins []plugin.Plugin) bool {
51-
for _, plug := range plugins {
52-
_, ok := plug.(*requirements.Extractor)
48+
func areRequiredPluginsEnabled(plugins []plugin.Plugin, enr enricher.Enricher) bool {
49+
enabled := make(map[string]struct{}, len(plugins))
5350

54-
if ok {
55-
return true
56-
}
57-
}
58-
59-
return false
60-
}
61-
62-
func isPomXMLExtractorEnabled(plugins []plugin.Plugin) bool {
6351
for _, plug := range plugins {
64-
_, ok := plug.(*pomxml.Extractor)
52+
enabled[plug.Name()] = struct{}{}
53+
}
6554

66-
if ok {
67-
return true
55+
for _, required := range enr.RequiredPlugins() {
56+
if _, ok := enabled[required]; !ok {
57+
return false
6858
}
6959
}
7060

71-
return false
61+
return true
7262
}
7363

7464
func getPlugins(defaultPlugins []string, accessors ExternalAccessors, actions ScannerActions) []plugin.Plugin {
@@ -87,8 +77,7 @@ func getPlugins(defaultPlugins []string, accessors ExternalAccessors, actions Sc
8777
plugins := scalibrplugin.Resolve(actions.PluginsEnabled, actions.PluginsDisabled)
8878

8979
if !actions.TransitiveScanning.Disabled {
90-
// TODO: Use Enricher.RequiredPlugins to check this generically
91-
if isRequirementsExtractorEnabled(plugins) {
80+
if areRequiredPluginsEnabled(plugins, transitivedependencyrequirements.Enricher{}) {
9281
p, err := transitivedependencyrequirements.New(&cpb.PluginConfig{
9382
UserAgent: actions.RequestUserAgent,
9483
})
@@ -99,8 +88,7 @@ func getPlugins(defaultPlugins []string, accessors ExternalAccessors, actions Sc
9988
}
10089
}
10190

102-
// TODO: Use Enricher.RequiredPlugins to check this generically
103-
if isPomXMLExtractorEnabled(plugins) {
91+
if areRequiredPluginsEnabled(plugins, transitivedependencypomxml.Enricher{}) {
10492
p, err := transitivedependencypomxml.New(&cpb.PluginConfig{
10593
UserAgent: actions.RequestUserAgent,
10694
PluginSpecific: []*cpb.PluginSpecificConfig{

0 commit comments

Comments
 (0)