mirror of
https://github.com/anchore/syft.git
synced 2026-11-03 16:06:36 +01:00
* change directory resolver to ignore system runtime paths + drive by index Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * add event/etui support for filesystem indexing (for dir resolver) Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * add warnings for path indexing problems Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * add directory resolver index tests Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * improve testing around directory resolver Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * renamed p var to path when not conflicting with import Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * pull docker image in CLI dir scan timeout test Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * ensure file not exist errors do not stop directory resolver indexing Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
158 lines
3.7 KiB
Go
158 lines
3.7 KiB
Go
/*
|
|
Package parsers provides parser helpers to extract payloads for each event type that the syft library publishes onto the event bus.
|
|
*/
|
|
package parsers
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/anchore/syft/syft/presenter"
|
|
|
|
"github.com/anchore/syft/syft/file"
|
|
|
|
"github.com/wagoodman/go-progress"
|
|
|
|
"github.com/anchore/syft/syft/event"
|
|
"github.com/anchore/syft/syft/pkg/cataloger"
|
|
"github.com/wagoodman/go-partybus"
|
|
)
|
|
|
|
type ErrBadPayload struct {
|
|
Type partybus.EventType
|
|
Field string
|
|
Value interface{}
|
|
}
|
|
|
|
func (e *ErrBadPayload) Error() string {
|
|
return fmt.Sprintf("event='%s' has bad event payload field='%v': '%+v'", string(e.Type), e.Field, e.Value)
|
|
}
|
|
|
|
func newPayloadErr(t partybus.EventType, field string, value interface{}) error {
|
|
return &ErrBadPayload{
|
|
Type: t,
|
|
Field: field,
|
|
Value: value,
|
|
}
|
|
}
|
|
|
|
func checkEventType(actual, expected partybus.EventType) error {
|
|
if actual != expected {
|
|
return newPayloadErr(expected, "Type", actual)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func ParsePackageCatalogerStarted(e partybus.Event) (*cataloger.Monitor, error) {
|
|
if err := checkEventType(e.Type, event.PackageCatalogerStarted); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
monitor, ok := e.Value.(cataloger.Monitor)
|
|
if !ok {
|
|
return nil, newPayloadErr(e.Type, "Value", e.Value)
|
|
}
|
|
|
|
return &monitor, nil
|
|
}
|
|
|
|
func ParseSecretsCatalogingStarted(e partybus.Event) (*file.SecretsMonitor, error) {
|
|
if err := checkEventType(e.Type, event.SecretsCatalogerStarted); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
monitor, ok := e.Value.(file.SecretsMonitor)
|
|
if !ok {
|
|
return nil, newPayloadErr(e.Type, "Value", e.Value)
|
|
}
|
|
|
|
return &monitor, nil
|
|
}
|
|
|
|
func ParseFileMetadataCatalogingStarted(e partybus.Event) (progress.StagedProgressable, error) {
|
|
if err := checkEventType(e.Type, event.FileMetadataCatalogerStarted); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
prog, ok := e.Value.(progress.StagedProgressable)
|
|
if !ok {
|
|
return nil, newPayloadErr(e.Type, "Value", e.Value)
|
|
}
|
|
|
|
return prog, nil
|
|
}
|
|
|
|
func ParseFileDigestsCatalogingStarted(e partybus.Event) (progress.StagedProgressable, error) {
|
|
if err := checkEventType(e.Type, event.FileDigestsCatalogerStarted); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
prog, ok := e.Value.(progress.StagedProgressable)
|
|
if !ok {
|
|
return nil, newPayloadErr(e.Type, "Value", e.Value)
|
|
}
|
|
|
|
return prog, nil
|
|
}
|
|
|
|
func ParseFileIndexingStarted(e partybus.Event) (string, progress.StagedProgressable, error) {
|
|
if err := checkEventType(e.Type, event.FileIndexingStarted); err != nil {
|
|
return "", nil, err
|
|
}
|
|
|
|
path, ok := e.Source.(string)
|
|
if !ok {
|
|
return "", nil, newPayloadErr(e.Type, "Source", e.Source)
|
|
}
|
|
|
|
prog, ok := e.Value.(progress.StagedProgressable)
|
|
if !ok {
|
|
return "", nil, newPayloadErr(e.Type, "Value", e.Value)
|
|
}
|
|
|
|
return path, prog, nil
|
|
}
|
|
|
|
func ParsePresenterReady(e partybus.Event) (presenter.Presenter, error) {
|
|
if err := checkEventType(e.Type, event.PresenterReady); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
pres, ok := e.Value.(presenter.Presenter)
|
|
if !ok {
|
|
return nil, newPayloadErr(e.Type, "Value", e.Value)
|
|
}
|
|
|
|
return pres, nil
|
|
}
|
|
|
|
func ParseAppUpdateAvailable(e partybus.Event) (string, error) {
|
|
if err := checkEventType(e.Type, event.AppUpdateAvailable); err != nil {
|
|
return "", err
|
|
}
|
|
|
|
newVersion, ok := e.Value.(string)
|
|
if !ok {
|
|
return "", newPayloadErr(e.Type, "Value", e.Value)
|
|
}
|
|
|
|
return newVersion, nil
|
|
}
|
|
|
|
func ParseImportStarted(e partybus.Event) (string, progress.StagedProgressable, error) {
|
|
if err := checkEventType(e.Type, event.ImportStarted); err != nil {
|
|
return "", nil, err
|
|
}
|
|
|
|
host, ok := e.Source.(string)
|
|
if !ok {
|
|
return "", nil, newPayloadErr(e.Type, "Source", e.Source)
|
|
}
|
|
|
|
prog, ok := e.Value.(progress.StagedProgressable)
|
|
if !ok {
|
|
return "", nil, newPayloadErr(e.Type, "Value", e.Value)
|
|
}
|
|
|
|
return host, prog, nil
|
|
}
|