2020-08-12 15:04:39 +00:00
|
|
|
/*
|
|
|
|
Package ui provides all public UI elements intended to be repurposed in other applications. Specifically, a single
|
|
|
|
Handler object is provided to allow consuming applications (such as grype) to check if there are UI elements the handler
|
|
|
|
can respond to (given a specific event type) and handle the event in context of the given screen frame object.
|
|
|
|
*/
|
2020-07-30 19:16:58 +00:00
|
|
|
package ui
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"sync"
|
|
|
|
|
|
|
|
"github.com/wagoodman/go-partybus"
|
|
|
|
"github.com/wagoodman/jotframe/pkg/frame"
|
2022-09-14 17:38:18 +00:00
|
|
|
|
|
|
|
stereoscopeEvent "github.com/anchore/stereoscope/pkg/event"
|
|
|
|
syftEvent "github.com/anchore/syft/syft/event"
|
2020-07-30 19:16:58 +00:00
|
|
|
)
|
|
|
|
|
2021-03-18 12:57:18 +00:00
|
|
|
// Handler is an aggregated event handler for the set of supported events (PullDockerImage, ReadImage, FetchImage, PackageCatalogerStarted)
|
2020-07-30 19:16:58 +00:00
|
|
|
type Handler struct {
|
|
|
|
}
|
|
|
|
|
2020-08-12 15:04:39 +00:00
|
|
|
// NewHandler returns an empty Handler
|
2020-07-30 19:16:58 +00:00
|
|
|
func NewHandler() *Handler {
|
|
|
|
return &Handler{}
|
|
|
|
}
|
|
|
|
|
2020-08-12 15:04:39 +00:00
|
|
|
// RespondsTo indicates if the handler is capable of handling the given event.
|
2020-07-30 19:16:58 +00:00
|
|
|
func (r *Handler) RespondsTo(event partybus.Event) bool {
|
|
|
|
switch event.Type {
|
2022-05-06 22:06:32 +00:00
|
|
|
case stereoscopeEvent.PullDockerImage,
|
|
|
|
stereoscopeEvent.ReadImage,
|
|
|
|
stereoscopeEvent.FetchImage,
|
|
|
|
syftEvent.PackageCatalogerStarted,
|
|
|
|
syftEvent.SecretsCatalogerStarted,
|
|
|
|
syftEvent.FileDigestsCatalogerStarted,
|
|
|
|
syftEvent.FileMetadataCatalogerStarted,
|
|
|
|
syftEvent.FileIndexingStarted,
|
2023-01-12 17:22:05 +00:00
|
|
|
syftEvent.ImportStarted,
|
2023-04-14 19:13:29 +00:00
|
|
|
syftEvent.AttestationStarted,
|
|
|
|
syftEvent.CatalogerTaskStarted:
|
2020-07-30 19:16:58 +00:00
|
|
|
return true
|
|
|
|
default:
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-12 15:04:39 +00:00
|
|
|
// Handle calls the specific event handler for the given event within the context of the screen frame.
|
2020-07-30 19:16:58 +00:00
|
|
|
func (r *Handler) Handle(ctx context.Context, fr *frame.Frame, event partybus.Event, wg *sync.WaitGroup) error {
|
|
|
|
switch event.Type {
|
2020-08-03 20:03:47 +00:00
|
|
|
case stereoscopeEvent.PullDockerImage:
|
|
|
|
return PullDockerImageHandler(ctx, fr, event, wg)
|
|
|
|
|
2020-07-30 19:16:58 +00:00
|
|
|
case stereoscopeEvent.ReadImage:
|
|
|
|
return ReadImageHandler(ctx, fr, event, wg)
|
|
|
|
|
|
|
|
case stereoscopeEvent.FetchImage:
|
|
|
|
return FetchImageHandler(ctx, fr, event, wg)
|
|
|
|
|
2021-03-18 12:57:18 +00:00
|
|
|
case syftEvent.PackageCatalogerStarted:
|
|
|
|
return PackageCatalogerStartedHandler(ctx, fr, event, wg)
|
2020-12-10 03:20:53 +00:00
|
|
|
|
2021-04-01 21:34:15 +00:00
|
|
|
case syftEvent.SecretsCatalogerStarted:
|
|
|
|
return SecretsCatalogerStartedHandler(ctx, fr, event, wg)
|
|
|
|
|
|
|
|
case syftEvent.FileDigestsCatalogerStarted:
|
|
|
|
return FileDigestsCatalogerStartedHandler(ctx, fr, event, wg)
|
|
|
|
|
|
|
|
case syftEvent.FileMetadataCatalogerStarted:
|
|
|
|
return FileMetadataCatalogerStartedHandler(ctx, fr, event, wg)
|
|
|
|
|
2021-06-29 22:06:47 +00:00
|
|
|
case syftEvent.FileIndexingStarted:
|
|
|
|
return FileIndexingStartedHandler(ctx, fr, event, wg)
|
|
|
|
|
2020-12-10 03:20:53 +00:00
|
|
|
case syftEvent.ImportStarted:
|
|
|
|
return ImportStartedHandler(ctx, fr, event, wg)
|
2023-01-12 17:22:05 +00:00
|
|
|
|
|
|
|
case syftEvent.AttestationStarted:
|
|
|
|
return AttestationStartedHandler(ctx, fr, event, wg)
|
2023-04-14 19:13:29 +00:00
|
|
|
|
|
|
|
case syftEvent.CatalogerTaskStarted:
|
|
|
|
return CatalogerTaskStartedHandler(ctx, fr, event, wg)
|
2020-07-30 19:16:58 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|