♻️ Refactored event audit system
This commit is contained in:
parent
35e5eadb05
commit
32e91e2601
@ -3,13 +3,14 @@ package authkit
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"git.solsynth.dev/hypernet/nexus/pkg/nex"
|
||||
"git.solsynth.dev/hypernet/nexus/pkg/nex/sec"
|
||||
"git.solsynth.dev/hypernet/passport/pkg/proto"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
func AddEvent(nx *nex.Conn, userId uint, action, target, ip, ua string) error {
|
||||
func AddEvent(nx *nex.Conn, userId uint, action string, meta map[string]any, ip, ua string) error {
|
||||
conn, err := nx.GetClientGrpcConn(nex.ServiceTypeAuth)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get auth service client: %v", err)
|
||||
@ -17,14 +18,14 @@ func AddEvent(nx *nex.Conn, userId uint, action, target, ip, ua string) error {
|
||||
_, err = proto.NewAuditServiceClient(conn).RecordEvent(context.Background(), &proto.RecordEventRequest{
|
||||
UserId: uint64(userId),
|
||||
Action: action,
|
||||
Target: target,
|
||||
Metadata: nex.EncodeMap(meta),
|
||||
Ip: ip,
|
||||
UserAgent: ua,
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
func AddEventExt(nx *nex.Conn, action, target string, c *fiber.Ctx) error {
|
||||
func AddEventExt(nx *nex.Conn, action string, meta map[string]any, c *fiber.Ctx) error {
|
||||
user, ok := c.Locals("nex_user").(*sec.UserInfo)
|
||||
if !ok {
|
||||
return fmt.Errorf("failed to get user info, make sure you call this method behind the ContextMiddleware")
|
||||
@ -37,7 +38,7 @@ func AddEventExt(nx *nex.Conn, action, target string, c *fiber.Ctx) error {
|
||||
_, err = proto.NewAuditServiceClient(conn).RecordEvent(context.Background(), &proto.RecordEventRequest{
|
||||
UserId: uint64(user.ID),
|
||||
Action: action,
|
||||
Target: target,
|
||||
Metadata: nex.EncodeMap(meta),
|
||||
Ip: c.IP(),
|
||||
UserAgent: c.Get(fiber.HeaderUserAgent),
|
||||
})
|
||||
|
@ -1,13 +1,15 @@
|
||||
package models
|
||||
|
||||
import "gorm.io/datatypes"
|
||||
|
||||
type ActionEvent struct {
|
||||
BaseModel
|
||||
|
||||
Type string `json:"type"`
|
||||
Target string `json:"target"`
|
||||
Location string `json:"location"`
|
||||
IpAddress string `json:"ip_address"`
|
||||
UserAgent string `json:"user_agent"`
|
||||
Type string `json:"type"`
|
||||
Metadata datatypes.JSONMap `json:"metadata"`
|
||||
Location string `json:"location"`
|
||||
IpAddress string `json:"ip_address"`
|
||||
UserAgent string `json:"user_agent"`
|
||||
|
||||
Account Account `json:"account"`
|
||||
AccountID uint `json:"account_id"`
|
||||
|
@ -2,6 +2,8 @@ package grpc
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.solsynth.dev/hypernet/nexus/pkg/nex"
|
||||
"git.solsynth.dev/hypernet/passport/pkg/internal/services"
|
||||
"git.solsynth.dev/hypernet/passport/pkg/proto"
|
||||
)
|
||||
@ -10,7 +12,7 @@ func (v *App) RecordEvent(ctx context.Context, request *proto.RecordEventRequest
|
||||
services.AddEvent(
|
||||
uint(request.GetUserId()),
|
||||
request.GetAction(),
|
||||
request.GetTarget(),
|
||||
nex.DecodeMap(request.GetMetadata()),
|
||||
request.GetIp(),
|
||||
request.GetUserAgent(),
|
||||
)
|
||||
|
@ -6,14 +6,16 @@ import (
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
var writeEventQueue []models.ActionEvent
|
||||
var writeAuditQueue []models.AuditRecord
|
||||
var (
|
||||
writeEventQueue []models.ActionEvent
|
||||
writeAuditQueue []models.AuditRecord
|
||||
)
|
||||
|
||||
// AddEvent to keep operation logs by user themselves clear to query
|
||||
func AddEvent(user uint, event, target, ip, ua string) {
|
||||
func AddEvent(user uint, event string, meta map[string]any, ip, ua string) {
|
||||
writeEventQueue = append(writeEventQueue, models.ActionEvent{
|
||||
Type: event,
|
||||
Target: target,
|
||||
Metadata: meta,
|
||||
IpAddress: ip,
|
||||
UserAgent: ua,
|
||||
AccountID: user,
|
||||
|
@ -170,7 +170,7 @@ func updateUserinfo(c *fiber.Ctx) error {
|
||||
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
||||
}
|
||||
|
||||
services.AddEvent(user.ID, "profile.edit", strconv.Itoa(int(user.ID)), c.IP(), c.Get(fiber.HeaderUserAgent))
|
||||
services.AddEvent(user.ID, "profile.edit", nil, c.IP(), c.Get(fiber.HeaderUserAgent))
|
||||
services.InvalidAuthCacheWithUser(account.ID)
|
||||
|
||||
return c.SendStatus(fiber.StatusOK)
|
||||
@ -195,7 +195,7 @@ func updateAccountLanguage(c *fiber.Ctx) error {
|
||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||
}
|
||||
|
||||
services.AddEvent(user.ID, "profile.edit.language", strconv.Itoa(int(user.ID)), c.IP(), c.Get(fiber.HeaderUserAgent))
|
||||
services.AddEvent(user.ID, "profile.edit.language", nil, c.IP(), c.Get(fiber.HeaderUserAgent))
|
||||
services.InvalidAuthCacheWithUser(user.ID)
|
||||
|
||||
user.Language = data.Language
|
||||
|
@ -1,8 +1,6 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"git.solsynth.dev/hypernet/paperclip/pkg/filekit"
|
||||
"git.solsynth.dev/hypernet/paperclip/pkg/proto"
|
||||
"git.solsynth.dev/hypernet/passport/pkg/authkit/models"
|
||||
@ -33,7 +31,7 @@ func setAvatar(c *fiber.Ctx) error {
|
||||
if err := database.C.Save(&user).Error; err != nil {
|
||||
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
||||
} else {
|
||||
services.AddEvent(user.ID, "profile.edit.avatar", strconv.Itoa(int(user.ID)), c.IP(), c.Get(fiber.HeaderUserAgent))
|
||||
services.AddEvent(user.ID, "profile.edit.avatar", nil, c.IP(), c.Get(fiber.HeaderUserAgent))
|
||||
services.InvalidAuthCacheWithUser(user.ID)
|
||||
}
|
||||
|
||||
@ -71,7 +69,7 @@ func setBanner(c *fiber.Ctx) error {
|
||||
if err := database.C.Save(&user).Error; err != nil {
|
||||
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
||||
} else {
|
||||
services.AddEvent(user.ID, "profile.edit.banner", strconv.Itoa(int(user.ID)), c.IP(), c.Get(fiber.HeaderUserAgent))
|
||||
services.AddEvent(user.ID, "profile.edit.banner", nil, c.IP(), c.Get(fiber.HeaderUserAgent))
|
||||
services.InvalidAuthCacheWithUser(user.ID)
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,6 @@ import (
|
||||
"git.solsynth.dev/hypernet/passport/pkg/internal/services"
|
||||
"git.solsynth.dev/hypernet/passport/pkg/internal/web/exts"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func listCheckInRecord(c *fiber.Ctx) error {
|
||||
@ -99,7 +98,9 @@ func doCheckIn(c *fiber.Ctx) error {
|
||||
if record, err := services.CheckIn(user); err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||
} else {
|
||||
services.AddEvent(user.ID, "checkIn", strconv.Itoa(int(record.ID)), c.IP(), c.Get(fiber.HeaderUserAgent))
|
||||
services.AddEvent(user.ID, "checkIn", map[string]any{
|
||||
"check_in_record": record,
|
||||
}, c.IP(), c.Get(fiber.HeaderUserAgent))
|
||||
return c.JSON(record)
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"git.solsynth.dev/hypernet/passport/pkg/authkit/models"
|
||||
@ -87,7 +86,9 @@ func markNotificationRead(c *fiber.Ctx) error {
|
||||
if err := database.C.Save(¬ify).Error; err != nil {
|
||||
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
||||
} else {
|
||||
services.AddEvent(user.ID, "notifications.mark.read", strconv.Itoa(int(notify.ID)), c.IP(), c.Get(fiber.HeaderUserAgent))
|
||||
services.AddEvent(user.ID, "notifications.mark.read", map[string]any{
|
||||
"notification_id": notify.ID,
|
||||
}, c.IP(), c.Get(fiber.HeaderUserAgent))
|
||||
return c.SendStatus(fiber.StatusOK)
|
||||
}
|
||||
}
|
||||
@ -111,7 +112,9 @@ func markNotificationReadBatch(c *fiber.Ctx) error {
|
||||
Updates(&models.Notification{ReadAt: lo.ToPtr(time.Now())}).Error; err != nil {
|
||||
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
||||
} else {
|
||||
services.AddEvent(user.ID, "notifications.markBatch.read", strconv.Itoa(int(user.ID)), c.IP(), c.Get(fiber.HeaderUserAgent))
|
||||
services.AddEvent(user.ID, "notifications.markBatch.read", map[string]any{
|
||||
"notification_id": data.MessageIDs,
|
||||
}, c.IP(), c.Get(fiber.HeaderUserAgent))
|
||||
return c.SendStatus(fiber.StatusOK)
|
||||
}
|
||||
}
|
||||
@ -127,7 +130,9 @@ func markNotificationAllRead(c *fiber.Ctx) error {
|
||||
Updates(&models.Notification{ReadAt: lo.ToPtr(time.Now())}); tx.Error != nil {
|
||||
return fiber.NewError(fiber.StatusInternalServerError, tx.Error.Error())
|
||||
} else {
|
||||
services.AddEvent(user.ID, "notifications.markAll.read", strconv.Itoa(int(user.ID)), c.IP(), c.Get(fiber.HeaderUserAgent))
|
||||
services.AddEvent(user.ID, "notifications.markAll.read", map[string]any{
|
||||
"count": tx.RowsAffected,
|
||||
}, c.IP(), c.Get(fiber.HeaderUserAgent))
|
||||
return c.JSON(fiber.Map{
|
||||
"count": tx.RowsAffected,
|
||||
})
|
||||
@ -186,7 +191,9 @@ func addNotifySubscriber(c *fiber.Ctx) error {
|
||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||
}
|
||||
|
||||
services.AddEvent(user.ID, "notifications.subscribe.push", data.DeviceID, c.IP(), c.Get(fiber.HeaderUserAgent))
|
||||
services.AddEvent(user.ID, "notifications.subscribe.push", map[string]any{
|
||||
"device_id": data.DeviceID,
|
||||
}, c.IP(), c.Get(fiber.HeaderUserAgent))
|
||||
return c.JSON(subscriber)
|
||||
}
|
||||
|
||||
@ -205,6 +212,8 @@ func removeNotifySubscriber(c *fiber.Ctx) error {
|
||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||
}
|
||||
|
||||
services.AddEvent(user.ID, "notifications.unsubscribe.push", device, c.IP(), c.Get(fiber.HeaderUserAgent))
|
||||
services.AddEvent(user.ID, "notifications.unsubscribe.push", map[string]any{
|
||||
"device_id": device,
|
||||
}, c.IP(), c.Get(fiber.HeaderUserAgent))
|
||||
return c.SendStatus(fiber.StatusOK)
|
||||
}
|
||||
|
@ -95,7 +95,9 @@ func authorizeThirdClient(c *fiber.Ctx) error {
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
||||
} else {
|
||||
services.AddEvent(user.ID, "oauth.connect", client.Alias, c.IP(), c.Get(fiber.HeaderUserAgent))
|
||||
services.AddEvent(user.ID, "oauth.connect", map[string]any{
|
||||
"client": client,
|
||||
}, c.IP(), c.Get(fiber.HeaderUserAgent))
|
||||
return c.JSON(fiber.Map{
|
||||
"ticket": ticket,
|
||||
"redirect_uri": redirect,
|
||||
@ -118,7 +120,9 @@ func authorizeThirdClient(c *fiber.Ctx) error {
|
||||
} else if access, refresh, err := services.GetToken(ticket); err != nil {
|
||||
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
||||
} else {
|
||||
services.AddEvent(user.ID, "oauth.connect", client.Alias, c.IP(), c.Get(fiber.HeaderUserAgent))
|
||||
services.AddEvent(user.ID, "oauth.connect", map[string]any{
|
||||
"client": client,
|
||||
}, c.IP(), c.Get(fiber.HeaderUserAgent))
|
||||
return c.JSON(fiber.Map{
|
||||
"access_token": access,
|
||||
"refresh_token": refresh,
|
||||
|
@ -36,7 +36,10 @@ func updateAuthPreference(c *fiber.Ctx) error {
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||
} else {
|
||||
services.AddEvent(user.ID, "preferences.edit", "auth", c.IP(), c.Get(fiber.HeaderUserAgent))
|
||||
services.AddEvent(user.ID, "preferences.edit", map[string]any{
|
||||
"type": "auth",
|
||||
"preferences": data,
|
||||
}, c.IP(), c.Get(fiber.HeaderUserAgent))
|
||||
}
|
||||
|
||||
return c.JSON(cfg.Config.Data())
|
||||
@ -73,7 +76,10 @@ func updateNotificationPreference(c *fiber.Ctx) error {
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||
} else {
|
||||
services.AddEvent(user.ID, "preferences.edit", "notifications", c.IP(), c.Get(fiber.HeaderUserAgent))
|
||||
services.AddEvent(user.ID, "preferences.edit", map[string]any{
|
||||
"type": "notify",
|
||||
"preferences": data,
|
||||
}, c.IP(), c.Get(fiber.HeaderUserAgent))
|
||||
}
|
||||
|
||||
return c.JSON(notification)
|
||||
|
@ -1,8 +1,6 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"git.solsynth.dev/hypernet/passport/pkg/authkit/models"
|
||||
"git.solsynth.dev/hypernet/passport/pkg/internal/database"
|
||||
"git.solsynth.dev/hypernet/passport/pkg/internal/services"
|
||||
@ -88,7 +86,9 @@ func createRealm(c *fiber.Ctx) error {
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||
} else {
|
||||
services.AddEvent(user.ID, "realms.new", strconv.Itoa(int(realm.ID)), c.IP(), c.Get(fiber.HeaderUserAgent))
|
||||
services.AddEvent(user.ID, "realms.new", map[string]any{
|
||||
"realm": realm,
|
||||
}, c.IP(), c.Get(fiber.HeaderUserAgent))
|
||||
}
|
||||
|
||||
return c.JSON(realm)
|
||||
@ -138,7 +138,9 @@ func editRealm(c *fiber.Ctx) error {
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||
} else {
|
||||
services.AddEvent(user.ID, "realms.edit", strconv.Itoa(int(realm.ID)), c.IP(), c.Get(fiber.HeaderUserAgent))
|
||||
services.AddEvent(user.ID, "realms.edit", map[string]any{
|
||||
"realm": realm,
|
||||
}, c.IP(), c.Get(fiber.HeaderUserAgent))
|
||||
}
|
||||
|
||||
return c.JSON(realm)
|
||||
@ -162,7 +164,9 @@ func deleteRealm(c *fiber.Ctx) error {
|
||||
if err := services.DeleteRealm(realm); err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||
} else {
|
||||
services.AddEvent(user.ID, "realms.delete", strconv.Itoa(int(realm.ID)), c.IP(), c.Get(fiber.HeaderUserAgent))
|
||||
services.AddEvent(user.ID, "realms.delete", map[string]any{
|
||||
"realm": realm,
|
||||
}, c.IP(), c.Get(fiber.HeaderUserAgent))
|
||||
}
|
||||
|
||||
return c.SendStatus(fiber.StatusOK)
|
||||
|
@ -87,7 +87,9 @@ func editRelationship(c *fiber.Ctx) error {
|
||||
if friendship, err := services.EditRelationship(relationship); err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||
} else {
|
||||
services.AddEvent(user.ID, "relationships.edit", strconv.Itoa(int(relationship.ID)), c.IP(), c.Get(fiber.HeaderUserAgent))
|
||||
services.AddEvent(user.ID, "relationships.edit", map[string]any{
|
||||
"relationship": relationship,
|
||||
}, c.IP(), c.Get(fiber.HeaderUserAgent))
|
||||
return c.JSON(friendship)
|
||||
}
|
||||
}
|
||||
@ -111,7 +113,9 @@ func deleteRelationship(c *fiber.Ctx) error {
|
||||
if err := services.DeleteRelationship(relationship); err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||
} else {
|
||||
services.AddEvent(user.ID, "relationships.delete", strconv.Itoa(int(relationship.ID)), c.IP(), c.Get(fiber.HeaderUserAgent))
|
||||
services.AddEvent(user.ID, "relationships.delete", map[string]any{
|
||||
"relationship": relationship,
|
||||
}, c.IP(), c.Get(fiber.HeaderUserAgent))
|
||||
return c.JSON(relationship)
|
||||
}
|
||||
}
|
||||
@ -149,7 +153,9 @@ func makeFriendship(c *fiber.Ctx) error {
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||
} else {
|
||||
services.AddEvent(user.ID, "relationships.friends.new", strconv.Itoa(int(related.ID)), c.IP(), c.Get(fiber.HeaderUserAgent))
|
||||
services.AddEvent(user.ID, "relationships.friends.new", map[string]any{
|
||||
"related": related,
|
||||
}, c.IP(), c.Get(fiber.HeaderUserAgent))
|
||||
return c.JSON(friend)
|
||||
}
|
||||
}
|
||||
@ -185,7 +191,9 @@ func makeBlockship(c *fiber.Ctx) error {
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||
} else {
|
||||
services.AddEvent(user.ID, "relationships.blocks.new", strconv.Itoa(int(related.ID)), c.IP(), c.Get(fiber.HeaderUserAgent))
|
||||
services.AddEvent(user.ID, "relationships.blocks.new", map[string]any{
|
||||
"related": related,
|
||||
}, c.IP(), c.Get(fiber.HeaderUserAgent))
|
||||
return c.JSON(friend)
|
||||
}
|
||||
}
|
||||
@ -205,7 +213,9 @@ func acceptFriend(c *fiber.Ctx) error {
|
||||
if err := services.HandleFriend(user, related, true); err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||
} else {
|
||||
services.AddEvent(user.ID, "relationships.friends.accept", strconv.Itoa(relatedId), c.IP(), c.Get(fiber.HeaderUserAgent))
|
||||
services.AddEvent(user.ID, "relationships.friends.accept", map[string]any{
|
||||
"related": related,
|
||||
}, c.IP(), c.Get(fiber.HeaderUserAgent))
|
||||
return c.SendStatus(fiber.StatusOK)
|
||||
}
|
||||
}
|
||||
@ -225,7 +235,9 @@ func declineFriend(c *fiber.Ctx) error {
|
||||
if err := services.HandleFriend(user, related, false); err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||
} else {
|
||||
services.AddEvent(user.ID, "relationships.friends.decline", strconv.Itoa(relatedId), c.IP(), c.Get(fiber.HeaderUserAgent))
|
||||
services.AddEvent(user.ID, "relationships.friends.decline", map[string]any{
|
||||
"related": related,
|
||||
}, c.IP(), c.Get(fiber.HeaderUserAgent))
|
||||
return c.SendStatus(fiber.StatusOK)
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"git.solsynth.dev/hypernet/passport/pkg/authkit/models"
|
||||
@ -91,7 +90,9 @@ func setStatus(c *fiber.Ctx) error {
|
||||
if status, err := services.NewStatus(user, status); err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||
} else {
|
||||
services.AddEvent(user.ID, "statuses.set", strconv.Itoa(int(status.ID)), c.IP(), c.Get(fiber.HeaderUserAgent))
|
||||
services.AddEvent(user.ID, "statuses.set", map[string]any{
|
||||
"status": status,
|
||||
}, c.IP(), c.Get(fiber.HeaderUserAgent))
|
||||
return c.JSON(status)
|
||||
}
|
||||
}
|
||||
@ -130,7 +131,9 @@ func editStatus(c *fiber.Ctx) error {
|
||||
if status, err := services.EditStatus(user, status); err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||
} else {
|
||||
services.AddEvent(user.ID, "statuses.edit", strconv.Itoa(int(status.ID)), c.IP(), c.Get(fiber.HeaderUserAgent))
|
||||
services.AddEvent(user.ID, "statuses.edit", map[string]any{
|
||||
"status": status,
|
||||
}, c.IP(), c.Get(fiber.HeaderUserAgent))
|
||||
return c.JSON(status)
|
||||
}
|
||||
}
|
||||
@ -144,7 +147,7 @@ func clearStatus(c *fiber.Ctx) error {
|
||||
if err := services.ClearStatus(user); err != nil {
|
||||
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
||||
} else {
|
||||
services.AddEvent(user.ID, "statuses.clear", strconv.Itoa(int(user.ID)), c.IP(), c.Get(fiber.HeaderUserAgent))
|
||||
services.AddEvent(user.ID, "statuses.clear", nil, c.IP(), c.Get(fiber.HeaderUserAgent))
|
||||
}
|
||||
|
||||
return c.SendStatus(fiber.StatusOK)
|
||||
|
@ -27,7 +27,7 @@ type RecordEventRequest struct {
|
||||
|
||||
UserId uint64 `protobuf:"varint,1,opt,name=user_id,json=userId,proto3" json:"user_id,omitempty"`
|
||||
Action string `protobuf:"bytes,2,opt,name=action,proto3" json:"action,omitempty"`
|
||||
Target string `protobuf:"bytes,3,opt,name=target,proto3" json:"target,omitempty"`
|
||||
Metadata []byte `protobuf:"bytes,3,opt,name=metadata,proto3" json:"metadata,omitempty"`
|
||||
Ip string `protobuf:"bytes,4,opt,name=ip,proto3" json:"ip,omitempty"`
|
||||
UserAgent string `protobuf:"bytes,5,opt,name=user_agent,json=userAgent,proto3" json:"user_agent,omitempty"`
|
||||
}
|
||||
@ -76,11 +76,11 @@ func (x *RecordEventRequest) GetAction() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *RecordEventRequest) GetTarget() string {
|
||||
func (x *RecordEventRequest) GetMetadata() []byte {
|
||||
if x != nil {
|
||||
return x.Target
|
||||
return x.Metadata
|
||||
}
|
||||
return ""
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *RecordEventRequest) GetIp() string {
|
||||
@ -146,26 +146,26 @@ var File_record_proto protoreflect.FileDescriptor
|
||||
|
||||
var file_record_proto_rawDesc = []byte{
|
||||
0x0a, 0x0c, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x05,
|
||||
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x8c, 0x01, 0x0a, 0x12, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64,
|
||||
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x90, 0x01, 0x0a, 0x12, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64,
|
||||
0x45, 0x76, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x17, 0x0a, 0x07,
|
||||
0x75, 0x73, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x06, 0x75,
|
||||
0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x18,
|
||||
0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x16, 0x0a,
|
||||
0x06, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x74,
|
||||
0x61, 0x72, 0x67, 0x65, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x70, 0x18, 0x04, 0x20, 0x01, 0x28,
|
||||
0x09, 0x52, 0x02, 0x69, 0x70, 0x12, 0x1d, 0x0a, 0x0a, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x61, 0x67,
|
||||
0x65, 0x6e, 0x74, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x75, 0x73, 0x65, 0x72, 0x41,
|
||||
0x67, 0x65, 0x6e, 0x74, 0x22, 0x34, 0x0a, 0x13, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x45, 0x76,
|
||||
0x65, 0x6e, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1d, 0x0a, 0x0a, 0x69,
|
||||
0x73, 0x5f, 0x73, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52,
|
||||
0x09, 0x69, 0x73, 0x53, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x32, 0x56, 0x0a, 0x0c, 0x41, 0x75,
|
||||
0x64, 0x69, 0x74, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x46, 0x0a, 0x0b, 0x52, 0x65,
|
||||
0x63, 0x6f, 0x72, 0x64, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x19, 0x2e, 0x70, 0x72, 0x6f, 0x74,
|
||||
0x6f, 0x2e, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x71,
|
||||
0x75, 0x65, 0x73, 0x74, 0x1a, 0x1a, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x52, 0x65, 0x63,
|
||||
0x6f, 0x72, 0x64, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65,
|
||||
0x22, 0x00, 0x42, 0x09, 0x5a, 0x07, 0x2e, 0x3b, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70,
|
||||
0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x1a, 0x0a,
|
||||
0x08, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, 0x52,
|
||||
0x08, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x70, 0x18,
|
||||
0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x70, 0x12, 0x1d, 0x0a, 0x0a, 0x75, 0x73, 0x65,
|
||||
0x72, 0x5f, 0x61, 0x67, 0x65, 0x6e, 0x74, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x75,
|
||||
0x73, 0x65, 0x72, 0x41, 0x67, 0x65, 0x6e, 0x74, 0x22, 0x34, 0x0a, 0x13, 0x52, 0x65, 0x63, 0x6f,
|
||||
0x72, 0x64, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12,
|
||||
0x1d, 0x0a, 0x0a, 0x69, 0x73, 0x5f, 0x73, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x18, 0x01, 0x20,
|
||||
0x01, 0x28, 0x08, 0x52, 0x09, 0x69, 0x73, 0x53, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x32, 0x56,
|
||||
0x0a, 0x0c, 0x41, 0x75, 0x64, 0x69, 0x74, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x46,
|
||||
0x0a, 0x0b, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x19, 0x2e,
|
||||
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x45, 0x76, 0x65, 0x6e,
|
||||
0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1a, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f,
|
||||
0x2e, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x73, 0x70,
|
||||
0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x09, 0x5a, 0x07, 0x2e, 0x3b, 0x70, 0x72, 0x6f, 0x74,
|
||||
0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
}
|
||||
|
||||
var (
|
||||
|
@ -11,7 +11,7 @@ service AuditService {
|
||||
message RecordEventRequest {
|
||||
uint64 user_id = 1;
|
||||
string action = 2;
|
||||
string target = 3;
|
||||
bytes metadata = 3;
|
||||
string ip = 4;
|
||||
string user_agent = 5;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user