tenso

package
v0.0.0-...-bf33661 Latest Latest
Warning

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

Go to latest
Published: May 4, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ValidationHandlerRegistry is a pluggable.Registry for ValidationHandler implementations.
	ValidationHandlerRegistry pluggable.Registry[ValidationHandler]
	// TranslationHandlerRegistry is a pluggable.Registry for TranslationHandler implementations.
	TranslationHandlerRegistry pluggable.Registry[TranslationHandler]
	// DeliveryHandlerRegistry is a pluggable.Registry for DeliveryHandler implementations.
	DeliveryHandlerRegistry pluggable.Registry[DeliveryHandler]
)

Functions

func InitDB

func InitDB(dbURL *url.URL) (*gorp.DbMap, error)

InitDB connects to the Postgres database.

func InitializeSwiftDelivery

func InitializeSwiftDelivery(pc *gophercloud.ProviderClient, eo gophercloud.EndpointOpts, envVarName string) (*schwift.Container, error)

InitializeSwiftDelivery provides the shared Init() behavior for DeliveryHandler implementations that deliver to Swift. The target container name must be provided by the user in the environment variable with the given name.

func IsWellformedPayloadType

func IsWellformedPayloadType(val string) bool

func SourcePayloadTypeOf

func SourcePayloadTypeOf(h TranslationHandler) string

SourcePayloadTypeOf extracts the source payload type from h.PluginTypeID().

func TargetPayloadTypeOf

func TargetPayloadTypeOf(h TranslationHandler) string

TargetPayloadTypeOf extracts the source payload type from h.PluginTypeID().

Types

type Configuration

type Configuration struct {
	DatabaseURL   *url.URL
	EnabledRoutes []Route
}

Configuration contains all configuration values that we collect from the environment.

func ParseConfiguration

ParseConfiguration obtains a tenso.Configuration instance from the corresponding environment variables. Aborts on error.

type DeliveryHandler

type DeliveryHandler interface {
	pluggable.Plugin
	// Init will be called at least once during startup if this DeliveryHandler
	// is enabled in the configuration.
	//
	// A (ProviderClient, EndpointOpts) pair is provided for handlers that need to
	// talk to OpenStack. During unit tests, (nil, nil) will be provided instead.
	Init(pc *gophercloud.ProviderClient, eo gophercloud.EndpointOpts) error

	// The `routingInfo` argument contains the metadata that was supplied in the
	// `X-Tenso-Routing-Info` header when posting the original event.
	DeliverPayload(ctx context.Context, payload []byte, routingInfo map[string]string) (*DeliveryLog, error)
}

DeliveryHandler is an object that can deliver payloads of one specific payload type to a target in some way. The PluginTypeID must be equal to the payload type.

type DeliveryLog

type DeliveryLog struct {
	Message string
}

DeliveryLog can be returned by DeliverPayload() to produce additional log messages, e.g. to report the ID of an object that was created in the target system.

type Event

type Event struct {
	ID              int64     `db:"id"`
	CreatorID       int64     `db:"creator_id"` // ID into the `users` table
	CreatedAt       time.Time `db:"created_at"`
	PayloadType     string    `db:"payload_type"`
	Payload         string    `db:"payload"`
	Description     string    `db:"description"`       // a short summary that appears in log messages
	RoutingInfoJSON string    `db:"routing_info_json"` // from the X-Tenso-Routing-Info header
}

Event contains a record from the `events` table.

type PayloadInfo

type PayloadInfo struct {
	// Description is a short summary of the event with this payload. It is used
	// to identify the event in log messages.
	Description string
}

PayloadInfo contains structured information about a payload. It is returned by ValidationHandler.ValidatePayload().

type PendingDelivery

type PendingDelivery struct {
	EventID     int64  `db:"event_id"`
	PayloadType string `db:"payload_type"`
	// Payload and ConvertedAt are nil when the payload has not been converted from event.Payload yet.
	Payload               *string    `db:"payload"`
	ConvertedAt           *time.Time `db:"converted_at"`
	FailedConversionCount int64      `db:"failed_conversions"`
	NextConversionAt      time.Time  `db:"next_conversion_at"`
	FailedDeliveryCount   int64      `db:"failed_deliveries"`
	NextDeliveryAt        time.Time  `db:"next_delivery_at"`
}

PendingDelivery contains a record from the `pending_deliveries` table.

type Route

type Route struct {
	SourcePayloadType  string
	TargetPayloadType  string
	ValidationHandler  ValidationHandler
	TranslationHandler TranslationHandler
	DeliveryHandler    DeliveryHandler
}

Route describes a complete delivery path for events: An event gets submitted to us with an initial payload type, gets translated into a different payload type, and then the translated payload gets delivered.

func BuildRoutes

func BuildRoutes(routeSpecs []string, pc *gophercloud.ProviderClient, eo gophercloud.EndpointOpts) ([]Route, error)

BuildRoutes is used by ParseConfiguration to process the TENSO_ROUTES env variable. It is an exported function to make it accessible in unit tests.

The `pc` and `eo` args are passed to the handlers' Init() methods verbatim.

type TranslationHandler

type TranslationHandler interface {
	pluggable.Plugin
	// Init will be called at least once during startup if this TranslationHandler
	// is enabled in the configuration.
	//
	// A (ProviderClient, EndpointOpts) pair is provided for handlers that need to
	// talk to OpenStack. During unit tests, (nil, {}) will be provided instead.
	Init(pc *gophercloud.ProviderClient, eo gophercloud.EndpointOpts) error

	TranslatePayload(payload []byte, routingInfo map[string]string) ([]byte, error)
}

TranslationHandler is an object that can translate payloads from one specific payload type into a different payload type. The PluginTypeID must be equal to "$SOURCE_PAYLOAD_TYPE->$TARGET_PAYLOAD_TYPE".

type User

type User struct {
	ID         int64  `db:"id"`
	UUID       string `db:"uuid"`
	Name       string `db:"name"`
	DomainName string `db:"domain_name"`
}

User contains a record from the `users` table.

type ValidationHandler

type ValidationHandler interface {
	pluggable.Plugin
	// Init will be called at least once during startup if this ValidationHandler
	// is enabled in the configuration.
	//
	// A (ProviderClient, EndpointOpts) pair is provided for handlers that need to
	// talk to OpenStack. During unit tests, (nil, nil) will be provided instead.
	Init(pc *gophercloud.ProviderClient, eo gophercloud.EndpointOpts) error

	ValidatePayload(payload []byte) (*PayloadInfo, error)
}

ValidationHandler is an object that validates incoming payloads of a specific payload type. The PluginTypeID must be equal to the payload type.

Jump to

Keyboard shortcuts

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