diff --git a/go.mod b/go.mod index 5501a933..70ed3d5a 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index ed3feaf9..0e6608d5 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/models/events/build.go b/models/events/build.go new file mode 100644 index 00000000..b196938d --- /dev/null +++ b/models/events/build.go @@ -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 +} diff --git a/models/events/events.go b/models/events/events.go new file mode 100644 index 00000000..fa53cf91 --- /dev/null +++ b/models/events/events.go @@ -0,0 +1,90 @@ +// Package events provides primitives to interact with the openapi HTTP API. +// +// Code generated by github.com/deepmap/oapi-codegen version v1.13.4 DO NOT EDIT. +package events + +import ( + "time" + + "github.com/gofrs/uuid" +) + +// Defines values for EventSeverity. +const ( + Alert EventSeverity = "alert" + Critical EventSeverity = "critical" + Debug EventSeverity = "debug" + Emergency EventSeverity = "emergency" + Error EventSeverity = "error" + Informational EventSeverity = "informational" + Warning EventSeverity = "warning" +) + +// CreatedAt Timestamp when the resource was created. +type CreatedAt = time.Time + +// DeletedAt Timestamp when the resource was deleted. +type DeletedAt = time.Time + +// Event Defines model for event_trackers +type Event struct { + // ActedUpon UUID of the entity on which the event was performed. + ActedUpon uuid.UUID `db:"acted_upon" json:"acted_upon"` + + // Action Action taken on the resource. + Action string `db:"action" json:"action"` + + // Category Resource name on which the operation is invoked. + Category string `db:"category" json:"category"` + + // CreatedAt Timestamp when the resource was created. + CreatedAt CreatedAt `db:"created_at" json:"created_at"` + + // DeletedAt Timestamp when the resource was deleted. + DeletedAt *DeletedAt `db:"deleted_at" json:"deleted_at,omitempty"` + + // Description A summary/receipt of event that occured. + Description string `db:"description" json:"description"` + ID ID `db:"id" json:"id"` + + // Metadata Contains meaningful information, specific to the type of event. + // Structure of metadata can be different for different events. + Metadata interface{} `db:"metadata" json:"metadata"` + OperationID OperationID `db:"operation_id" json:"operation_id"` + + // Severity A set of seven standard event levels. + Severity EventSeverity `db:"severity" json:"severity"` + SystemID SystemID `db:"system_id" json:"system_id"` + + // UpdatedAt Timestamp when the resource was updated. + UpdatedAt UpdatedAt `db:"updated_at" json:"updated_at"` + UserID *UserID `db:"user_id" json:"user_id,omitempty"` +} + +// EventSeverity A set of seven standard event levels. +type EventSeverity string + +// ID defines model for id. +type ID = uuid.UUID + +// OperationID defines model for operation_id. +type OperationID = uuid.UUID + +// SystemID defines model for system_id. +type SystemID = uuid.UUID + +// Time defines model for time. +type Time = time.Time + +// UpdatedAt Timestamp when the resource was updated. +type UpdatedAt = time.Time + +// UserID defines model for user_uuid. +type UserID = uuid.UUID + +// EventsFilter defines model for eventsFilter. +type EventsFilter struct { + Action []string `json:"action"` + Category []string `json:"category"` + Provider []string `json:"provider"` +} \ No newline at end of file