diff --git a/backend/schemaservice/events.go b/backend/schemaservice/events.go index 3d53c0760f..21b3b47ed6 100644 --- a/backend/schemaservice/events.go +++ b/backend/schemaservice/events.go @@ -14,6 +14,9 @@ import ( // ApplyEvent applies an event to the schema state func (r SchemaState) ApplyEvent(event schema.Event) error { + if err := event.Validate(); err != nil { + return fmt.Errorf("invalid event: %w", err) + } switch e := event.(type) { case *schema.DeploymentCreatedEvent: return handleDeploymentCreatedEvent(r, e) diff --git a/common/schema/events.go b/common/schema/events.go index 8ce55b45db..8b83b864d0 100644 --- a/common/schema/events.go +++ b/common/schema/events.go @@ -14,6 +14,7 @@ import ( //protobuf:export type Event interface { event() + Validate() error } // deployment events @@ -37,6 +38,10 @@ type DeploymentCreatedEvent struct { func (r *DeploymentCreatedEvent) event() {} +func (r *DeploymentCreatedEvent) Validate() error { + return nil +} + //protobuf:2 type DeploymentSchemaUpdatedEvent struct { Key key.Deployment `protobuf:"1"` @@ -45,6 +50,10 @@ type DeploymentSchemaUpdatedEvent struct { func (r *DeploymentSchemaUpdatedEvent) event() {} +func (r *DeploymentSchemaUpdatedEvent) Validate() error { + return nil +} + //protobuf:3 type DeploymentReplicasUpdatedEvent struct { Key key.Deployment `protobuf:"1"` @@ -53,6 +62,10 @@ type DeploymentReplicasUpdatedEvent struct { func (r *DeploymentReplicasUpdatedEvent) event() {} +func (r *DeploymentReplicasUpdatedEvent) Validate() error { + return nil +} + //protobuf:4 type DeploymentActivatedEvent struct { Key key.Deployment `protobuf:"1"` @@ -62,6 +75,10 @@ type DeploymentActivatedEvent struct { func (r *DeploymentActivatedEvent) event() {} +func (r *DeploymentActivatedEvent) Validate() error { + return nil +} + //protobuf:5 type DeploymentDeactivatedEvent struct { Key key.Deployment `protobuf:"1"` @@ -70,6 +87,10 @@ type DeploymentDeactivatedEvent struct { func (r *DeploymentDeactivatedEvent) event() {} +func (r *DeploymentDeactivatedEvent) Validate() error { + return nil +} + //protobuf:6 type VerbRuntimeEvent struct { Module string `protobuf:"1"` @@ -80,6 +101,10 @@ type VerbRuntimeEvent struct { func (e *VerbRuntimeEvent) event() {} +func (e *VerbRuntimeEvent) Validate() error { + return nil +} + //protobuf:7 type TopicRuntimeEvent struct { Module string `protobuf:"1"` @@ -89,6 +114,10 @@ type TopicRuntimeEvent struct { func (e *TopicRuntimeEvent) event() {} +func (e *TopicRuntimeEvent) Validate() error { + return nil +} + //protobuf:8 type DatabaseRuntimeEvent struct { Module string `protobuf:"1"` @@ -98,6 +127,10 @@ type DatabaseRuntimeEvent struct { func (e *DatabaseRuntimeEvent) event() {} +func (e *DatabaseRuntimeEvent) Validate() error { + return nil +} + //protobuf:9 type ModuleRuntimeEvent struct { Module string `protobuf:"1"` @@ -111,9 +144,17 @@ type ModuleRuntimeEvent struct { func (e *ModuleRuntimeEvent) event() {} +func (e *ModuleRuntimeEvent) Validate() error { + return nil +} + //protobuf:10 type ProvisioningCreatedEvent struct { DesiredModule *Module `protobuf:"1"` } func (e *ProvisioningCreatedEvent) event() {} + +func (e *ProvisioningCreatedEvent) Validate() error { + return nil +}