event

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2021 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrVaultFilenameEmpty = errors.New("vault filename required but was empty")

ErrVaultFilenameEmpty is an error returned when trying to obtain a PSK for an empty file name

Functions

func Consume added in v0.8.0

func Consume(ctx context.Context, cg kafka.IConsumerGroup, handler Handler, numWorkers int)

Consume converts messages to event instances, and pass the event to the provided handler.

Types

type Handler

type Handler interface {
	Handle(ctx context.Context, ImageUploaded *ImageUploaded) error
}

Handler represents a handler for processing a single event.

type ImageAPIClient

type ImageAPIClient interface {
	Checker(ctx context.Context, state *healthcheck.CheckState) error
	GetImage(ctx context.Context, userAuthToken, serviceAuthToken, collectionID, imageID string) (image.Image, error)
	PutImage(ctx context.Context, userAuthToken, serviceAuthToken, collectionID, imageID string, data image.Image) (image.Image, error)
	PostDownloadVariant(ctx context.Context, userAuthToken, serviceAuthToken, collectionID, imageID string, data image.NewImageDownload) (image.ImageDownload, error)
	PutDownloadVariant(ctx context.Context, userAuthToken, serviceAuthToken, collectionID, imageID, variant string, data image.ImageDownload) (image.ImageDownload, error)
}

ImageAPIClient defines the required methods from image API client

type ImageUploaded

type ImageUploaded struct {
	Path     string `avro:"path"`
	ImageID  string `avro:"image_id"`
	Filename string `avro:"filename"`
}

ImageUploaded provides an avro structure for an image uploaded event

type ImageUploadedHandler

type ImageUploadedHandler struct {
	AuthToken          string
	S3Upload           S3Reader
	S3Private          S3Writer
	VaultCli           VaultClient
	VaultPath          string
	ImageCli           ImageAPIClient
	DownloadServiceURL string
}

ImageUploadedHandler ...

func (*ImageUploadedHandler) Handle

func (h *ImageUploadedHandler) Handle(ctx context.Context, event *ImageUploaded) (err error)

Handle takes a single event. It reads the PSK from Vault, uses it to decrypt the encrypted file from the uploaded S3 bucket, and writes it to the private bucket with a new vault psk for encryption. It also calls the API to create a new download variant and to update it after the variant has been imported.

type S3Reader

type S3Reader interface {
	Checker(ctx context.Context, state *healthcheck.CheckState) error
	Session() *session.Session
	BucketName() string
	Get(key string) (io.ReadCloser, *int64, error)
	GetWithPSK(key string, psk []byte) (io.ReadCloser, *int64, error)
}

S3Reader defines the required methods from dp-s3 to read data to an AWS S3 Bucket

type S3Writer

type S3Writer interface {
	Checker(ctx context.Context, state *healthcheck.CheckState) error
	Session() *session.Session
	BucketName() string
	Upload(input *s3manager.UploadInput, options ...func(*s3manager.Uploader)) (*s3manager.UploadOutput, error)
	UploadWithPSK(input *s3manager.UploadInput, psk []byte) (*s3manager.UploadOutput, error)
}

S3Writer defines the required methods from dp-s3 to interact with a particular bucket of AWS S3

type VaultClient

type VaultClient interface {
	ReadKey(path, key string) (string, error)
	WriteKey(path, key, value string) error
	Checker(ctx context.Context, state *healthcheck.CheckState) error
}

VaultClient defines the required methods from dp-vault client

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳