open-vault/sdk/logical/events.go
Christopher Swenson 404d7a57bb
events: WS protobuf messages should be binary (#19232)
The [WebSockets spec](https://www.rfc-editor.org/rfc/rfc6455) states
that text messages must be valid UTF-8 encoded strings, which protobuf
messages virtually never are. This now correctly sends the protobuf events
as binary messages.

We change the format to correspond to CloudEvents, as originally intended,
and remove a redundant timestamp and newline.

We also bump the eventlogger to fix a race condition that this code triggers.
2023-02-17 11:38:03 -08:00

32 lines
659 B
Go

package logical
import (
"context"
"github.com/hashicorp/go-uuid"
)
// ID is an alias to GetId() for CloudEvents compatibility.
func (x *EventReceived) ID() string {
return x.Event.GetId()
}
// NewEvent returns an event with a new, random EID.
func NewEvent() (*EventData, error) {
id, err := uuid.GenerateUUID()
if err != nil {
return nil, err
}
return &EventData{
Id: id,
}, nil
}
// EventType represents a topic, and is a wrapper around eventlogger.EventType.
type EventType string
// EventSender sends events to the common event bus.
type EventSender interface {
Send(ctx context.Context, eventType EventType, event *EventData) error
}