From 08ace96be850cfbd0805e86a6edc7c320b186920 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Sun, 3 Dec 2023 01:46:44 +0100 Subject: [PATCH] cookie: nicer prometheus metrics handling --- cookie/store.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/cookie/store.go b/cookie/store.go index 3447022..5b6e30c 100644 --- a/cookie/store.go +++ b/cookie/store.go @@ -463,7 +463,7 @@ func (st *Store) New(username string, ai AgentInfo) (value string, opts Options, return } -func (st *Store) Verify(value string) (s Session, err error) { +func (st *Store) verify(value string) (s Session, err error) { var v Value if err = v.FromString(value); err != nil { return @@ -475,39 +475,43 @@ func (st *Store) Verify(value string) (s Session, err error) { } } if err != nil { - cookiesVerifiedFailed.WithLabelValues().Inc() err = fmt.Errorf("cookie signature is not valid") return } if s, err = v.Session(); err != nil { - cookiesVerifiedFailed.WithLabelValues().Inc() err = fmt.Errorf("unable to decode cookie: %v", err) return } if s.IsExpired() { - cookiesVerifiedFailed.WithLabelValues().Inc() err = fmt.Errorf("cookie is expired") return } var revoked bool if revoked, err = st.backend.IsRevoked(s); err != nil { - cookiesVerifiedFailed.WithLabelValues().Inc() err = fmt.Errorf("failed to check for cookie revocation: %v", err) return } if revoked { - cookiesVerifiedFailed.WithLabelValues().Inc() err = fmt.Errorf("cookie is revoked") return } - cookiesVerifiedSuccess.WithLabelValues().Inc() st.dbgLog.Printf("successfully verified session('%v'): %+v", s.ID, s.SessionBase) return } +func (st *Store) Verify(value string) (s Session, err error) { + s, err = st.verify(value) + if err != nil { + cookiesVerifiedFailed.WithLabelValues().Inc() + } else { + cookiesVerifiedSuccess.WithLabelValues().Inc() + } + return +} + func (st *Store) ListUser(username string) (SessionFullList, error) { return st.backend.ListUser(username) }