grype/ui/handler.go
Christopher Angelo Phillips 788ed965ec
chore: prune cosign dependency for grype builds (#1100)
* feat: segment cosign dependency for grype builds for faster build times

Signed-off-by: Christopher Phillips <christopher.phillips@anchore.com>
2023-01-31 11:42:40 -05:00

46 lines
1.1 KiB
Go

package ui
import (
"context"
"sync"
"github.com/wagoodman/go-partybus"
"github.com/wagoodman/jotframe/pkg/frame"
grypeEvent "github.com/anchore/grype/grype/event"
syftUI "github.com/anchore/syft/ui"
)
type Handler struct {
syftHandler *syftUI.Handler
}
func NewHandler() *Handler {
return &Handler{
syftHandler: syftUI.NewHandler(),
}
}
func (r *Handler) RespondsTo(event partybus.Event) bool {
switch event.Type {
case grypeEvent.VulnerabilityScanningStarted,
grypeEvent.UpdateVulnerabilityDatabase,
grypeEvent.DatabaseDiffingStarted:
return true
default:
return r.syftHandler.RespondsTo(event)
}
}
func (r *Handler) Handle(ctx context.Context, fr *frame.Frame, event partybus.Event, wg *sync.WaitGroup) error {
switch event.Type {
case grypeEvent.VulnerabilityScanningStarted:
return r.VulnerabilityScanningStartedHandler(ctx, fr, event, wg)
case grypeEvent.UpdateVulnerabilityDatabase:
return r.UpdateVulnerabilityDatabaseHandler(ctx, fr, event, wg)
case grypeEvent.DatabaseDiffingStarted:
return r.DatabaseDiffingStartedHandler(ctx, fr, event, wg)
default:
return r.syftHandler.Handle(ctx, fr, event, wg)
}
}