Skip to content

Commit

Permalink
Merge pull request #356 from MUzairS15/events
Browse files Browse the repository at this point in the history
Add constructs for `Meshery Events`.
  • Loading branch information
Mohd Uzair authored Aug 30, 2023
2 parents b4e728e + ebf5cbf commit b9b6cc4
Show file tree
Hide file tree
Showing 4 changed files with 158 additions and 0 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ require (
github.com/go-openapi/jsonreference v0.20.1 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/gobwas/glob v0.2.3 // indirect
github.com/gofrs/uuid v4.4.0+incompatible
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,8 @@ github.com/gofrs/flock v0.8.1 h1:+gYjHKf32LDeiEEFhQaotPbLuUXjY5ZqxKgXy7n59aw=
github.com/gofrs/flock v0.8.1/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14jxHU=
github.com/gofrs/uuid v3.3.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/gofrs/uuid v4.0.0+incompatible h1:1SD/1F5pU8p29ybwgQSwpQk+mwdRrXCYuPhW6m+TnJw=
github.com/gofrs/uuid v4.4.0+incompatible h1:3qXRTX8/NbyulANqlc0lchS1gqAVxRgsuW1YrTJupqA=
github.com/gofrs/uuid v4.4.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/gogo/googleapis v1.2.0/go.mod h1:Njal3psf3qN6dwBtQfUmBZh2ybovJ0tlu3o/AC7HYjU=
github.com/gogo/googleapis v1.4.0 h1:zgVt4UpGxcqVOw97aRGxT4svlcmdK35fynLNctY32zI=
github.com/gogo/googleapis v1.4.0/go.mod h1:5YRNX2z1oM5gXdAkurHa942MDgEJyk02w4OecKY87+c=
Expand Down
65 changes: 65 additions & 0 deletions models/events/build.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package events

import (
"time"

"github.com/gofrs/uuid"
)

type EventBuilder struct {
event Event
}

func NewEvent() *EventBuilder {
operationId, _ := uuid.NewV4()
return &EventBuilder{
event: Event{
CreatedAt: time.Now(),
OperationID: operationId,
},
}
}

func (e *EventBuilder) ActedUpon(resource uuid.UUID) *EventBuilder {
e.event.ActedUpon = resource
return e
}

func (e *EventBuilder) WithDescription(description string) *EventBuilder {
e.event.Description = description
return e
}

func (e *EventBuilder) WithCategory(eventCategory string) *EventBuilder {
e.event.Category = eventCategory
return e
}

func (e *EventBuilder) WithAction(eventAction string) *EventBuilder {
e.event.Action = eventAction
return e
}

func (e *EventBuilder) WithMetadata(metadata interface{}) *EventBuilder {
e.event.Metadata = metadata
return e
}

func (e *EventBuilder) WithSeverity(severity EventSeverity) *EventBuilder {
e.event.Severity = severity
return e
}

func (e *EventBuilder) FromUser(id uuid.UUID) *EventBuilder {
e.event.UserID = &id
return e
}

func (e *EventBuilder) FromSystem(id uuid.UUID) *EventBuilder {
e.event.SystemID = id
return e
}

func (e *EventBuilder) Build() *Event {
return &e.event
}
90 changes: 90 additions & 0 deletions models/events/events.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b9b6cc4

Please sign in to comment.