mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 08:23:15 +01:00
add collection
Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
This commit is contained in:
parent
3e27b6e93f
commit
c231a9d7cb
@ -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
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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()
|
||||
}
|
||||
|
||||
@ -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()
|
||||
|
||||
7
syft/plugin/collection.go
Normal file
7
syft/plugin/collection.go
Normal 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
10
syft/plugin/config.go
Normal file
@ -0,0 +1,10 @@
|
||||
package plugin
|
||||
|
||||
type Config struct {
|
||||
Name string
|
||||
Type Type
|
||||
Command string
|
||||
Args []string
|
||||
Env []string
|
||||
//Sha256 []byte
|
||||
}
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user