notifier

package
v4.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 3, 2022 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// max number of UOIDs that we will queue in a channel
	MaxChanSize = 1024
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Callback

type Callback struct {
	NotificationID uuid.UUID `json:"notification_id"`
	Callback       url.URL   `json:"callback"`
}

Callback holds the details for clients to call back the Notifier and receive notifications.

func (Callback) MarshalJSON

func (cb Callback) MarshalJSON() ([]byte, error)

func (*Callback) UnmarshalJSON

func (cb *Callback) UnmarshalJSON(b []byte) error

type Deliverer

type Deliverer interface {
	// A unique name for the deliverer implementation
	Name() string
	// Deliver will push the notification ID to subscribed clients.
	//
	// If delivery fails a clairerror.ErrDeliveryFailed error must be returned.
	Deliver(ctx context.Context, nID uuid.UUID) error
}

Deliverer provides the method set for delivering notifications

type Delivery

type Delivery struct {
	// a Deliverer implementation to invoke.
	Deliverer Deliverer
	// contains filtered or unexported fields
}

Delivery handles the business logic of delivering notifications.

func NewDelivery

func NewDelivery(store Store, l Locker, d Deliverer, interval time.Duration) *Delivery

func (*Delivery) Deliver

func (d *Delivery) Deliver(ctx context.Context) error

Deliver begins delivering notifications.

Canceling the ctx will end delivery.

func (*Delivery) RunDelivery

func (d *Delivery) RunDelivery(ctx context.Context) error

RunDelivery determines notifications to deliver and calls the implemented Deliverer to perform the actions.

type DirectDeliverer

type DirectDeliverer interface {
	Notifications(ctx context.Context, n []Notification) error
}

DirectDeliverer implementations are used in coordination with the Deliverer interface.

DirectDeliverer(s) expect this method to be called prior to their Deliverer methods. Implementations must still implement both Deliverer and DirectDeliverer methods for correct use.

Implementations will be provided a list of notifications in which they can directly deliver to subscribed clients.

type Event

type Event struct {
	// contains filtered or unexported fields
}

Event is delivered on the poller's channel when a new UpdateOperation is discovered.

type Locker added in v4.3.0

Locker is any context-based locking API.

type MockStore

type MockStore struct {
	Notifications_         func(ctx context.Context, id uuid.UUID, page *Page) ([]Notification, Page, error)
	PutNotifications_      func(ctx context.Context, opts PutOpts) error
	PutReceipt_            func(ctx context.Context, updater string, r Receipt) error
	CollectNotitfications_ func(ctx context.Context) error
	Receipt_               func(ctx context.Context, id uuid.UUID) (Receipt, error)
	ReceiptByUOID_         func(ctx context.Context, id uuid.UUID) (Receipt, error)
	Created_               func(ctx context.Context) ([]uuid.UUID, error)
	Failed_                func(ctx context.Context) ([]uuid.UUID, error)
	Deleted_               func(ctx context.Context) ([]uuid.UUID, error)
	SetDelivered_          func(ctx context.Context, id uuid.UUID) error
	SetDeliveredFailed_    func(ctx context.Context, id uuid.UUID) error
	SetDeleted_            func(ctx context.Context, id uuid.UUID) error
}

MockStore implements a mock Store.

func (*MockStore) CollectNotifications added in v4.4.0

func (m *MockStore) CollectNotifications(ctx context.Context) error

CollectNotifications garbage collects all notifications.

func (*MockStore) Created

func (m *MockStore) Created(ctx context.Context) ([]uuid.UUID, error)

Created returns a slice of notification ids in created status

func (*MockStore) Deleted

func (m *MockStore) Deleted(ctx context.Context) ([]uuid.UUID, error)

Deleted returns a slice of notification ids in deleted status

func (*MockStore) Failed

func (m *MockStore) Failed(ctx context.Context) ([]uuid.UUID, error)

Failed returns a slice of notification ids in failed status

func (*MockStore) Notifications

func (m *MockStore) Notifications(ctx context.Context, id uuid.UUID, page *Page) ([]Notification, Page, error)

Notifications retrieves the list of notifications associated with a notification id

func (*MockStore) PutNotifications

func (m *MockStore) PutNotifications(ctx context.Context, opts PutOpts) error

PutNotifications persists the provided notifications and associates them with the provided notification id

PutNotifications must update the latest update operation for the provided updater in such a way that UpdateOperation returns the the provided update operation id when queried with the updater name

PutNotifications must create a Receipt with status created status on successful persistence of notifications in such a way that Receipter.Created() returns the persisted notification id.

func (*MockStore) PutReceipt

func (m *MockStore) PutReceipt(ctx context.Context, updater string, r Receipt) error

PutReceipt allows for the caller to directly add a receipt to the store without notifications being created.

After this method returns all methods on the Receipter interface must work accordingly.

func (*MockStore) Receipt

func (m *MockStore) Receipt(ctx context.Context, id uuid.UUID) (Receipt, error)

Receipt returns the Receipt for a given notification id

func (*MockStore) ReceiptByUOID

func (m *MockStore) ReceiptByUOID(ctx context.Context, id uuid.UUID) (Receipt, error)

ReceiptByUOID returns the Receipt for a given UOID

func (*MockStore) SetDeleted

func (m *MockStore) SetDeleted(ctx context.Context, id uuid.UUID) error

SetDeleted marks the provided notification id as deleted

func (*MockStore) SetDelivered

func (m *MockStore) SetDelivered(ctx context.Context, id uuid.UUID) error

SetDelivered marks the provided notification id as delivered

func (*MockStore) SetDeliveryFailed

func (m *MockStore) SetDeliveryFailed(ctx context.Context, id uuid.UUID) error

SetDeliveryFailed marks the provided notification id failed to be delivere

type Notification

type Notification struct {
	ID            uuid.UUID        `json:"id"`
	Manifest      claircore.Digest `json:"manifest"`
	Reason        Reason           `json:"reason"`
	Vulnerability VulnSummary      `json:"vulnerability"`
}

Notification summarizes a change in the vulnerabilities affecting a manifest.

The mentioned Vulnerability will be the most severe vulnerability discovered in an update operation.

Receiving clients are expected to filter notifications by severity in such a way that they receive all vulnerabilities at or above a particular claircore.Severity level.

type NotificationHandle

type NotificationHandle struct {
	ID uuid.UUID `json:"id"`
}

NotificationHandle is a handle a client may use to retrieve a list of associated notification models

type Notificationer

type Notificationer interface {
	// Notifications retrieves the list of notifications associated with a
	// notification id
	//
	// If a Page is provided the returned notifications will be a subset of the total
	// and it's len will be no larger then Page.Size.
	//
	// This method should interpret the page.Next field as the requested page and
	// set the returned page.Next field to the next page to receive or -1 if
	// paging has been exhausted.
	//
	// Page maybe nil to receive all notifications.
	Notifications(ctx context.Context, id uuid.UUID, page *Page) ([]Notification, Page, error)
	// PutNotifications persists the provided notifications and associates
	// them with the provided notification id
	//
	// PutNotifications must update the latest update operation for the provided
	// updater in such a way that UpdateOperation returns the the provided update
	// operation id when queried with the updater name
	//
	// PutNotifications must create a Receipt with status created status on
	// successful persistence of notifications in such a way that Receipter.Created()
	// returns the persisted notification id.
	PutNotifications(ctx context.Context, opts PutOpts) error
	// PutReceipt allows for the caller to directly add a receipt to the store
	// without notifications being created.
	//
	// After this method returns all methods on the Receipter interface must work accordingly.
	PutReceipt(ctx context.Context, updater string, r Receipt) error
	// CollectNotifications garbage collects all notifications.
	//
	// Normally Receipter.SetDeleted will be issues first, however
	// application logic may decide to GC notifications which have not been
	// set deleted after some period of time, thus this condition should not
	// be checked.
	CollectNotifications(ctx context.Context) error
}

Notificationer implements persistence methods for Notification models

type Page

type Page struct {
	// the next id to retrieve
	Next *uuid.UUID `json:"next,omitempty"`
	// the max number of elements returned in a page
	Size int `json:"size"`
}

Page communicates a bare-minimum paging protocol with clients.

type Poller

type Poller struct {
	// contains filtered or unexported fields
}

Poller implements new Update Operation discovery via an event channel.

func NewPoller

func NewPoller(store Store, differ matcher.Differ, interval time.Duration) *Poller

func (*Poller) Poll

func (p *Poller) Poll(ctx context.Context, c chan<- Event) error

Poll begins polling the Matcher for UpdateOperations and producing Events on the supplied channel. This method takes ownership of the channel and is responsible for closing it.

Cancel ctx to stop the poller.

type PollerOpt

type PollerOpt func(*Poller) error

PollerOpt applies a configuration to a Poller

type Processor

type Processor struct {

	// NoSummary controls whether per-manifest vulnerability summarization
	// should happen.
	//
	// The zero value makes the default behavior to do the summary.
	NoSummary bool
	// contains filtered or unexported fields
}

Processor listen for new UOIDs, creates notifications, and persists these notifications for later retrieval.

Processor(s) create atomic boundaries, no two Processor(s) will be creating notifications for the same UOID at once.

func NewProcessor

func NewProcessor(store Store, l Locker, indexer indexer.Service, matcher matcher.Service) *Processor

func (*Processor) Process

func (p *Processor) Process(ctx context.Context, c <-chan Event) error

Process receives new UOs as events, creates and persists notifications, and updates the notifier system with the "latest" seen UOID.

Canceling the ctx will end the processing.

type PutOpts

type PutOpts struct {
	// the updater triggering a notification
	Updater string
	// the update operation id triggering the notification
	UpdateID uuid.UUID
	// the notification id clients will use to retrieve the
	// list of notifications
	NotificationID uuid.UUID
	// a slice of notifications to persist. these notifications
	// will be retrievable via the notification id
	Notifications []Notification
}

PutOpts is provided to Notificationer.Put with fields necessary to persist a notification id

type Reason

type Reason string

Reason indicates the catalyst for a notification.

const (
	Added   Reason = "added"
	Removed Reason = "removed"
	Changed Reason = "changed"
)

type Receipt

type Receipt struct {
	// The update operation associated with this receipt
	UOID uuid.UUID
	// the id a client may use to retrieve a set of notifications
	NotificationID uuid.UUID
	// the current status  of the notification
	Status Status
	// the timestamp of the last status update
	TS time.Time
}

Receipt represents the current status of a notification

type Receipter

type Receipter interface {
	// Receipt returns the Receipt for a given notification id
	Receipt(ctx context.Context, id uuid.UUID) (Receipt, error)
	// ReceiptByUOID returns the Receipt for a given UOID
	ReceiptByUOID(ctx context.Context, id uuid.UUID) (Receipt, error)
	// Created returns a slice of notification ids in created status
	Created(ctx context.Context) ([]uuid.UUID, error)
	// Failed returns a slice of notification ids to in delivery failed status
	Failed(ctx context.Context) ([]uuid.UUID, error)
	// Deleted returns a slice of notification ids in deleted status
	Deleted(ctx context.Context) ([]uuid.UUID, error)
	// SetDelivered marks the provided notification id as delivered
	SetDelivered(ctx context.Context, id uuid.UUID) error
	// SetDeliveryFailed marks the provided notification id failed to be delivered
	SetDeliveryFailed(ctx context.Context, id uuid.UUID) error
	// SetDeleted marks the provided notification id as deleted
	SetDeleted(ctx context.Context, id uuid.UUID) error
}

Receipter implements persistence methods for Receipt models

type Service added in v4.4.0

type Service interface {
	// Retrieves an optional paginated set of notifications given an notification id
	Notifications(ctx context.Context, id uuid.UUID, page *Page) ([]Notification, Page, error)
	// Deletes the provided notification id
	DeleteNotifications(ctx context.Context, id uuid.UUID) error
}

Service is an interface wrapping ClairV4's notifier functionality.

This remains an interface so remote clients may implement as well.

type Status

type Status string

Status defines the possible states of a notification.

const (
	// A notification is created and ready to be delivered to a client
	Created Status = "created"
	// A notification has been successfully delivered to a client
	Delivered Status = "delivered"
	// A notification failed to be delivered
	DeliveryFailed Status = "delivery_failed"
	// The client has read the notification and issued a delete
	Deleted Status = "deleted"
)

type Store

type Store interface {
	Notificationer
	Receipter
}

Store is an aggregate interface implementing all methods necessary for a notifier persistence layer

type VulnSummary

type VulnSummary struct {
	Name           string                  `json:"name"`
	Description    string                  `json:"description"`
	Package        *claircore.Package      `json:"package,omitempty"`
	Distribution   *claircore.Distribution `json:"distribution,omitempty"`
	Repo           *claircore.Repository   `json:"repo,omitempty"`
	Severity       string                  `json:"severity"`
	FixedInVersion string                  `json:"fixed_in_version"`
	Links          string                  `json:"links"`
}

VulnSummary summarizes a vulnerability which triggered a notification

func (*VulnSummary) FromVulnerability

func (vs *VulnSummary) FromVulnerability(v *claircore.Vulnerability)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL