diff --git a/.golangci.yaml b/.golangci.yaml index 638b3e696..c1bbd9324 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -31,7 +31,6 @@ linters: - misspell - nakedret - nolintlint -# - prealloc - rowserrcheck - scopelint - staticcheck @@ -55,5 +54,6 @@ linters: # - lll # without a way to specify per-line exception cases, this is not usable # - maligned # this is an excellent linter, but tricky to optimize and we are not sensitive to memory layout optimizations # - nestif +# - prealloc # this unnecessarily requires preallocations for slices # - testpackage # - wsl \ No newline at end of file diff --git a/syft/cataloger/catalog.go b/syft/cataloger/catalog.go index 4e4e95942..14419732c 100644 --- a/syft/cataloger/catalog.go +++ b/syft/cataloger/catalog.go @@ -12,27 +12,6 @@ import ( "github.com/wagoodman/go-progress" ) -// Monitor provides progress-related data for observing the progress of a Catalog() call (published on the event bus). -type Monitor struct { - FilesProcessed progress.Monitorable // the number of files selected and contents analyzed from all registered catalogers - PackagesDiscovered progress.Monitorable // the number of packages discovered from all registered catalogers -} - -// newMonitor creates a new Monitor object and publishes the object on the bus as a CatalogerStarted event. -func newMonitor() (*progress.Manual, *progress.Manual) { - filesProcessed := progress.Manual{} - packagesDiscovered := progress.Manual{} - - bus.Publish(partybus.Event{ - Type: event.CatalogerStarted, - Value: Monitor{ - FilesProcessed: progress.Monitorable(&filesProcessed), - PackagesDiscovered: progress.Monitorable(&packagesDiscovered), - }, - }) - return &filesProcessed, &packagesDiscovered -} - // Catalog a given scope (container image or filesystem) with the given catalogers, returning all discovered packages. // In order to efficiently retrieve contents from a underlying container image the content fetch requests are // done in bulk. Specifically, all files of interest are collected from each catalogers and accumulated into a single @@ -86,3 +65,24 @@ func Catalog(resolver scope.Resolver, catalogers ...Cataloger) (*pkg.Catalog, er return catalog, nil } + +// Monitor provides progress-related data for observing the progress of a Catalog() call (published on the event bus). +type Monitor struct { + FilesProcessed progress.Monitorable // the number of files selected and contents analyzed from all registered catalogers + PackagesDiscovered progress.Monitorable // the number of packages discovered from all registered catalogers +} + +// newMonitor creates a new Monitor object and publishes the object on the bus as a CatalogerStarted event. +func newMonitor() (*progress.Manual, *progress.Manual) { + filesProcessed := progress.Manual{} + packagesDiscovered := progress.Manual{} + + bus.Publish(partybus.Event{ + Type: event.CatalogerStarted, + Value: Monitor{ + FilesProcessed: progress.Monitorable(&filesProcessed), + PackagesDiscovered: progress.Monitorable(&packagesDiscovered), + }, + }) + return &filesProcessed, &packagesDiscovered +} diff --git a/syft/cataloger/cataloger.go b/syft/cataloger/cataloger.go index 237aa6697..fb1136644 100644 --- a/syft/cataloger/cataloger.go +++ b/syft/cataloger/cataloger.go @@ -34,8 +34,7 @@ type Cataloger interface { // TODO: add "IterationNeeded" error to indicate to the driver to continue with another Select/Catalog pass } -// All returns a slice of all locally defined catalogers (defined in child packages). -func All() []Cataloger { +func BuiltIn() []Cataloger { return []Cataloger{ dpkg.New(), bundler.New(), @@ -47,3 +46,8 @@ func All() []Cataloger { javascript.New(), } } + +// All returns a slice of all locally defined catalogers (defined in child packages). +func All() []Cataloger { + return BuiltIn() +} diff --git a/syft/distro/identify.go b/syft/distro/identify.go index db418a49f..2c3aa60ef 100644 --- a/syft/distro/identify.go +++ b/syft/distro/identify.go @@ -19,6 +19,7 @@ type parseEntry struct { fn parseFunc } +// nolint: funlen // Identify parses distro-specific files to determine distro metadata like version and release. func Identify(resolver scope.Resolver) Distro { distro := NewUnknownDistro() diff --git a/syft/plugin/collection.go b/syft/plugin/collection.go new file mode 100644 index 000000000..9d96c6070 --- /dev/null +++ b/syft/plugin/collection.go @@ -0,0 +1,7 @@ +package plugin + +// repository +type Collection struct { + byType map[Type]Plugin + byName map[string]Plugin +} diff --git a/syft/plugin/config.go b/syft/plugin/config.go new file mode 100644 index 000000000..6969c99f1 --- /dev/null +++ b/syft/plugin/config.go @@ -0,0 +1,10 @@ +package plugin + +type Config struct { + Name string + Type Type + Command string + Args []string + Env []string + //Sha256 []byte +} diff --git a/syft/plugin/grpc/cataloger_server.go b/syft/plugin/grpc/cataloger_server.go index b568307a9..7da492e48 100644 --- a/syft/plugin/grpc/cataloger_server.go +++ b/syft/plugin/grpc/cataloger_server.go @@ -64,7 +64,7 @@ func (s *CatalogerServer) Catalog(ctx context.Context, req *proto.CatalogRequest return nil, err } - var results []proto.Package + var results []*proto.Package for _, p := range packages { var sources []*proto.FileReference for _, s := range p.Source { @@ -80,7 +80,7 @@ func (s *CatalogerServer) Catalog(ctx context.Context, req *proto.CatalogRequest } // TODO: this is potentially brittle - results = append(results, proto.Package{ + results = append(results, &proto.Package{ Name: p.Name, Version: p.Version, FoundBy: p.FoundBy, @@ -94,6 +94,6 @@ func (s *CatalogerServer) Catalog(ctx context.Context, req *proto.CatalogRequest } return &proto.CatalogResponse{ - Package: nil, + Package: results, }, nil } diff --git a/syft/plugin/plugin.go b/syft/plugin/plugin.go index 12cdd0745..5e56febc0 100644 --- a/syft/plugin/plugin.go +++ b/syft/plugin/plugin.go @@ -13,18 +13,9 @@ var plugins = map[int]plugin.PluginSet{ }, } -type Config struct { - Name string - Type Type - Command string - Args []string - Env []string - //Sha256 []byte -} - type Plugin struct { Config Config - clientConfig *plugin.ClientConfig + clientConfig plugin.ClientConfig client *plugin.Client } @@ -37,7 +28,7 @@ func NewPlugin(config Config) Plugin { // Hash: sha256.New(), //} - clientConfig := &plugin.ClientConfig{ + clientConfig := plugin.ClientConfig{ HandshakeConfig: config.Type.HandshakeConfig(), VersionedPlugins: plugins, //SecureConfig: secureConfig, @@ -59,7 +50,7 @@ func (p Plugin) Start() (interface{}, error) { } // start the plugin in a sub process - p.client = plugin.NewClient(p.clientConfig) + p.client = plugin.NewClient(&p.clientConfig) // connect to the sub process via RPC rpcClient, err := p.client.Client()