Skip to content

Commit

Permalink
Structured logging of grants (#930)
Browse files Browse the repository at this point in the history
* Structured logging of grants

* generated protobuf

---------

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
boks1971 and github-actions[bot] authored Dec 20, 2024
1 parent c87b1af commit 970d4dc
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions auth/grants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit 970d4dc

Please sign in to comment.