Add username to authenticated log messages
This commit is contained in:
@@ -217,6 +217,7 @@ func UsernameFromConfig(r *http.Request) string {
|
|||||||
func contextWithUser(ctx context.Context, ds model.DataStore, username string) (context.Context, error) {
|
func contextWithUser(ctx context.Context, ds model.DataStore, username string) (context.Context, error) {
|
||||||
user, err := ds.User(ctx).FindByUsername(username)
|
user, err := ds.User(ctx).FindByUsername(username)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
ctx = log.NewContext(ctx, "username", username)
|
||||||
ctx = request.WithUsername(ctx, user.UserName)
|
ctx = request.WithUsername(ctx, user.UserName)
|
||||||
return request.WithUser(ctx, *user), nil
|
return request.WithUser(ctx, *user), nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,7 +98,9 @@ func authenticate(ds model.DataStore) func(next http.Handler) http.Handler {
|
|||||||
// }
|
// }
|
||||||
//}()
|
//}()
|
||||||
|
|
||||||
|
ctx = log.NewContext(r.Context(), "username", username)
|
||||||
ctx = request.WithUser(ctx, *usr)
|
ctx = request.WithUser(ctx, *usr)
|
||||||
|
ctx = request.WithUsername(ctx, usr.UserName)
|
||||||
r = r.WithContext(ctx)
|
r = r.WithContext(ctx)
|
||||||
|
|
||||||
next.ServeHTTP(w, r)
|
next.ServeHTTP(w, r)
|
||||||
|
|||||||
Reference in New Issue
Block a user