cloudfoundry-incubator/stratos

View on GitHub
src/jetstream/cnsi.go

Summary

Maintainability
F
3 days
Test Coverage

Method portalProxy.updateEndpoint has a Cognitive Complexity of 45 (exceeds 8 allowed). Consider refactoring.
Open

func (p *portalProxy) updateEndpoint(ec echo.Context) error {
    log.Debug("updateEndpoint")

    params := new(interfaces.UpdateEndpointParams)
    if err := ec.Bind(params); err != nil {
Severity: Minor
Found in src/jetstream/cnsi.go - About 6 hrs 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

File cnsi.go has 660 lines of code (exceeds 500 allowed). Consider refactoring.
Open

package main

import (
    "crypto/x509"
    "encoding/json"
Severity: Minor
Found in src/jetstream/cnsi.go - About 5 hrs to fix

    Method portalProxy.DoRegisterEndpoint has a Cognitive Complexity of 36 (exceeds 8 allowed). Consider refactoring.
    Wontfix

    func (p *portalProxy) DoRegisterEndpoint(cnsiName string, apiEndpoint string, skipSSLValidation bool, clientId string, clientSecret string, userId string, ssoAllowed bool, subType string, createSystemEndpoint bool, fetchInfo interfaces.InfoFunc) (interfaces.CNSIRecord, error) {
        log.Debug("DoRegisterEndpoint")
    
        if len(cnsiName) == 0 || len(apiEndpoint) == 0 {
            return interfaces.CNSIRecord{}, interfaces.NewHTTPShadowError(
    Severity: Minor
    Found in src/jetstream/cnsi.go - About 4 hrs 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 portalProxy.buildCNSIList has a Cognitive Complexity of 35 (exceeds 8 allowed). Consider refactoring.
    Open

    func (p *portalProxy) buildCNSIList(c echo.Context) ([]*interfaces.CNSIRecord, error) {
        log.Debug("buildCNSIList")
    
        if p.GetConfig().UserEndpointsEnabled != config.UserEndpointsConfigEnum.Disabled {
            userID, err := p.GetSessionValue(c, "user_id")
    Severity: Minor
    Found in src/jetstream/cnsi.go - About 4 hrs 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 portalProxy.DoRegisterEndpoint has 101 lines of code (exceeds 50 allowed). Consider refactoring.
    Wontfix

    func (p *portalProxy) DoRegisterEndpoint(cnsiName string, apiEndpoint string, skipSSLValidation bool, clientId string, clientSecret string, userId string, ssoAllowed bool, subType string, createSystemEndpoint bool, fetchInfo interfaces.InfoFunc) (interfaces.CNSIRecord, error) {
        log.Debug("DoRegisterEndpoint")
    
        if len(cnsiName) == 0 || len(apiEndpoint) == 0 {
            return interfaces.CNSIRecord{}, interfaces.NewHTTPShadowError(
    Severity: Major
    Found in src/jetstream/cnsi.go - About 3 hrs to fix

      portalProxy has 26 methods (exceeds 20 allowed). Consider refactoring.
      Open

      func (p *portalProxy) RegisterEndpoint(c echo.Context, fetchInfo interfaces.InfoFunc) error {
          log.Debug("registerEndpoint")
      
          params := new(interfaces.RegisterEndpointParams)
          err := interfaces.BindOnce(params, c)
      Severity: Minor
      Found in src/jetstream/cnsi.go - About 3 hrs to fix

        Method portalProxy.updateEndpoint has 88 lines of code (exceeds 50 allowed). Consider refactoring.
        Open

        func (p *portalProxy) updateEndpoint(ec echo.Context) error {
            log.Debug("updateEndpoint")
        
            params := new(interfaces.UpdateEndpointParams)
            if err := ec.Bind(params); err != nil {
        Severity: Major
        Found in src/jetstream/cnsi.go - About 2 hrs to fix

          Method portalProxy.DoRegisterEndpoint has 10 arguments (exceeds 4 allowed). Consider refactoring.
          Open

          func (p *portalProxy) DoRegisterEndpoint(cnsiName string, apiEndpoint string, skipSSLValidation bool, clientId string, clientSecret string, userId string, ssoAllowed bool, subType string, createSystemEndpoint bool, fetchInfo interfaces.InfoFunc) (interfaces.CNSIRecord, error) {
          Severity: Major
          Found in src/jetstream/cnsi.go - About 1 hr to fix

            Method portalProxy.DoRegisterEndpoint has 10 return statements (exceeds 4 allowed).
            Open

            func (p *portalProxy) DoRegisterEndpoint(cnsiName string, apiEndpoint string, skipSSLValidation bool, clientId string, clientSecret string, userId string, ssoAllowed bool, subType string, createSystemEndpoint bool, fetchInfo interfaces.InfoFunc) (interfaces.CNSIRecord, error) {
                log.Debug("DoRegisterEndpoint")
            
                if len(cnsiName) == 0 || len(apiEndpoint) == 0 {
                    return interfaces.CNSIRecord{}, interfaces.NewHTTPShadowError(
            Severity: Major
            Found in src/jetstream/cnsi.go - About 1 hr to fix

              Method portalProxy.updateEndpoint has 9 return statements (exceeds 4 allowed).
              Open

              func (p *portalProxy) updateEndpoint(ec echo.Context) error {
                  log.Debug("updateEndpoint")
              
                  params := new(interfaces.UpdateEndpointParams)
                  if err := ec.Bind(params); err != nil {
              Severity: Major
              Found in src/jetstream/cnsi.go - About 55 mins to fix

                Avoid deeply nested control flow statements.
                Open

                                    if err != nil {
                                        if ok, detail := isSSLRelatedError(err); ok {
                                            return interfaces.NewHTTPShadowError(
                                                http.StatusForbidden,
                                                "SSL error - "+detail,
                Severity: Major
                Found in src/jetstream/cnsi.go - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                                      if err != nil {
                                          return fmt.Errorf("Can not get endpoint type for %s: '%v'", endpoint.CNSIType, err)
                                      }
                  Severity: Major
                  Found in src/jetstream/cnsi.go - About 45 mins to fix

                    Method portalProxy.buildCNSIList has 6 return statements (exceeds 4 allowed).
                    Open

                    func (p *portalProxy) buildCNSIList(c echo.Context) ([]*interfaces.CNSIRecord, error) {
                        log.Debug("buildCNSIList")
                    
                        if p.GetConfig().UserEndpointsEnabled != config.UserEndpointsConfigEnum.Disabled {
                            userID, err := p.GetSessionValue(c, "user_id")
                    Severity: Major
                    Found in src/jetstream/cnsi.go - About 40 mins to fix

                      Method portalProxy.listRegisteredCNSIs has 5 return statements (exceeds 4 allowed).
                      Open

                      func (p *portalProxy) listRegisteredCNSIs(c echo.Context) error {
                          log.Debug("listRegisteredCNSIs")
                          userGUIDIntf, err := p.GetSessionValue(c, "user_id")
                          if err != nil {
                              return interfaces.NewHTTPShadowError(
                      Severity: Major
                      Found in src/jetstream/cnsi.go - About 35 mins to fix

                        TODO found
                        Open

                        // TODO (wchrisjohnson) We need do this as a TRANSACTION, vs a set of single calls
                        Severity: Minor
                        Found in src/jetstream/cnsi.go by fixme

                        There are no issues that match your filters.

                        Category
                        Status