@@ -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
3537const (
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.
5843type 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.
8059func (e Extractor ) Name () string { return Name }
8160
@@ -109,10 +88,10 @@ func (e Extractor) FileRequired(api filesystem.FileAPI) bool {
10988}
11089
11190func (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.
123102func (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