legacy

package
v0.0.0-...-5cf3e1d Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AllowedEventTypeVersionChars = `[a-zA-Z0-9]+`
	AllowedEventIDChars          = `^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$`
)

Allowed patterns for the Event components.

View Source
const (
	ErrorMessageBadPayload          = "Bad payload syntax"
	ErrorMessageRequestBodyTooLarge = "Request body too large"
	ErrorMessageMissingField        = "Missing field"
	ErrorMessageInvalidField        = "Invalid field"
)

Error messages.

View Source
const (
	ErrorTypeBadPayload          = "bad_payload_syntax"
	ErrorTypeRequestBodyTooLarge = "request_body_too_large"
	ErrorTypeMissingField        = "missing_field"
	ErrorTypeValidationViolation = "validation_violation"
	ErrorTypeInvalidField        = "invalid_field"
)

Error type definitions.

View Source
const (
	FieldEventID          = "event-id"
	FieldEventTime        = "event-time"
	FieldEventType        = "event-type"
	FieldEventTypeVersion = "event-type-version"
	FieldData             = "data"
)

Field definitions.

Variables

This section is empty.

Functions

func CreateInvalidFieldError

func CreateInvalidFieldError(field any) *api.PublishEventResponses

CreateInvalidFieldError creates an error for an invalid field.

func CreateMissingFieldError

func CreateMissingFieldError(field any) *api.PublishEventResponses

CreateMissingFieldError creates an error for a missing field.

func ErrorResponse

func ErrorResponse(status int, err error) *api.PublishEventResponses

ErrorResponse returns an error of type PublishEventResponses with the given status and error.

func ErrorResponseBadRequest

func ErrorResponseBadRequest(moreInfo string) *api.PublishEventResponses

ErrorResponseBadRequest returns an error of type PublishEventResponses with BadRequest status code.

func ErrorResponseMissingFieldData

func ErrorResponseMissingFieldData() *api.PublishEventResponses

ErrorResponseMissingFieldData returns an error of type PublishEventResponses for missing Data field.

func ErrorResponseMissingFieldEventTime

func ErrorResponseMissingFieldEventTime() *api.PublishEventResponses

ErrorResponseMissingFieldEventTime returns an error of type PublishEventResponses for missing EventTime field.

func ErrorResponseMissingFieldEventType

func ErrorResponseMissingFieldEventType() *api.PublishEventResponses

ErrorResponseMissingFieldEventType returns an error of type PublishEventResponses for missing EventType field.

func ErrorResponseMissingFieldEventTypeVersion

func ErrorResponseMissingFieldEventTypeVersion() *api.PublishEventResponses

ErrorResponseMissingFieldEventTypeVersion returns an error of type PublishEventResponses for missing EventTypeVersion field.

func ErrorResponseRequestBodyTooLarge

func ErrorResponseRequestBodyTooLarge(moreInfo string) *api.PublishEventResponses

ErrorResponseRequestBodyTooLarge returns an error of type PublishEventResponses with BadRequest status code.

func ErrorResponseWrongEventID

func ErrorResponseWrongEventID() *api.PublishEventResponses

ErrorResponseWrongEventID returns an error of type PublishEventResponses for wrong EventID field.

func ErrorResponseWrongEventTime

func ErrorResponseWrongEventTime() *api.PublishEventResponses

ErrorResponseWrongEventTime returns an error of type PublishEventResponses for wrong EventTime field.

func ErrorResponseWrongEventTypeVersion

func ErrorResponseWrongEventTypeVersion() *api.PublishEventResponses

ErrorResponseWrongEventTypeVersion returns an error of type PublishEventResponses for wrong EventTypeVersion field.

func ParseApplicationNameFromPath

func ParseApplicationNameFromPath(path string) string

ParseApplicationNameFromPath returns application name from the URL. The format of the URL is: /:application-name/v1/... returns empty string if application-name cannot be found.

func WriteJSONResponse

func WriteJSONResponse(w http.ResponseWriter, resp *api.PublishEventResponses)

WriteJSONResponse writes a JSON response.

Types

type HTTPErrorResponse

type HTTPErrorResponse struct {
	Code  int    `json:"code"`
	Error string `json:"error"`
}

An HTTPErrorResponse represents an error with a status code and an error message.

type RequestToCETransformer

type RequestToCETransformer interface {
	ExtractPublishRequestData(*http.Request) (*apiv1.PublishRequestData, *apiv1.PublishEventResponses, error)
	TransformPublishRequestToCloudEvent(*apiv1.PublishRequestData) (*cev2.Event, error)
	WriteLegacyRequestsToCE(http.ResponseWriter, *apiv1.PublishRequestData) (*cev2.Event, string)
	WriteCEResponseAsLegacyResponse(http.ResponseWriter, int, *cev2.Event, string)
}

type Transformer

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

func NewTransformer

func NewTransformer(bebNamespace string, eventTypePrefix string, applicationLister *application.Lister) *Transformer

func (*Transformer) ExtractPublishRequestData

func (t *Transformer) ExtractPublishRequestData(request *http.Request) (*apiv1.PublishRequestData, *apiv1.PublishEventResponses, error)

ExtractPublishRequestData extracts the data for publishing event from the given legacy event request.

func (*Transformer) TransformPublishRequestToCloudEvent

func (t *Transformer) TransformPublishRequestToCloudEvent(publishRequestData *apiv1.PublishRequestData) (*cev2.Event, error)

TransformPublishRequestToCloudEvent converts the given publish request to a CloudEvent with raw values.

func (*Transformer) WriteCEResponseAsLegacyResponse

func (t *Transformer) WriteCEResponseAsLegacyResponse(writer http.ResponseWriter, statusCode int, event *cev2.Event, msg string)

func (*Transformer) WriteLegacyRequestsToCE

func (t *Transformer) WriteLegacyRequestsToCE(writer http.ResponseWriter, publishData *apiv1.PublishRequestData) (*cev2.Event, string)

WriteLegacyRequestsToCE transforms the legacy event to cloudevent from the given request. It also returns the original event-type without cleanup as the second return type.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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