basicauth: Simplify user replacement on auth failure (#2470)

* Can simply add user to replacer before Replace call.  user is then also added to logs

* use fmt.Errorf

* fix how fmt.Errorf is called.
This commit is contained in:
Toby Allen 2019-03-04 19:02:24 +00:00 committed by Matt Holt
parent b295aab2d8
commit 4f8020a94c

View file

@ -106,10 +106,9 @@ func (a BasicAuth) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error
// Get a replacer so we can provide basic info for the authentication error. // Get a replacer so we can provide basic info for the authentication error.
repl := httpserver.NewReplacer(r, nil, "-") repl := httpserver.NewReplacer(r, nil, "-")
errstr := repl.Replace("BasicAuth: user \"%s\" was not found or password was incorrect. {remote} {host} {uri} {proto}") repl.Set("user", username)
errstr := repl.Replace("BasicAuth: user \"{user}\" was not found or password was incorrect. {remote} {host} {uri} {proto}")
// Username will not exist in Replacer so provide here. err := fmt.Errorf("%s", errstr)
err := fmt.Errorf(errstr, username)
return http.StatusUnauthorized, err return http.StatusUnauthorized, err
} }