cloudfoundry-incubator/stratos

View on GitHub

Showing 1,111 of 1,370 total issues

Method PostgresCNSIRepository.listBy has 6 return statements (exceeds 4 allowed).
Open

func (p *PostgresCNSIRepository) listBy(query string, match string, encryptionKey []byte) ([]*interfaces.CNSIRecord, error) {
    rows, err := p.db.Query(query, match)
    if err != nil {
        return nil, fmt.Errorf("Unable to retrieve CNSI records: %v", err)
    }
Severity: Major
Found in src/jetstream/repository/cnsis/pgsql_cnsis.go - About 40 mins to fix

    Method ConsoleConfigRepository.GetConsoleConfig has 6 return statements (exceeds 4 allowed).
    Open

    func (c *ConsoleConfigRepository) GetConsoleConfig() (*interfaces.ConsoleConfig, error) {
        log.Debug("Get ConsoleConfig")
        rows, err := c.db.Query(getConsoleConfig)
        if err != nil {
            return nil, fmt.Errorf("Unable to retrieve console config record: %v", err)
    Severity: Major
    Found in src/jetstream/repository/console_config/psql_console_config.go - About 40 mins to fix

      Consider simplifying this complex logical expression.
      Open

          if (isAdmin) {
            const allCfUsersAction = this.createCfGetAllUsersAction(cfGuid);
      
            if (!orgGuid) {
              return observableOf(allCfUsersAction);

        Method PgsqlTokenRepository.FindAllCNSITokenBackup has 6 return statements (exceeds 4 allowed).
        Open

        func (p *PgsqlTokenRepository) FindAllCNSITokenBackup(cnsiGUID string, encryptionKey []byte) ([]interfaces.BackupTokenRecord, error) {
            log.Debug("FindAllCNSITokenBackup")
            if cnsiGUID == "" {
                msg := "Unable to find CNSI Token without a valid CNSI GUID."
                log.Debug(msg)
        Severity: Major
        Found in src/jetstream/repository/tokens/pgsql_tokens.go - About 40 mins to fix

          Consider simplifying this complex logical expression.
          Open

              if (!secrets ||
                !secrets.consoleUsers || !secrets.consoleUsers.admin || !secrets.consoleUsers.nonAdmin ||
                !secrets.endpoints || !secrets.endpoints.cf
              ) {
                throw new Error(`Failed to validate secrets`);
          Severity: Major
          Found in src/test-e2e/helpers/secrets-helpers.ts - About 40 mins to fix

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

            package analysis
            
            import (
                "database/sql"
                "strings"
            Severity: Minor
            Found in src/jetstream/plugins/analysis/20200210105400_Analysis.go and 1 other location - About 40 mins to fix
            src/jetstream/plugins/analysis/20201005105400_AnalysisUpstream.go on lines 1..52

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

            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 2 locations. Consider refactoring.
            Open

            package analysis
            
            import (
                "database/sql"
                "strings"
            src/jetstream/plugins/analysis/20200210105400_Analysis.go on lines 1..52

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

            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

            Consider simplifying this complex logical expression.
            Open

              if (ep.provider && ep.provider.metadata && ep.provider.metadata && ep.provider.metadata.metrics_stratos
                && Array.isArray(ep.provider.metadata.metrics_stratos)) {
                ep.provider.metadata.metrics_stratos.forEach(endp => {
                  // See if we already know about this endpoint
                  const hasEndpoint = data.findIndex(i => compareUrl(i.url, endp.url) || compareUrl(i.url, endp.cfEndpoint)) !== -1;
            Severity: Major
            Found in src/frontend/packages/core/src/features/metrics/metrics.helpers.ts - About 40 mins to fix

              Consider simplifying this complex logical expression.
              Open

                  if (dsEndpointType || onlyConnected) {
                    transformEntities.push((entities: EndpointModel[]) => {
                      return dsEndpointType || onlyConnected ? entities.filter(endpoint => {
                        return (!onlyConnected || endpoint.connectionStatus === 'connected') &&
                          (!dsEndpointType || endpoint.cnsi_type === dsEndpointType);

                Function start has 5 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                func start(config interfaces.PortalConfig, p *portalProxy, needSetupMiddleware bool, isUpgrade bool, envLookup *env.VarSet) error {
                Severity: Minor
                Found in src/jetstream/main.go - About 35 mins to fix

                  Function initSessionStore has 5 arguments (exceeds 4 allowed). Consider refactoring.
                  Open

                  func initSessionStore(db *sql.DB, databaseProvider string, pc interfaces.PortalConfig, sessionExpiry int, env *env.VarSet) (HttpSessionStore, *sessions.Options, error) {
                  Severity: Minor
                  Found in src/jetstream/main.go - About 35 mins to fix

                    Function newPortalProxy has 5 arguments (exceeds 4 allowed). Consider refactoring.
                    Open

                    func newPortalProxy(pc interfaces.PortalConfig, dcp *sql.DB, ss HttpSessionStore, sessionStoreOptions *sessions.Options, env *env.VarSet) *portalProxy {
                    Severity: Minor
                    Found in src/jetstream/main.go - About 35 mins to fix

                      Method portalProxy.login has 5 arguments (exceeds 4 allowed). Consider refactoring.
                      Open

                      func (p *portalProxy) login(c echo.Context, skipSSLValidation bool, client string, clientSecret string, endpoint string) (uaaRes *interfaces.UAAResponse, u *interfaces.JWTUserTokenInfo, err error) {
                      Severity: Minor
                      Found in src/jetstream/auth.go - About 35 mins to fix

                        Method portalProxy.DoProxySingleRequestWithToken has 5 arguments (exceeds 4 allowed). Consider refactoring.
                        Open

                        func (p *portalProxy) DoProxySingleRequestWithToken(cnsiGUID string, token *interfaces.TokenRecord, method, requestURL string, headers http.Header, body []byte) (*interfaces.CNSIRequest, error) {
                        Severity: Minor
                        Found in src/jetstream/passthrough.go - About 35 mins to fix

                          Function handleSessionError has 5 arguments (exceeds 4 allowed). Consider refactoring.
                          Open

                          func handleSessionError(config interfaces.PortalConfig, c echo.Context, err error, doNotLog bool, msg string) error {
                          Severity: Minor
                          Found in src/jetstream/middleware.go - About 35 mins to fix

                            Function updatePermission has 5 arguments (exceeds 4 allowed). Consider refactoring.
                            Open

                              user: CfUser,
                              entityGuid: string,
                              isSpace: boolean,
                              permissionType: OrgUserRoleNames | SpaceUserRoleNames,
                              add = false) {

                              Method CertKubeAuth.DoFlowRequest has a Cognitive Complexity of 10 (exceeds 8 allowed). Consider refactoring.
                              Open

                              func (c *CertKubeAuth) DoFlowRequest(cnsiRequest *interfaces.CNSIRequest, req *http.Request) (*http.Response, error) {
                                  log.Debug("doCertAuthFlowRequest")
                              
                                  authHandler := func(tokenRec interfaces.TokenRecord, cnsi interfaces.CNSIRecord) (*http.Response, error) {
                              
                              
                              Severity: Minor
                              Found in src/jetstream/plugins/kubernetes/auth/cert.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

                              Function getKubeDashboardSecretToken has a Cognitive Complexity of 10 (exceeds 8 allowed). Consider refactoring.
                              Open

                              func getKubeDashboardSecretToken(p interfaces.PortalProxy, cnsiGUID, userGUID string, sa *v1.ServiceAccount) (string, error) {
                                  log.Debug("getKubeDashboardSecretToken request")
                              
                                  namespace := sa.Namespace
                              
                              
                              Severity: Minor
                              Found in src/jetstream/plugins/kubernetes/dashboard/common.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 OIDCKubeAuth.GetOIDCConfig has 5 return statements (exceeds 4 allowed).
                              Open

                              func (c *OIDCKubeAuth) GetOIDCConfig(k *config.KubeConfigUser) (*KubeConfigAuthProviderOIDC, error) {
                              
                                  if k.User.AuthProvider.Name != "oidc" {
                                      return nil, errors.New("User doesn't use OIDC")
                                  }
                              Severity: Major
                              Found in src/jetstream/plugins/kubernetes/auth/oidc.go - About 35 mins to fix

                                Method LocalUserInfo.UpdateUserInfo has 5 return statements (exceeds 4 allowed).
                                Open

                                func (userInfo *LocalUserInfo) UpdateUserInfo(profile *uaaUser) (int, error) {
                                
                                    // Fetch the user, make updates and save
                                    id := profile.ID
                                    localUsersRepo, err := localusers.NewPgsqlLocalUsersRepository(userInfo.portalProxy.GetDatabaseConnection())
                                Severity: Major
                                Found in src/jetstream/plugins/userinfo/local_user.go - About 35 mins to fix
                                  Severity
                                  Category
                                  Status
                                  Source
                                  Language