Skip to content

Commit

Permalink
chore: add event validation methods (#4249)
Browse files Browse the repository at this point in the history
  • Loading branch information
jvmakine authored Jan 30, 2025
1 parent 6a54331 commit 438fee6
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
3 changes: 3 additions & 0 deletions backend/schemaservice/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
41 changes: 41 additions & 0 deletions common/schema/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
//protobuf:export
type Event interface {
event()
Validate() error
}

// deployment events
Expand All @@ -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"`
Expand All @@ -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"`
Expand All @@ -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"`
Expand All @@ -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"`
Expand All @@ -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"`
Expand All @@ -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"`
Expand All @@ -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"`
Expand All @@ -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"`
Expand All @@ -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
}

0 comments on commit 438fee6

Please sign in to comment.