add collection

Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
This commit is contained in:
Alex Goodman 2020-09-03 09:28:45 -04:00
parent 3e27b6e93f
commit c231a9d7cb
No known key found for this signature in database
GPG Key ID: 86E2870463D5E890
8 changed files with 52 additions and 39 deletions

View File

@ -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

View File

@ -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
}

View File

@ -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()
}

View File

@ -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()

View File

@ -0,0 +1,7 @@
package plugin
// repository
type Collection struct {
byType map[Type]Plugin
byName map[string]Plugin
}

10
syft/plugin/config.go Normal file
View File

@ -0,0 +1,10 @@
package plugin
type Config struct {
Name string
Type Type
Command string
Args []string
Env []string
//Sha256 []byte
}

View File

@ -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
}

View File

@ -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()