From 4de0c4c969adb2f86054f1965562400ce56d4330 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Mon, 14 Oct 2024 21:18:29 +0800 Subject: [PATCH] :sparkles: API wrapper of record audit log --- pkg/hyper/audit.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 pkg/hyper/audit.go diff --git a/pkg/hyper/audit.go b/pkg/hyper/audit.go new file mode 100644 index 0000000..3c840f4 --- /dev/null +++ b/pkg/hyper/audit.go @@ -0,0 +1,30 @@ +package hyper + +import ( + "context" + "git.solsynth.dev/hydrogen/dealer/pkg/proto" + "time" +) + +func (v *HyperConn) RecordAuditLog(user uint, action, target, ip, ua string) error { + ctx, cancel := context.WithTimeout(context.Background(), time.Second*10) + defer cancel() + + in, err := v.GetServiceGrpcConn(ServiceTypeAuthProvider) + if err != nil { + return err + } + + _, err = proto.NewEventRecorderClient(in).RecordEvent(ctx, &proto.RecordEventRequest{ + UserId: uint64(user), + Action: action, + Target: target, + Ip: ip, + UserAgent: ua, + }) + if err != nil { + return err + } + + return nil +}