Skip to content

Commit

Permalink
Add more debug
Browse files Browse the repository at this point in the history
  • Loading branch information
leszko committed Sep 3, 2024
1 parent b29cfc7 commit c7a6441
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions handlers/accesscontrol/access-control.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ func (ac *AccessControlHandlersCollection) isAuthorized(ctx context.Context, pla
return false, err
}
cacheKey = "accessKey_" + hashCacheKey
glog.Infof("Produced cacheKey from accessKey: %s", cacheKey)
} else if jwt != "" {
for _, blocked := range ac.blockedJWTs {
if jwt == blocked {
Expand All @@ -288,6 +289,7 @@ func (ac *AccessControlHandlersCollection) isAuthorized(ctx context.Context, pla
return false, err
}
cacheKey = "jwtPubKey_" + hashCacheKey
glog.Infof("Produced cacheKey from JWT: %s", cacheKey)
}

body, err := json.Marshal(acReq)
Expand Down Expand Up @@ -377,29 +379,35 @@ func (ac *AccessControlHandlersCollection) refreshConcurrentViewerCache(playback
}

func (ac *AccessControlHandlersCollection) GetPlaybackAccessControlInfo(ctx context.Context, playbackID, cacheKey string, requestBody []byte) (bool, error) {
glog.Infof("GetPlaybackAccessControlInfo playbackID=%s, cacheKey=%s, requestBody=%v", playbackID, cacheKey, requestBody)
ac.mutex.RLock()
entry := ac.cache[playbackID][cacheKey]
ac.mutex.RUnlock()

if isExpired(entry) {
log.V(7).LogCtx(ctx, "Cache expired",
"cache_key", cacheKey)
glog.Infof("Cache expired, calling cachePlaybackAccessControlInfo")
err := ac.cachePlaybackAccessControlInfo(playbackID, cacheKey, requestBody)
if err != nil {
return false, err
}
glog.Infof("Cache expired, cached new playback access control info")
} else if isStale(entry) {
log.V(7).LogCtx(ctx, "Cache stale",
"cache_key", cacheKey)
glog.Infof("Cache stale")
go func() {
ac.mutex.RLock()
stillStale := isStale(ac.cache[playbackID][cacheKey])
ac.mutex.RUnlock()
if stillStale {
glog.Infof("Cache still stale, calling cachePlaybackAccessControlInfo")
err := ac.cachePlaybackAccessControlInfo(playbackID, cacheKey, requestBody)
if err != nil {
log.LogCtx(ctx, "Error caching playback access control info", "err", err)
}
glog.Infof("Cache still stale, cached new playback access control info")
}
}()
}
Expand Down Expand Up @@ -433,6 +441,7 @@ func isStale(entry *PlaybackAccessControlEntry) bool {
}

func (ac *AccessControlHandlersCollection) cachePlaybackAccessControlInfo(playbackID, cacheKey string, requestBody []byte) error {
glog.Infof("cachePlaybackAccessControlInfo, playbackID=%s, cacheKey=%s, requestBody=%v", playbackID, cacheKey, requestBody)
allow, gateConfig, err := ac.gateClient.QueryGate(requestBody)

refreshInterval := gateConfig.RefreshInterval
Expand Down

0 comments on commit c7a6441

Please sign in to comment.