11package gateway
22
33import (
4+ "context"
45 "encoding/base64"
56 "encoding/json"
67 "strings"
@@ -21,6 +22,7 @@ type SessionHandler interface {
2122 UpdateSession (keyName string , session * user.SessionState , resetTTLTo int64 , hashed bool ) error
2223 RemoveSession (orgID string , keyName string , hashed bool ) bool
2324 SessionDetail (orgID string , keyName string , hashed bool ) (user.SessionState , bool )
25+ SessionDetailContext (ctx context.Context , orgID string , keyName string , hashed bool ) (user.SessionState , bool )
2426 KeyExpired (newSession * user.SessionState ) bool
2527 Sessions (filter string ) []string
2628 ResetQuota (string , * user.SessionState , bool )
@@ -159,6 +161,28 @@ func (b *DefaultSessionManager) RemoveSession(orgID string, keyName string, hash
159161
160162// SessionDetail returns the session detail using the storage engine (either in memory or Redis)
161163func (b * DefaultSessionManager ) SessionDetail (orgID string , keyName string , hashed bool ) (user.SessionState , bool ) {
164+ return b .fetchSessionDetail (nil , orgID , keyName , hashed )
165+ }
166+
167+ // SessionDetailContext returns the session detail using the storage engine with context support for cancellation
168+ func (b * DefaultSessionManager ) SessionDetailContext (ctx context.Context , orgID string , keyName string , hashed bool ) (user.SessionState , bool ) {
169+ return b .fetchSessionDetail (ctx , orgID , keyName , hashed )
170+ }
171+
172+ // fetchSessionDetail is the internal implementation shared by SessionDetail and SessionDetailContext
173+ func (b * DefaultSessionManager ) fetchSessionDetail (ctx context.Context , orgID string , keyName string , hashed bool ) (user.SessionState , bool ) {
174+ if ctx != nil {
175+ select {
176+ case <- ctx .Done ():
177+ log .WithFields (logrus.Fields {
178+ "prefix" : "auth-mgr" ,
179+ "inbound-key" : b .Gw .obfuscateKey (keyName ),
180+ }).Debug ("Context cancelled" )
181+ return user.SessionState {}, false
182+ default :
183+ }
184+ }
185+
162186 var jsonKeyVal string
163187 var err error
164188 keyId := keyName
0 commit comments