Skip to content

Commit 03bd125

Browse files
mtrzoscopybara-github
authored andcommitted
Add global plugin config to the apk, cos, dpkg and rpm plugins.
PiperOrigin-RevId: 846651631
1 parent d2cba0c commit 03bd125

12 files changed

Lines changed: 282 additions & 278 deletions

File tree

‎binary/proto/config.proto‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ message PluginSpecificConfig {
5353
HashiCorpVaultValidatorConfig hashicorp_vault_validator = 7;
5454
SDPInspectConfig sdp_inspect = 8;
5555
POMXMLNetConfig pom_xml_net = 9;
56+
DpkgConfig dpkg = 10;
57+
RpmConfig rpm = 11;
5658
}
5759
}
5860

@@ -111,3 +113,14 @@ message POMXMLNetConfig {
111113
// The URL of the upstream Maven registry.
112114
string upstream_registry = 1;
113115
}
116+
117+
message DpkgConfig {
118+
// IncludeNotInstalled includes packages that are not installed
119+
// (e.g. `deinstall`, `purge`, and those missing a status field).
120+
bool include_not_installed = 1;
121+
}
122+
123+
message RpmConfig {
124+
// Timeout in seconds for parsing the RPM database.
125+
int64 timeout_seconds = 1;
126+
}

‎binary/proto/config_go_proto/config.pb.go‎

Lines changed: 147 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎extractor/filesystem/list/list.go‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -267,10 +267,10 @@ var (
267267

268268
// OS extractors.
269269
OS = InitMap{
270-
dpkg.Name: {noCFG(dpkg.NewDefault)},
271-
apk.Name: {noCFG(apk.NewDefault)},
272-
rpm.Name: {noCFG(rpm.NewDefault)},
273-
cos.Name: {noCFG(cos.NewDefault)},
270+
dpkg.Name: {dpkg.New},
271+
apk.Name: {apk.New},
272+
rpm.Name: {rpm.New},
273+
cos.Name: {cos.New},
274274
snap.Name: {noCFG(snap.NewDefault)},
275275
nix.Name: {noCFG(nix.New)},
276276
module.Name: {noCFG(module.NewDefault)},
@@ -494,7 +494,7 @@ func noCFG(f func() filesystem.Extractor) InitFn {
494494
// ExtractorsFromName returns a list of extractors from a name.
495495
func ExtractorsFromName(name string, cfg *cpb.PluginConfig) ([]filesystem.Extractor, error) {
496496
if initers, ok := extractorNames[name]; ok {
497-
result := []filesystem.Extractor{}
497+
var result []filesystem.Extractor
498498
for _, initer := range initers {
499499
result = append(result, initer(cfg))
500500
}

‎extractor/filesystem/os/apk/apk.go‎

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -30,52 +30,31 @@ import (
3030
"github.com/google/osv-scalibr/plugin"
3131
"github.com/google/osv-scalibr/purl"
3232
"github.com/google/osv-scalibr/stats"
33+
34+
cpb "github.com/google/osv-scalibr/binary/proto/config_go_proto"
3335
)
3436

3537
const (
3638
// Name is the unique name of this extractor.
3739
Name = "os/apk"
3840
)
3941

40-
// Config is the configuration for the Extractor.
41-
type Config struct {
42-
// Stats is a stats collector for reporting metrics.
43-
Stats stats.Collector
44-
// MaxFileSizeBytes is the maximum file size this extractor will unmarshal. If
45-
// `FileRequired` gets a bigger file, it will return false,
46-
MaxFileSizeBytes int64
47-
}
48-
49-
// DefaultConfig returns the default configuration for the extractor.
50-
func DefaultConfig() Config {
51-
return Config{
52-
MaxFileSizeBytes: 0,
53-
Stats: nil,
54-
}
55-
}
56-
5742
// Extractor extracts packages from the APK database.
5843
type Extractor struct {
59-
stats stats.Collector
44+
Stats stats.Collector
6045
maxFileSizeBytes int64
6146
}
6247

6348
// New returns an APK extractor.
6449
//
6550
// For most use cases, initialize with:
6651
// ```
67-
// e := New(DefaultConfig())
52+
// e := New(&cpb.PluginConfig{})
6853
// ```
69-
func New(cfg Config) *Extractor {
70-
return &Extractor{
71-
stats: cfg.Stats,
72-
maxFileSizeBytes: cfg.MaxFileSizeBytes,
73-
}
54+
func New(cfg *cpb.PluginConfig) filesystem.Extractor {
55+
return &Extractor{maxFileSizeBytes: cfg.MaxFileSizeBytes}
7456
}
7557

76-
// NewDefault returns an extractor with the default config settings.
77-
func NewDefault() filesystem.Extractor { return New(DefaultConfig()) }
78-
7958
// Name of the extractor.
8059
func (e Extractor) Name() string { return Name }
8160

@@ -109,10 +88,10 @@ func (e Extractor) FileRequired(api filesystem.FileAPI) bool {
10988
}
11089

11190
func (e Extractor) reportFileRequired(path string, fileSizeBytes int64, result stats.FileRequiredResult) {
112-
if e.stats == nil {
91+
if e.Stats == nil {
11392
return
11493
}
115-
e.stats.AfterFileRequired(e.Name(), &stats.FileRequiredStats{
94+
e.Stats.AfterFileRequired(e.Name(), &stats.FileRequiredStats{
11695
Path: path,
11796
Result: result,
11897
FileSizeBytes: fileSizeBytes,
@@ -122,12 +101,12 @@ func (e Extractor) reportFileRequired(path string, fileSizeBytes int64, result s
122101
// Extract extracts packages from lib/apk/db/installed passed through the scan input.
123102
func (e Extractor) Extract(ctx context.Context, input *filesystem.ScanInput) (inventory.Inventory, error) {
124103
pkgs, err := e.extractFromInput(ctx, input)
125-
if e.stats != nil {
104+
if e.Stats != nil {
126105
var fileSizeBytes int64
127106
if input.Info != nil {
128107
fileSizeBytes = input.Info.Size()
129108
}
130-
e.stats.AfterFileExtracted(e.Name(), &stats.FileExtractedStats{
109+
e.Stats.AfterFileExtracted(e.Name(), &stats.FileExtractedStats{
131110
Path: input.Path,
132111
Result: filesystem.ExtractorErrorToFileExtractedResult(err),
133112
FileSizeBytes: fileSizeBytes,

0 commit comments

Comments
 (0)