Skip to content

Commit

Permalink
Fever API: add client IP in middleware logs
Browse files Browse the repository at this point in the history
  • Loading branch information
fguillot committed Aug 9, 2020
1 parent 019cf79 commit 4e07b54
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions fever/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ func newMiddleware(s *storage.Storage) *middleware {

func (m *middleware) serve(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
clientIP := request.ClientIP(r)
apiKey := r.FormValue("api_key")
if apiKey == "" {
logger.Info("[Fever] No API key provided")
logger.Info("[Fever] [ClientIP=%s] No API key provided", clientIP)
json.OK(w, r, newAuthFailureResponse())
return
}
Expand All @@ -39,12 +40,12 @@ func (m *middleware) serve(next http.Handler) http.Handler {
}

if user == nil {
logger.Info("[Fever] No user found with this API key")
logger.Info("[Fever] [ClientIP=%s] No user found with this API key", clientIP)
json.OK(w, r, newAuthFailureResponse())
return
}

logger.Info("[Fever] User #%d is authenticated with user agent %q", user.ID, r.UserAgent())
logger.Info("[Fever] [ClientIP=%s] User #%d is authenticated with user agent %q", clientIP, user.ID, r.UserAgent())
m.store.SetLastLogin(user.ID)

ctx := r.Context()
Expand Down

0 comments on commit 4e07b54

Please sign in to comment.