mirror of
https://github.com/anchore/syft.git
synced 2026-11-01 15:06:36 +01:00
rename to syft
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
package event
|
||||
|
||||
import "github.com/wagoodman/go-partybus"
|
||||
|
||||
const (
|
||||
AppUpdateAvailable partybus.EventType = "app-update-available"
|
||||
CatalogerStarted partybus.EventType = "cataloger-started-event"
|
||||
CatalogerFinished partybus.EventType = "cataloger-finished-event"
|
||||
)
|
||||
@@ -0,0 +1,74 @@
|
||||
package parsers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/anchore/syft/syft/cataloger"
|
||||
"github.com/anchore/syft/syft/event"
|
||||
"github.com/anchore/syft/syft/presenter"
|
||||
"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 ParseCatalogerStarted(e partybus.Event) (*cataloger.Monitor, error) {
|
||||
if err := checkEventType(e.Type, event.CatalogerStarted); 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 ParseCatalogerFinished(e partybus.Event) (presenter.Presenter, error) {
|
||||
if err := checkEventType(e.Type, event.CatalogerFinished); 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
|
||||
}
|
||||
Reference in New Issue
Block a user