palourde/uchiwa

View on GitHub

Showing 56 of 81 total issues

Method API.doRequest has 8 return statements (exceeds 4 allowed).
Open

func (api *API) doRequest(req *http.Request) ([]byte, *http.Response, error) {
    if api.User != "" && api.Pass != "" {
        req.SetBasicAuth(api.User, api.Pass)
    }

Severity: Major
Found in uchiwa/sensu/request.go - About 50 mins to fix

    Method Uchiwa.resultsHandler has a Cognitive Complexity of 23 (exceeds 20 allowed). Consider refactoring.
    Open

    func (u *Uchiwa) resultsHandler(w http.ResponseWriter, r *http.Request) {
        if r.Method != http.MethodDelete {
            http.Error(w, "", http.StatusBadRequest)
            return
        }
    Severity: Minor
    Found in uchiwa/server.go - About 45 mins to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Avoid deeply nested control flow statements.
    Open

        } else if global.Db.Driver != "" && global.Db.Scheme != "" {
            global.Auth.Driver = "sql"
        } else if len(global.Users) != 0 {
            logger.Debug("Loading multiple users from the config")
            global.Auth.Driver = "simple"
    Severity: Major
    Found in uchiwa/config/config.go - About 45 mins to fix

      Method Uchiwa.eventHandler has a Cognitive Complexity of 23 (exceeds 20 allowed). Consider refactoring.
      Open

      func (u *Uchiwa) eventHandler(w http.ResponseWriter, r *http.Request) {
          if r.Method != http.MethodDelete {
              http.Error(w, "", http.StatusBadRequest)
              return
          }
      Severity: Minor
      Found in uchiwa/server.go - About 45 mins to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Method API.getSlice has 6 return statements (exceeds 4 allowed).
      Open

      func (api *API) getSlice(ctx context.Context, endpoint string, limit int) ([]interface{}, error) {
          var offset int
      
          u, err := url.Parse(fmt.Sprintf("%s/%s", api.URL, endpoint))
          if err != nil {
      Severity: Major
      Found in uchiwa/sensu/methods.go - About 40 mins to fix

        Method Uchiwa.datacenterHandler has 6 return statements (exceeds 4 allowed).
        Open

        func (u *Uchiwa) datacenterHandler(w http.ResponseWriter, r *http.Request) {
            if r.Method != http.MethodGet && r.Method != http.MethodHead {
                http.Error(w, "", http.StatusBadRequest)
                return
            }
        Severity: Major
        Found in uchiwa/server.go - About 40 mins to fix

          Function IsCheckSilenced has 5 return statements (exceeds 4 allowed).
          Open

          func IsCheckSilenced(check, client map[string]interface{}, dc string, silenced []interface{}) (bool, []string) {
              var isSilenced bool
              var commonSubscriptions, isSilencedBy, subscribers, subscriptions []string
          
              if dc == "" || len(silenced) == 0 {
          Severity: Major
          Found in uchiwa/helpers/helpers.go - About 35 mins to fix

            Method Uchiwa.datacentersHandler has 5 return statements (exceeds 4 allowed).
            Open

            func (u *Uchiwa) datacentersHandler(w http.ResponseWriter, r *http.Request) {
                if r.Method != http.MethodGet && r.Method != http.MethodHead {
                    http.Error(w, "", http.StatusBadRequest)
                    return
                }
            Severity: Major
            Found in uchiwa/server.go - About 35 mins to fix

              Method Uchiwa.eventsHandler has 5 return statements (exceeds 4 allowed).
              Open

              func (u *Uchiwa) eventsHandler(w http.ResponseWriter, r *http.Request) {
                  if r.Method != http.MethodGet && r.Method != http.MethodHead {
                      http.Error(w, "", http.StatusBadRequest)
                      return
                  }
              Severity: Major
              Found in uchiwa/server.go - About 35 mins to fix

                Method Uchiwa.UpdateClient has 5 return statements (exceeds 4 allowed).
                Open

                func (u *Uchiwa) UpdateClient(payload interface{}) error {
                    client, ok := payload.(map[string]interface{})
                    if !ok {
                        return fmt.Errorf("Unable to decode the payload")
                    }
                Severity: Major
                Found in uchiwa/client.go - About 35 mins to fix

                  Method Uchiwa.stashesHandler has a Cognitive Complexity of 22 (exceeds 20 allowed). Consider refactoring.
                  Open

                  func (u *Uchiwa) stashesHandler(w http.ResponseWriter, r *http.Request) {
                      token := authentication.GetJWTFromContext(r)
                  
                      if r.Method == http.MethodGet || r.Method == http.MethodHead {
                          // GET on /stashes
                  Severity: Minor
                  Found in uchiwa/server.go - About 35 mins to fix

                  Cognitive Complexity

                  Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                  A method's cognitive complexity is based on a few simple rules:

                  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                  • Code is considered more complex for each "break in the linear flow of the code"
                  • Code is considered more complex when "flow breaking structures are nested"

                  Further reading

                  Method Uchiwa.aggregatesHandler has 5 return statements (exceeds 4 allowed).
                  Open

                  func (u *Uchiwa) aggregatesHandler(w http.ResponseWriter, r *http.Request) {
                      if r.Method != http.MethodGet && r.Method != http.MethodHead {
                          http.Error(w, "", http.StatusBadRequest)
                          return
                      }
                  Severity: Major
                  Found in uchiwa/server.go - About 35 mins to fix

                    Method Uchiwa.checksHandler has 5 return statements (exceeds 4 allowed).
                    Open

                    func (u *Uchiwa) checksHandler(w http.ResponseWriter, r *http.Request) {
                        if r.Method != http.MethodGet && r.Method != http.MethodHead {
                            http.Error(w, "", http.StatusBadRequest)
                            return
                        }
                    Severity: Major
                    Found in uchiwa/server.go - About 35 mins to fix

                      Method Uchiwa.requestHandler has 5 return statements (exceeds 4 allowed).
                      Open

                      func (u *Uchiwa) requestHandler(w http.ResponseWriter, r *http.Request) {
                          if r.Method != http.MethodPost {
                              http.Error(w, "", http.StatusBadRequest)
                              return
                          }
                      Severity: Major
                      Found in uchiwa/server.go - About 35 mins to fix

                        Function verifyJWT has 5 return statements (exceeds 4 allowed).
                        Open

                        func verifyJWT(tokenString string) (*jwt.Token, error) {
                            token, err := jwt.Parse(tokenString, func(token *jwt.Token) (interface{}, error) {
                                // Don't forget to validate the alg is what you expect:
                                if _, ok := token.Method.(*jwt.SigningMethodRSA); !ok {
                                    logger.Debugf("Unexpected signing method: %v", token.Header["alg"])
                        Severity: Major
                        Found in uchiwa/authentication/jwt.go - About 35 mins to fix

                          Method API.getSlice has a Cognitive Complexity of 22 (exceeds 20 allowed). Consider refactoring.
                          Open

                          func (api *API) getSlice(ctx context.Context, endpoint string, limit int) ([]interface{}, error) {
                              var offset int
                          
                              u, err := url.Parse(fmt.Sprintf("%s/%s", api.URL, endpoint))
                              if err != nil {
                          Severity: Minor
                          Found in uchiwa/sensu/methods.go - About 35 mins to fix

                          Cognitive Complexity

                          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                          A method's cognitive complexity is based on a few simple rules:

                          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                          • Code is considered more complex for each "break in the linear flow of the code"
                          • Code is considered more complex when "flow breaking structures are nested"

                          Further reading

                          Severity
                          Category
                          Status
                          Source
                          Language