From cb6a6125f6c1b456f2c00c5bc152aaa7f2bcf886 Mon Sep 17 00:00:00 2001 From: Richard Date: Tue, 14 Apr 2015 16:07:23 -0700 Subject: [PATCH] Add auth.user.name to logging context --- registry/auth/silly/access.go | 2 +- registry/handlers/app.go | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/registry/auth/silly/access.go b/registry/auth/silly/access.go index 134b0ae55..39318d1a3 100644 --- a/registry/auth/silly/access.go +++ b/registry/auth/silly/access.go @@ -66,7 +66,7 @@ func (ac *accessController) Authorized(ctx context.Context, accessRecords ...aut return nil, &challenge } - return context.WithValue(ctx, "auth.user", auth.UserInfo{Name: "silly"}), nil + return auth.WithUser(ctx, auth.UserInfo{Name: "silly"}), nil } type challenge struct { diff --git a/registry/handlers/app.go b/registry/handlers/app.go index c106df47c..8188c9cfb 100644 --- a/registry/handlers/app.go +++ b/registry/handlers/app.go @@ -324,6 +324,9 @@ func (app *App) dispatcher(dispatch dispatchFunc) http.Handler { return } + // Add username to request logging + context.Context = ctxu.WithLogger(context.Context, ctxu.GetLogger(context.Context, "auth.user.name")) + if app.nameRequired(r) { repository, err := app.registry.Repository(context, getName(context)) @@ -456,7 +459,6 @@ func (app *App) authorized(w http.ResponseWriter, r *http.Request, context *Cont // should be replaced by another, rather than replacing the context on a // mutable object. context.Context = ctx - return nil }