events

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2020 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrEventNotSigned = errors.New("the event is not signed")

ErrEventNotSigned is returned when the event is not signed

View Source
var ErrEventSystemNotConfigured = errors.New("the event system hasn't been configured, please call Configure()")

ErrEventSystemNotConfigured is returned when the event system is used but wasn't configured by calling Configure()

View Source
var ErrInvalidTimestamp = errors.New("event timestamp does not match required pattern (yyyyMMddHHmmssmmm)")

ErrInvalidTimestamp is returned when a timestamp does not match the required pattern

View Source
var ErrMissingEventType = errors.New("unmarshalling error: missing event type")

ErrMissingEventType is given when the event being unmarshalled has no type attribute.

View Source
var NoopJwsVerifier = func(signature []byte, signingTime time.Time, verifier crypto.CertificateVerifier) ([]byte, error) {
	msg, err := jws.Parse(bytes.NewReader(signature))
	if err != nil {
		return nil, err
	}
	return msg.Payload(), nil
}

NoopJwsVerifier is a JwsVerifier that just parses the JWS without verifying the signatures

View Source
var NoopTrustStore = &noopTrustStore{}

NoopTrustStore is a TrustStore that holds no state

Functions

func SuggestEventFileName

func SuggestEventFileName(event Event) string

SuggestEventFileName suggests a file name for a event, when writing that event to disk.

Types

type Event

type Event interface {
	Type() EventType
	IssuedAt() time.Time
	Unmarshal(out interface{}) error
	Marshal() []byte
	Signature() []byte
	Sign(signFn func([]byte) ([]byte, error)) error
}

Event defines an event which can be (un)marshalled.

func CreateEvent

func CreateEvent(eventType EventType, payload interface{}) Event

CreateEvent creates an event of the given type and the provided payload. If the event can't be created, an error is returned.

func EventFromJSON

func EventFromJSON(data []byte) (Event, error)

EventFromJSON unmarshals an event. If the event can't be unmarshalled, an error is returned.

type EventHandler

type EventHandler func(Event) error

EventHandler handles an event of a specific type.

type EventRegistrar

type EventRegistrar func(EventType, EventHandler)

EventRegistrar is a function to register an event

type EventSystem

type EventSystem interface {
	// RegisterEventHandler registers an event handler for the given type, which will be called when the an event of this
	// type is received.
	RegisterEventHandler(eventType EventType, handler EventHandler)
	ProcessEvent(event Event) error
	PublishEvent(event Event) error
	LoadAndApplyEvents() error
	Configure(location string) error
}

EventSystem is meant for registering and handling events.

func NewEventSystem

func NewEventSystem(eventTypes ...EventType) EventSystem

NewEventSystem creates and initializes a new event system.

type EventType

type EventType string

EventType defines a supported type of event, which is used for executing the right handler.

type JwsVerifier

type JwsVerifier func(signature []byte, signingTime time.Time, verifier crypto.CertificateVerifier) ([]byte, error)

JwsVerifier defines a verification delegate for JWS'.

type SignatureDetails

type SignatureDetails struct {
	// Certificate contains the X.509 certificate that signed the event
	Certificate *x509.Certificate
	// Payload contains the event data that is protected by the signature
	Payload []byte
}

SignatureDetails describes the properties of the signature that secures the event

type SignatureValidator

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

SignatureValidator validates event signatures.

func NewSignatureValidator

func NewSignatureValidator(verifier JwsVerifier, trustStore TrustStore) SignatureValidator

NewSignatureValidator creates a new SignatureValidator for the given event types.

func (SignatureValidator) RegisterEventHandlers

func (v SignatureValidator) RegisterEventHandlers(fn EventRegistrar, eventType []EventType)

RegisterEventHandlers registers event handlers which will validate the event signatures.

type TrustStore

type TrustStore interface {
	crypto.CertificateVerifier
	RegisterEventHandlers(func(EventType, EventHandler))
}

type UnmarshalPostProcessor

type UnmarshalPostProcessor interface {
	PostProcessUnmarshal(event Event) error
}

UnmarshalPostProcessor allows to define custom logic that should be executed after unmarshalling

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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