From 970d4dcfad8dcfb5abd304f4084bc4a531d30738 Mon Sep 17 00:00:00 2001 From: Raja Subramanian Date: Fri, 20 Dec 2024 10:56:46 +0530 Subject: [PATCH] Structured logging of grants (#930) * Structured logging of grants * generated protobuf --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> --- auth/grants.go | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/auth/grants.go b/auth/grants.go index 765b692c..fa8ba0d9 100644 --- a/auth/grants.go +++ b/auth/grants.go @@ -18,10 +18,12 @@ import ( "maps" "strings" + "go.uber.org/zap/zapcore" "golang.org/x/exp/slices" "google.golang.org/protobuf/encoding/protojson" "github.com/livekit/protocol/livekit" + "github.com/livekit/protocol/logger" "github.com/livekit/protocol/utils" ) @@ -93,6 +95,20 @@ func (c *ClaimGrants) Clone() *ClaimGrants { return &clone } +func (c *ClaimGrants) MarshalLogObject(e zapcore.ObjectEncoder) error { + if c == nil { + return nil + } + + e.AddString("Identity", c.Identity) + e.AddString("Kind", c.Kind) + e.AddObject("Video", c.Video) + e.AddObject("SIP", c.SIP) + e.AddObject("RoomConfig", logger.Proto((*livekit.RoomConfiguration)(c.RoomConfig))) + e.AddString("RoomPreset", c.RoomPreset) + return nil +} + // ------------------------------------------------------------- type VideoGrant struct { @@ -323,6 +339,43 @@ func (v *VideoGrant) Clone() *VideoGrant { return &clone } +func (v *VideoGrant) MarshalLogObject(e zapcore.ObjectEncoder) error { + if v == nil { + return nil + } + + logBoolPtr := func(prop string, val *bool) { + if val == nil { + e.AddString(prop, "not-set") + } else { + e.AddBool(prop, *val) + } + } + + logBoolPtr("RoomCreate", &v.RoomCreate) + logBoolPtr("RoomList", &v.RoomList) + logBoolPtr("RoomRecord", &v.RoomRecord) + + logBoolPtr("RoomAdmin", &v.RoomAdmin) + logBoolPtr("RoomJoin", &v.RoomJoin) + e.AddString("Room", v.Room) + + logBoolPtr("CanPublish", v.CanPublish) + logBoolPtr("CanSubscribe", v.CanSubscribe) + logBoolPtr("CanPublishData", v.CanPublishData) + e.AddArray("CanPublishSources", logger.StringSlice(v.CanPublishSources)) + logBoolPtr("CanUpdateOwnMetadata", v.CanUpdateOwnMetadata) + + logBoolPtr("IngressAdmin", &v.IngressAdmin) + + logBoolPtr("Hidden", &v.Hidden) + logBoolPtr("Recorder", &v.Recorder) + logBoolPtr("Agent", &v.Agent) + + logBoolPtr("CanSubscribeMetrics", v.CanSubscribeMetrics) + return nil +} + // ---------------------------------------------------------------- type SIPGrant struct { @@ -343,6 +396,16 @@ func (s *SIPGrant) Clone() *SIPGrant { return &clone } +func (s *SIPGrant) MarshalLogObject(e zapcore.ObjectEncoder) error { + if s == nil { + return nil + } + + e.AddBool("Admin", s.Admin) + e.AddBool("Call", s.Call) + return nil +} + // ------------------------------------------------------------------ func sourceToString(source livekit.TrackSource) string {