Better tracing

Not done yet, still need to add them to just about every other function
This commit is contained in:
Melody Becker 2024-11-06 16:57:44 +01:00
parent 83f47d17be
commit 529d106351
13 changed files with 148 additions and 22 deletions

View file

@ -4,6 +4,7 @@ import (
"github.com/go-webauthn/webauthn/webauthn"
"github.com/google/uuid"
"github.com/rs/zerolog/log"
"gitlab.com/mstarongitlab/linstrom/util"
)
// Session data used during login attempts with a passkey
@ -18,6 +19,7 @@ type PasskeySession struct {
// Generate some id for a new session. Just returns a new uuid
func (s *Storage) GenSessionID() (string, error) {
defer util.Untrace(util.Trace(&log.Logger))
x := uuid.NewString()
log.Debug().Str("session-id", x).Msg("Generated new passkey session id")
return x, nil
@ -26,6 +28,7 @@ func (s *Storage) GenSessionID() (string, error) {
// Look for an active session with a given id
// Returns the session if found and a bool indicating if a session was found
func (s *Storage) GetSession(sessionId string) (*webauthn.SessionData, bool) {
defer util.Untrace(util.Trace(&log.Logger))
log.Debug().Str("id", sessionId).Msg("Looking for passkey session")
session := PasskeySession{}
res := s.db.Where("id = ?", sessionId).First(&session)
@ -38,6 +41,7 @@ func (s *Storage) GetSession(sessionId string) (*webauthn.SessionData, bool) {
// Save (or update) a session with the new data
func (s *Storage) SaveSession(token string, data *webauthn.SessionData) {
defer util.Untrace(util.Trace(&log.Logger))
log.Debug().Str("id", token).Any("webauthn-data", data).Msg("Saving passkey session")
session := PasskeySession{
ID: token,
@ -49,6 +53,7 @@ func (s *Storage) SaveSession(token string, data *webauthn.SessionData) {
// Delete a session
// NOTE: This is a hard delete since the session struct contains no DeletedAt field
func (s *Storage) DeleteSession(token string) {
defer util.Untrace(util.Trace(&log.Logger))
log.Debug().Str("id", token).Msg("Deleting passkey session (if one exists)")
s.db.Delete(&PasskeySession{ID: token})
}