Documentation ¶
Index ¶
- Constants
- func CreateInvalidFieldError(field any) *api.PublishEventResponses
- func CreateMissingFieldError(field any) *api.PublishEventResponses
- func ErrorResponse(status int, err error) *api.PublishEventResponses
- func ErrorResponseBadRequest(moreInfo string) *api.PublishEventResponses
- func ErrorResponseMissingFieldData() *api.PublishEventResponses
- func ErrorResponseMissingFieldEventTime() *api.PublishEventResponses
- func ErrorResponseMissingFieldEventType() *api.PublishEventResponses
- func ErrorResponseMissingFieldEventTypeVersion() *api.PublishEventResponses
- func ErrorResponseRequestBodyTooLarge(moreInfo string) *api.PublishEventResponses
- func ErrorResponseWrongEventID() *api.PublishEventResponses
- func ErrorResponseWrongEventTime() *api.PublishEventResponses
- func ErrorResponseWrongEventTypeVersion() *api.PublishEventResponses
- func ParseApplicationNameFromPath(path string) string
- func WriteJSONResponse(w http.ResponseWriter, resp *api.PublishEventResponses)
- type HTTPErrorResponse
- type RequestToCETransformer
- type Transformer
- func (t *Transformer) ExtractPublishRequestData(request *http.Request) (*apiv1.PublishRequestData, *apiv1.PublishEventResponses, error)
- func (t *Transformer) TransformPublishRequestToCloudEvent(publishRequestData *apiv1.PublishRequestData) (*cev2.Event, error)
- func (t *Transformer) WriteCEResponseAsLegacyResponse(writer http.ResponseWriter, statusCode int, event *cev2.Event, msg string)
- func (t *Transformer) WriteLegacyRequestsToCE(writer http.ResponseWriter, publishData *apiv1.PublishRequestData) (*cev2.Event, string)
Constants ¶
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.
const ( ErrorMessageBadPayload = "Bad payload syntax" ErrorMessageRequestBodyTooLarge = "Request body too large" ErrorMessageMissingField = "Missing field" ErrorMessageInvalidField = "Invalid field" )
Error messages.
const ( ErrorTypeBadPayload = "bad_payload_syntax" ErrorTypeRequestBodyTooLarge = "request_body_too_large" ErrorTypeMissingField = "missing_field" ErrorTypeValidationViolation = "validation_violation" ErrorTypeInvalidField = "invalid_field" )
Error type definitions.
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 ¶
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 ¶
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.