Capstone/ui/db/models/audit.go

72 lines
2.1 KiB
Go
Raw Normal View History

2023-11-16 20:15:44 -05:00
package models
import (
"time"
"go.mongodb.org/mongo-driver/bson/primitive"
)
2023-11-16 20:21:40 -05:00
const (
EVENT_RECIEVED_TYPE = "audit_event_recieved"
ACTION_TAKEN_TYPE = "audit_action_taken"
)
2023-11-16 20:15:44 -05:00
2023-11-16 20:21:40 -05:00
// Event Recieved
2023-11-16 20:15:44 -05:00
type EventRecieved struct {
*CommonFields `bson:"obj_info"`
Id primitive.ObjectID `bson:"_id,omitempty"`
2023-11-16 20:43:34 -05:00
UserId primitive.ObjectID `bson:"user_id,omitempty"` //what user is this associated too
2023-11-16 20:21:40 -05:00
VendorName string `bson:"vendor_name,omitempty"` //Vendor name of who sent us the event
2023-11-24 02:00:28 -05:00
VendorId string `bson:"vendor_id,omitempty"`
Type string `bson:"type,omitempty"` //type of event
2023-11-16 20:15:44 -05:00
}
func (obj *EventRecieved) MongoId() primitive.ObjectID {
if obj.Id.IsZero() {
now := time.Now()
obj.Id = primitive.NewObjectIDFromTimestamp(now)
}
return obj.Id
}
func (obj *EventRecieved) UpdateObjectInfo() {
now := time.Now()
if obj.CommonFields == nil {
obj.CommonFields = new(CommonFields)
2023-11-24 02:00:28 -05:00
obj.EntityType = ACTION_TAKEN_TYPE
2023-11-16 20:15:44 -05:00
obj.CreatedAt = now
}
obj.UpdatedAt = now
}
2023-11-16 20:21:40 -05:00
// Action Taken
type ActionTaken struct {
*CommonFields `bson:"obj_info"`
2023-11-23 13:22:16 -05:00
Id primitive.ObjectID `bson:"_id,omitempty"`
UserId primitive.ObjectID `bson:"user_id,omitempty"` //what user is this associated too
TriggeringEvent primitive.ObjectID `bson:"triggering_event,omitempty"` //what triggered this action to be taken
Result string `bson:"result,omitempty"` //list of entities effected or created from action
2023-11-24 02:00:28 -05:00
CorrelationId string `bson:"correlation_id,omitempty"` //list of entities effected or created from action
2023-11-23 13:22:16 -05:00
VendorName string `bson:"vendor_name,omitempty"` //Vendor name that the action was taken against
2023-11-16 20:21:40 -05:00
}
func (obj *ActionTaken) MongoId() primitive.ObjectID {
if obj.Id.IsZero() {
now := time.Now()
obj.Id = primitive.NewObjectIDFromTimestamp(now)
}
return obj.Id
}
func (obj *ActionTaken) UpdateObjectInfo() {
now := time.Now()
if obj.CommonFields == nil {
obj.CommonFields = new(CommonFields)
obj.EntityType = EVENT_RECIEVED_TYPE
obj.CreatedAt = now
}
obj.UpdatedAt = now
}