Skip to content

Commit

Permalink
provisioning/Logout: use structured logging
Browse files Browse the repository at this point in the history
Signed-off-by: Sumner Evans <[email protected]>
  • Loading branch information
sumnerevans committed Dec 30, 2023
1 parent e08c282 commit a6edfd0
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions provisioning.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,14 +330,15 @@ func (prov *ProvisioningAPI) existingSession(user *User) (handle *provisioningHa
return nil
}

func (prov *ProvisioningAPI) clearSession(user *User) {
func (prov *ProvisioningAPI) clearSession(ctx context.Context, user *User) {
log := zerolog.Ctx(ctx).With().Str("function", "clearSession").Logger()
prov.mutexForUser(user).Lock()
defer prov.mutexForUser(user).Unlock()

if existingSessionID, ok := prov.provisioningUsers[user.MXID.String()]; ok {
prov.log.Debug().Msgf("clearSession called for %v, clearing session %v", user.MXID, existingSessionID)
log.Debug().Int("existing_session_id", existingSessionID).Msg("clearing existing session")
if existingSessionID >= len(prov.provisioningHandles) {
prov.log.Warn().Msgf("clearSession called for %v, session %v does not exist", user.MXID, existingSessionID)
log.Warn().Msg("session does not exist")
return
}
if prov.provisioningHandles[existingSessionID].cancel != nil {
Expand All @@ -346,7 +347,7 @@ func (prov *ProvisioningAPI) clearSession(user *User) {
prov.provisioningHandles[existingSessionID] = nil
delete(prov.provisioningUsers, user.MXID.String())
} else {
prov.log.Debug().Msgf("clearSession called for %v, no session found", user.MXID)
prov.log.Debug().Msg("no session found")
}
}

Expand All @@ -361,7 +362,7 @@ func (prov *ProvisioningAPI) loginOrSendError(ctx context.Context, w http.Respon
zerolog.Ctx(ctx).Debug().
Int("existing_provisioning_handle", handle.id).
Msg("user already has pending provisioning request, cancelling")
prov.clearSession(user)
prov.clearSession(ctx, user)
newSessionLoggedIn, handle, err = prov.newOrExistingSession(user)
if err != nil {
return nil, fmt.Errorf("error logging in after cancelling existing session: %w", err)
Expand Down Expand Up @@ -639,8 +640,14 @@ func (prov *ProvisioningAPI) LinkWaitForAccount(w http.ResponseWriter, r *http.R

func (prov *ProvisioningAPI) Logout(w http.ResponseWriter, r *http.Request) {
user := r.Context().Value("user").(*User)
prov.log.Debug().Msgf("Logout called from %v (but not logging out)", user.MXID)
prov.clearSession(user)
log := prov.log.With().
Str("action", "logout").
Str("user_id", user.MXID.String()).
Logger()
ctx := log.WithContext(r.Context())
log.Debug().Msg("Logout called (but not logging out)")

prov.clearSession(ctx, user)

// For now do nothing - we need this API to return 200 to be compatible with
// the old Signal bridge, which needed a call to Logout before allowing LinkNew
Expand Down

0 comments on commit a6edfd0

Please sign in to comment.