refactor: Logs & errors review.
- log & error: remove format if not necessary, add if necessary. - add constants for k8s annotations. - fix typos
This commit is contained in:
parent
994e135368
commit
cbccdd51c5
26 changed files with 125 additions and 128 deletions
|
@ -12,8 +12,7 @@ import (
|
|||
const commonLogTimeFormat = "02/Jan/2006:15:04:05 -0700"
|
||||
|
||||
// CommonLogFormatter provides formatting in the Traefik common log format
|
||||
type CommonLogFormatter struct {
|
||||
}
|
||||
type CommonLogFormatter struct{}
|
||||
|
||||
//Format formats the log entry in the Traefik common log format
|
||||
func (f *CommonLogFormatter) Format(entry *logrus.Entry) ([]byte, error) {
|
||||
|
|
|
@ -70,10 +70,10 @@ func TestLogger(t *testing.T) {
|
|||
|
||||
if logdata, err := ioutil.ReadFile(logfilePath); err != nil {
|
||||
fmt.Printf("%s\n%s\n", string(logdata), err.Error())
|
||||
assert.Nil(t, err)
|
||||
assert.NoError(t, err)
|
||||
} else if tokens, err := shellwords.Parse(string(logdata)); err != nil {
|
||||
fmt.Printf("%s\n", err.Error())
|
||||
assert.Nil(t, err)
|
||||
assert.NoError(t, err)
|
||||
} else if assert.Equal(t, 14, len(tokens), printLogdata(logdata)) {
|
||||
assert.Equal(t, testHostname, tokens[0], printLogdata(logdata))
|
||||
assert.Equal(t, testUsername, tokens[2], printLogdata(logdata))
|
||||
|
|
|
@ -33,10 +33,10 @@ func NewAuthenticator(authConfig *types.Auth) (*Authenticator, error) {
|
|||
basicAuth := auth.NewBasicAuthenticator("traefik", authenticator.secretBasic)
|
||||
authenticator.handler = negroni.HandlerFunc(func(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
|
||||
if username := basicAuth.CheckAuth(r); username == "" {
|
||||
log.Debugf("Basic auth failed...")
|
||||
log.Debug("Basic auth failed...")
|
||||
basicAuth.RequireAuth(w, r)
|
||||
} else {
|
||||
log.Debugf("Basic auth success...")
|
||||
log.Debug("Basic auth success...")
|
||||
if authConfig.HeaderField != "" {
|
||||
r.Header[authConfig.HeaderField] = []string{username}
|
||||
}
|
||||
|
@ -51,10 +51,10 @@ func NewAuthenticator(authConfig *types.Auth) (*Authenticator, error) {
|
|||
digestAuth := auth.NewDigestAuthenticator("traefik", authenticator.secretDigest)
|
||||
authenticator.handler = negroni.HandlerFunc(func(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
|
||||
if username, _ := digestAuth.CheckAuth(r); username == "" {
|
||||
log.Debugf("Digest auth failed...")
|
||||
log.Debug("Digest auth failed...")
|
||||
digestAuth.RequireAuth(w, r)
|
||||
} else {
|
||||
log.Debugf("Digest auth success...")
|
||||
log.Debug("Digest auth success...")
|
||||
if authConfig.HeaderField != "" {
|
||||
r.Header[authConfig.HeaderField] = []string{username}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
|
||||
"github.com/codegangsta/negroni"
|
||||
"github.com/containous/traefik/log"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// IPWhitelister is a middleware that provides Checks of the Requesting IP against a set of Whitelists
|
||||
|
@ -20,7 +21,7 @@ func NewIPWhitelister(whitelistStrings []string) (*IPWhitelister, error) {
|
|||
whitelister := IPWhitelister{}
|
||||
|
||||
if len(whitelistStrings) == 0 {
|
||||
return nil, fmt.Errorf("no whitelists provided")
|
||||
return nil, errors.New("no whitelists provided")
|
||||
}
|
||||
|
||||
for _, whitelistString := range whitelistStrings {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue