notifier

package
v4.0.0-rc.10 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2020 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 implemention to invoke.
	Deliverer Deliverer
	// contains filtered or unexported fields
}

Delivery handles the business logic of delivering notifications.

func NewDelivery

func NewDelivery(id int, d Deliverer, interval time.Duration, store Store, distLock distlock.Locker) *Delivery

func (*Delivery) Deliver

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

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 Key

type Key struct {
	ID         uuid.UUID
	Expiration time.Time
	Public     *rsa.PublicKey
}

type KeyStore

type KeyStore interface {
	// Keys returns all stored public keys.
	Keys(ctx context.Context) ([]Key, error)
	// KeyByID returns a public key if exists.
	// Returns clairerror.ErrKeyNotFound if key does not exist.
	KeyByID(ctx context.Context, ID uuid.UUID) (Key, error)
	// PutKey persists a public key with an initial expiration of n + current time.
	//
	// BumpExpiration is expected to be called periodically to keep the public key alive.
	PutKey(ctx context.Context, ID uuid.UUID, key *rsa.PublicKey, n time.Duration) error
	// DeleteKey removes a public key from the keystore.
	//
	// Returns clairerror.ErrKeyNotFound if key does not exist.
	DeleteKey(ctx context.Context, ID uuid.UUID) error
	// BumpExpiration sets the public key's expiration to n +
	// current time.
	BumpExpiration(ctx context.Context, ID uuid.UUID, n time.Duration) error
	// GC performs garbage collection o f expired public certificates.
	// N is the number of records deleted.
	//
	// Implementations are free to define efficient GC procedures.
	// Callers of this method may repeat GC until 0 is returned.
	GC(ctx context.Context) (n int64, err error)
}

KeyStore stores and retrieves RSA public keys in PKIX, ASN.1 DER form

internally x509.ParsePKIXPublicKey is used to parse and return a *rsa.PublicKey to the caller.

type MockKeyStore

type MockKeyStore struct {
	Keys_           func(ctx context.Context) ([]Key, error)
	KeyByID_        func(ctx context.Context, ID uuid.UUID) (Key, error)
	PutKey_         func(ctx context.Context, ID uuid.UUID, key *rsa.PublicKey, n time.Duration) error
	DeleteKey_      func(ctx context.Context, ID uuid.UUID) error
	BumpExpiration_ func(ctx context.Context, ID uuid.UUID, n time.Duration) error
	GC_             func(ctx context.Context) (n int64, err error)
}

MockKeyStore implements a mock KeyStore.

func (*MockKeyStore) BumpExpiration

func (m *MockKeyStore) BumpExpiration(ctx context.Context, ID uuid.UUID, n time.Duration) error

BumpExpiration sets the public key's expiration to (n minutes) + (time of call).

func (*MockKeyStore) DeleteKey

func (m *MockKeyStore) DeleteKey(ctx context.Context, ID uuid.UUID) error

DeleteKey removes a public key from the keystore.

Returns clairerror.ErrKeyNotFound if key does not exist.

func (*MockKeyStore) GC

func (m *MockKeyStore) GC(ctx context.Context) (n int64, err error)

GC performs garbage collection of expired public certificates. N is the number of records deleted.

Implementations are free to define efficient GC procedures. Callers of this method may repeat GC until 0 is returned.

func (*MockKeyStore) KeyByID

func (m *MockKeyStore) KeyByID(ctx context.Context, ID uuid.UUID) (Key, error)

KeyByID returns a public key if exists. Returns clairerror.ErrKeyNotFound if key does not exist.

func (*MockKeyStore) Keys

func (m *MockKeyStore) Keys(ctx context.Context) ([]Key, error)

Keys returns all stored public keys.

func (*MockKeyStore) PutKey

func (m *MockKeyStore) PutKey(ctx context.Context, ID uuid.UUID, key *rsa.PublicKey, n time.Duration) error

PutKey persists a public key with a default expiration of 5 minutes.

A BumpExpiration call is expected to occur sometime before this default expiration.

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
	DeleteNotitfications_ func(ctx context.Context, id uuid.UUID) 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) Created

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

Created returns a slice of notification ids in created status

func (*MockStore) DeleteNotifications

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

DeleteNotifications garbage collects all notifications associated with a notification id.

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.

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) 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
	// DeleteNotifications garbage collects all notifications associated
	// with a notification id.
	//
	// 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.
	DeleteNotifications(ctx context.Context, id uuid.UUID) error
}

Notificationer implements persistence methods for Notification models

type Page

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

Page communicates a bare-minimum paging procotol 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(interval time.Duration, store Store, differ matcher.Differ) *Poller

func (*Poller) Poll

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

Poll is a non blocking call which begins polling the Matcher for UpdateOperations.

Returned channel can be listened to for events.

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 {
	// 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(id int, distLock distlock.Locker, indexer indexer.Service, matcher matcher.Service, store Store) *Processor

func (*Processor) Process

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

Process is an async method which receives new UOs as events, creates notifications, persists these 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 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 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