palourde/uchiwa

View on GitHub

Showing 81 of 81 total issues

Similar blocks of code found in 3 locations. Consider refactoring.
Open

func (u *Uchiwa) ClearSilenced(data silence) error {
    api, err := getAPI(u.Datacenters, data.Dc)
    if err != nil {
        logger.Warning(err)
        return err
Severity: Major
Found in uchiwa/silenced.go and 2 other locations - About 50 mins to fix
uchiwa/silenced.go on lines 35..49
uchiwa/stash.go on lines 17..31

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 120.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Method Uchiwa.stashesHandler has 8 return statements (exceeds 4 allowed).
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: Major
Found in uchiwa/server.go - About 50 mins to fix

    Similar blocks of code found in 3 locations. Consider refactoring.
    Open

    func (u *Uchiwa) PostStash(data stash) error {
        api, err := getAPI(u.Datacenters, data.Dc)
        if err != nil {
            logger.Warning(err)
            return err
    Severity: Major
    Found in uchiwa/stash.go and 2 other locations - About 50 mins to fix
    uchiwa/silenced.go on lines 18..32
    uchiwa/silenced.go on lines 35..49

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 120.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    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 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

      Similar blocks of code found in 3 locations. Consider refactoring.
      Open

      func (s *Sensu) CreateStash(payload interface{}) (map[string]interface{}, error) {
          payloadstr, err := json.Marshal(payload)
          if err != nil {
              return nil, fmt.Errorf("Stash parsing error: %q returned: %v", err, err)
          }
      Severity: Major
      Found in uchiwa/sensu/stashes.go and 2 other locations - About 40 mins to fix
      uchiwa/sensu/silenced.go on lines 10..16
      uchiwa/sensu/silenced.go on lines 24..30

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 111.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 3 locations. Consider refactoring.
      Open

      func (s *Sensu) ClearSilenced(payload interface{}) (map[string]interface{}, error) {
          payloadstr, err := json.Marshal(payload)
          if err != nil {
              return nil, fmt.Errorf("Silence parsing error: %q returned: %v", err, err)
          }
      Severity: Major
      Found in uchiwa/sensu/silenced.go and 2 other locations - About 40 mins to fix
      uchiwa/sensu/silenced.go on lines 24..30
      uchiwa/sensu/stashes.go on lines 20..26

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 111.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 3 locations. Consider refactoring.
      Open

      func (s *Sensu) Silence(payload interface{}) (map[string]interface{}, error) {
          payloadstr, err := json.Marshal(payload)
          if err != nil {
              return nil, fmt.Errorf("Silence parsing error: %q returned: %v", err, err)
          }
      Severity: Major
      Found in uchiwa/sensu/silenced.go and 2 other locations - About 40 mins to fix
      uchiwa/sensu/silenced.go on lines 10..16
      uchiwa/sensu/stashes.go on lines 20..26

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 111.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      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

        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.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.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.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 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 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

                      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
                        Severity
                        Category
                        Status
                        Source
                        Language