mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: Fix linting issues caught by ruleguard (#28799)
* Chore: Fix linting issues caught by ruleguard Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Improve error check Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
parent
967e9b39e8
commit
2bf964c61e
@ -3,6 +3,7 @@ package bus
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
@ -140,9 +141,13 @@ func (b *InProcBus) Publish(msg Msg) error {
|
||||
|
||||
for _, listenerHandler := range listeners {
|
||||
ret := reflect.ValueOf(listenerHandler).Call(params)
|
||||
err := ret[0].Interface()
|
||||
if err != nil {
|
||||
return err.(error)
|
||||
e := ret[0].Interface()
|
||||
if e != nil {
|
||||
err, ok := e.(error)
|
||||
if ok {
|
||||
return err
|
||||
}
|
||||
return fmt.Errorf("expected listener to return an error, got '%T'", e)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,11 +15,11 @@ var header = setting.AuthProxyHeaderName
|
||||
func logUserIn(auth *authproxy.AuthProxy, username string, logger log.Logger, ignoreCache bool) (int64, *authproxy.Error) {
|
||||
logger.Debug("Trying to log user in", "username", username, "ignoreCache", ignoreCache)
|
||||
// Try to log in user via various providers
|
||||
id, err := auth.Login(logger, ignoreCache)
|
||||
if err != nil {
|
||||
logger.Error("Failed to login", "username", username, "message", err.Error(), "error", err.DetailsError,
|
||||
id, e := auth.Login(logger, ignoreCache)
|
||||
if e != nil {
|
||||
logger.Error("Failed to login", "username", username, "message", e.Error(), "error", e.DetailsError,
|
||||
"ignoreCache", ignoreCache)
|
||||
return 0, err
|
||||
return 0, e
|
||||
}
|
||||
return id, nil
|
||||
}
|
||||
@ -55,16 +55,16 @@ func initContextWithAuthProxy(store *remotecache.RemoteCache, ctx *models.ReqCon
|
||||
return true
|
||||
}
|
||||
|
||||
id, err := logUserIn(auth, username, logger, false)
|
||||
if err != nil {
|
||||
ctx.Handle(407, err.Error(), err.DetailsError)
|
||||
id, e := logUserIn(auth, username, logger, false)
|
||||
if e != nil {
|
||||
ctx.Handle(407, e.Error(), e.DetailsError)
|
||||
return true
|
||||
}
|
||||
|
||||
logger.Debug("Got user ID, getting full user info", "userID", id)
|
||||
|
||||
user, err := auth.GetSignedUser(id)
|
||||
if err != nil {
|
||||
user, e := auth.GetSignedUser(id)
|
||||
if e != nil {
|
||||
// The reason we couldn't find the user corresponding to the ID might be that the ID was found from a stale
|
||||
// cache entry. For example, if a user is deleted via the API, corresponding cache entries aren't invalidated
|
||||
// because cache keys are computed from request header values and not just the user ID. Meaning that
|
||||
@ -76,15 +76,15 @@ func initContextWithAuthProxy(store *remotecache.RemoteCache, ctx *models.ReqCon
|
||||
logger.Error("Got unexpected error when removing user from auth cache", "error", err)
|
||||
}
|
||||
}
|
||||
id, err = logUserIn(auth, username, logger, true)
|
||||
if err != nil {
|
||||
ctx.Handle(407, err.Error(), err.DetailsError)
|
||||
id, e = logUserIn(auth, username, logger, true)
|
||||
if e != nil {
|
||||
ctx.Handle(407, e.Error(), e.DetailsError)
|
||||
return true
|
||||
}
|
||||
|
||||
user, err = auth.GetSignedUser(id)
|
||||
if err != nil {
|
||||
ctx.Handle(407, err.Error(), err.DetailsError)
|
||||
user, e = auth.GetSignedUser(id)
|
||||
if e != nil {
|
||||
ctx.Handle(407, e.Error(), e.DetailsError)
|
||||
return true
|
||||
}
|
||||
}
|
||||
@ -96,14 +96,14 @@ func initContextWithAuthProxy(store *remotecache.RemoteCache, ctx *models.ReqCon
|
||||
ctx.IsSignedIn = true
|
||||
|
||||
// Remember user data in cache
|
||||
if err := auth.Remember(id); err != nil {
|
||||
if e := auth.Remember(id); e != nil {
|
||||
logger.Error(
|
||||
"Failed to store user in cache",
|
||||
"username", username,
|
||||
"message", err.Error(),
|
||||
"error", err.DetailsError,
|
||||
"message", e.Error(),
|
||||
"error", e.DetailsError,
|
||||
)
|
||||
ctx.Handle(500, err.Error(), err.DetailsError)
|
||||
ctx.Handle(500, e.Error(), e.DetailsError)
|
||||
return true
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"hash/fnv"
|
||||
"net"
|
||||
"net/mail"
|
||||
"path"
|
||||
"reflect"
|
||||
"strings"
|
||||
"time"
|
||||
@ -179,12 +180,12 @@ func (auth *AuthProxy) Login(logger log.Logger, ignoreCache bool) (int64, *Error
|
||||
}
|
||||
|
||||
if isLDAPEnabled() {
|
||||
id, err := auth.LoginViaLDAP()
|
||||
if err != nil {
|
||||
if err == ldap.ErrInvalidCredentials {
|
||||
id, e := auth.LoginViaLDAP()
|
||||
if e != nil {
|
||||
if e == ldap.ErrInvalidCredentials {
|
||||
return 0, newError("proxy authentication required", ldap.ErrInvalidCredentials)
|
||||
}
|
||||
return 0, newError("failed to get the user", err)
|
||||
return 0, newError("failed to get the user", e)
|
||||
}
|
||||
|
||||
return id, nil
|
||||
@ -347,7 +348,7 @@ func (auth *AuthProxy) Remember(id int64) *Error {
|
||||
func coerceProxyAddress(proxyAddr string) (*net.IPNet, error) {
|
||||
proxyAddr = strings.TrimSpace(proxyAddr)
|
||||
if !strings.Contains(proxyAddr, "/") {
|
||||
proxyAddr = strings.Join([]string{proxyAddr, "32"}, "/")
|
||||
proxyAddr = path.Join(proxyAddr, "32")
|
||||
}
|
||||
|
||||
_, network, err := net.ParseCIDR(proxyAddr)
|
||||
|
@ -90,7 +90,7 @@ func (m *msSqlMacroEngine) evaluateMacro(name string, args []string) (string, er
|
||||
case "__timeGroupAlias":
|
||||
tg, err := m.evaluateMacro("__timeGroup", args)
|
||||
if err == nil {
|
||||
return tg + " AS [time]", err
|
||||
return tg + " AS [time]", nil
|
||||
}
|
||||
return "", err
|
||||
case "__unixEpochFilter":
|
||||
@ -125,7 +125,7 @@ func (m *msSqlMacroEngine) evaluateMacro(name string, args []string) (string, er
|
||||
case "__unixEpochGroupAlias":
|
||||
tg, err := m.evaluateMacro("__unixEpochGroup", args)
|
||||
if err == nil {
|
||||
return tg + " AS [time]", err
|
||||
return tg + " AS [time]", nil
|
||||
}
|
||||
return "", err
|
||||
default:
|
||||
|
@ -96,7 +96,7 @@ func (m *mySqlMacroEngine) evaluateMacro(name string, args []string) (string, er
|
||||
case "__timeGroupAlias":
|
||||
tg, err := m.evaluateMacro("__timeGroup", args)
|
||||
if err == nil {
|
||||
return tg + " AS \"time\"", err
|
||||
return tg + " AS \"time\"", nil
|
||||
}
|
||||
return "", err
|
||||
case "__unixEpochFilter":
|
||||
@ -131,7 +131,7 @@ func (m *mySqlMacroEngine) evaluateMacro(name string, args []string) (string, er
|
||||
case "__unixEpochGroupAlias":
|
||||
tg, err := m.evaluateMacro("__unixEpochGroup", args)
|
||||
if err == nil {
|
||||
return tg + " AS \"time\"", err
|
||||
return tg + " AS \"time\"", nil
|
||||
}
|
||||
return "", err
|
||||
default:
|
||||
|
@ -120,7 +120,7 @@ func (m *postgresMacroEngine) evaluateMacro(name string, args []string) (string,
|
||||
case "__timeGroupAlias":
|
||||
tg, err := m.evaluateMacro("__timeGroup", args)
|
||||
if err == nil {
|
||||
return tg + " AS \"time\"", err
|
||||
return tg + " AS \"time\"", nil
|
||||
}
|
||||
return "", err
|
||||
case "__unixEpochFilter":
|
||||
@ -155,7 +155,7 @@ func (m *postgresMacroEngine) evaluateMacro(name string, args []string) (string,
|
||||
case "__unixEpochGroupAlias":
|
||||
tg, err := m.evaluateMacro("__unixEpochGroup", args)
|
||||
if err == nil {
|
||||
return tg + " AS \"time\"", err
|
||||
return tg + " AS \"time\"", nil
|
||||
}
|
||||
return "", err
|
||||
default:
|
||||
|
Loading…
Reference in New Issue
Block a user