Skip to content

Commit

Permalink
cookie: nicer prometheus metrics handling
Browse files Browse the repository at this point in the history
  • Loading branch information
equinox0815 committed Dec 3, 2023
1 parent 513b52b commit 08ace96
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions cookie/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
Expand Down

0 comments on commit 08ace96

Please sign in to comment.