horizoncd/horizon

View on GitHub

Showing 676 of 677 total issues

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

func (d dao) GetByID(ctx context.Context, id uint) (*models.Template, error) {
    var template models.Template
    res := d.db.Raw(dbsql.TemplateQueryByID, id).First(&template)
    if res.Error != nil {
        if res.Error == gorm.ErrRecordNotFound {
Severity: Major
Found in pkg/template/dao/dao.go and 1 other location - About 2 hrs to fix
pkg/template/dao/dao.go on lines 102..114

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

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

func (d dao) GetByName(ctx context.Context, name string) (*models.Template, error) {
    var template models.Template
    res := d.db.Raw(dbsql.TemplateQueryByName, name).First(&template)
    if res.Error != nil {
        if res.Error == gorm.ErrRecordNotFound {
Severity: Major
Found in pkg/template/dao/dao.go and 1 other location - About 2 hrs to fix
pkg/template/dao/dao.go on lines 88..100

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

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

manager has 23 methods (exceeds 20 allowed). Consider refactoring.
Open

type manager struct {
    groupDAO       groupdao.DAO
    applicationDAO applicationdao.DAO
    envregionDAO   envregiondao.DAO
    regionDAO      regiondao.DAO
Severity: Minor
Found in pkg/group/manager/manager.go - About 2 hrs to fix

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

    func (a *API) RevokeResourceAccessToken(c *gin.Context) {
        const op = "access token: delete"
    
        accessTokenIDStr := c.Param(common.ParamAccessTokenID)
        id, err := strconv.ParseUint(accessTokenIDStr, 10, 0)
    Severity: Major
    Found in core/http/api/v2/accesstoken/apis.go and 1 other location - About 2 hrs to fix
    core/http/api/v2/accesstoken/apis.go on lines 136..155

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

    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

    func (a *API) RevokePersonalAccessToken(c *gin.Context) {
        const op = "access token: delete"
    
        accessTokenIDStr := c.Param(common.ParamAccessTokenID)
        id, err := strconv.ParseUint(accessTokenIDStr, 10, 0)
    Severity: Major
    Found in core/http/api/v2/accesstoken/apis.go and 1 other location - About 2 hrs to fix
    core/http/api/v2/accesstoken/apis.go on lines 115..134

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

    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

    Function parsePodLifeCycle has 87 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func parsePodLifeCycle(pod corev1.Pod) []*LifeCycleItem {
        var lifeCycle []*LifeCycleItem
        // if DeletionTimestamp is set, pod is Terminating
        if pod.DeletionTimestamp != nil {
            lifeCycle = []*LifeCycleItem{
    Severity: Major
    Found in pkg/cd/util.go - About 2 hrs to fix

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

      func (c *controller) checkHasOnlyOwnerPermissionForRelease(ctx context.Context,
          release *trmodels.TemplateRelease) bool {
          user, err := common.UserFromContext(ctx)
          if err != nil {
              return false
      Severity: Major
      Found in core/controller/template/controller.go and 1 other location - About 2 hrs to fix
      core/controller/template/controller.go on lines 901..927

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

      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

      func (c *controller) checkHasOnlyOwnerPermissionForTemplate(ctx context.Context,
          template *models.Template) bool {
          user, err := common.UserFromContext(ctx)
          if err != nil {
              return false
      Severity: Major
      Found in core/controller/template/controller.go and 1 other location - About 2 hrs to fix
      core/controller/template/controller.go on lines 929..955

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

      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

      Function WriteTarContents has a Cognitive Complexity of 33 (exceeds 20 allowed). Consider refactoring.
      Open

      func WriteTarContents(out *tar.Writer, c *chart.Chart, prefix string) error {
          base := filepath.Join(prefix, c.Name())
      
          // Pull out the dependencies of a v1 Chart, since there's no way
          // to tell the serializer to skip a field for just this use case
      Severity: Minor
      Found in pkg/templaterepo/chartutil.go - About 2 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 CreateClusterParamsV2.toClusterModel has a Cognitive Complexity of 33 (exceeds 20 allowed). Consider refactoring.
      Open

      func (r *CreateClusterParamsV2) toClusterModel(application *appmodels.Application,
          er *envregionmodels.EnvironmentRegion, info *BuildTemplateInfo,
          template *templatemodels.Template, expireSeconds uint) (*models.Cluster, []*tagmodels.Tag) {
          cluster := &models.Cluster{
              ApplicationID:   application.ID,
      Severity: Minor
      Found in core/controller/cluster/models_basic_v2.go - About 2 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

      Function Middleware has a Cognitive Complexity of 33 (exceeds 20 allowed). Consider refactoring.
      Open

      func Middleware(skippers ...middleware.Skipper) gin.HandlerFunc {
          return middleware.New(func(c *gin.Context) {
              // get auth record
              record, ok := c.Get(common.ContextAuthRecord)
              if !ok {
      Severity: Minor
      Found in core/middleware/admission/admission.go - About 2 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 controller.CreateApplicationV2 has 85 lines of code (exceeds 50 allowed). Consider refactoring.
      Open

      func (c *controller) CreateApplicationV2(ctx context.Context, groupID uint,
          request *CreateOrUpdateApplicationRequestV2) (*CreateApplicationResponseV2, error) {
          const op = "application controller: create application v2"
          defer wlog.Start(ctx, op).StopPrint()
      
      
      Severity: Major
      Found in core/controller/application/controller.go - About 2 hrs to fix

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

        func (h Helper) ListTag(ctx context.Context, gitURL string, params *git.SearchParams) ([]string, error) {
            pid, err := git.ExtractProjectPathFromURL(gitURL)
            if err != nil {
                return nil, err
            }
        Severity: Major
        Found in pkg/git/gitlab/gitlab.go and 1 other location - About 2 hrs to fix
        pkg/git/gitlab/gitlab.go on lines 129..150

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

        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

        func (h Helper) ListBranch(ctx context.Context, gitURL string, params *git.SearchParams) ([]string, error) {
            pid, err := git.ExtractProjectPathFromURL(gitURL)
            if err != nil {
                return nil, err
            }
        Severity: Major
        Found in pkg/git/gitlab/gitlab.go and 1 other location - About 2 hrs to fix
        pkg/git/gitlab/gitlab.go on lines 152..173

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

        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 controller.UpdateClusterV2 has 26 return statements (exceeds 4 allowed).
        Open

        func (c *controller) UpdateClusterV2(ctx context.Context, clusterID uint,
            r *UpdateClusterRequestV2, mergePatch bool) error {
            const op = "cluster controller: update cluster v2"
            defer wlog.Start(ctx, op).StopPrint()
        
        
        Severity: Major
        Found in core/controller/cluster/controller_basic_v2.go - About 2 hrs to fix

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

          func (a *API) CreateSecret(c *gin.Context) {
              const op = "CreateSecret"
              oauthAppClientIDStr := c.Param(_oauthAppClientIDParam)
              secret, err := a.oauthAppController.CreateSecret(c, oauthAppClientIDStr)
              if err != nil {
          Severity: Major
          Found in core/http/api/v2/oauthapp/apis.go and 1 other location - About 2 hrs to fix
          core/http/api/v2/oauthapp/apis.go on lines 146..162

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

          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

          func (a *API) ListSecret(c *gin.Context) {
              const op = "ListSecret"
              oauthAppClientIDStr := c.Param(_oauthAppClientIDParam)
              secrets, err := a.oauthAppController.ListSecret(c, oauthAppClientIDStr)
              if err != nil {
          Severity: Major
          Found in core/http/api/v2/oauthapp/apis.go and 1 other location - About 2 hrs to fix
          core/http/api/v2/oauthapp/apis.go on lines 128..144

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

          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

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

              if err != nil {
                  if e, ok := perror.Cause(err).(*herrors.HorizonErrNotFound); ok {
                      if e.Source == herrors.GroupInDB || e.Source == herrors.ApplicationInDB {
                          response.AbortWithRPCError(c, rpcerror.NotFoundError.WithErrMsg(err.Error()))
                          return
          Severity: Major
          Found in core/http/api/v2/application/apis.go and 1 other location - About 2 hrs to fix
          core/http/api/v2/application/apis.go on lines 210..223

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

          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

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

              if err := a.applicationCtl.DeleteApplication(c, uint(appID), hard); err != nil {
                  if e, ok := perror.Cause(err).(*herrors.HorizonErrNotFound); ok {
                      if e.Source == herrors.GroupInDB || e.Source == herrors.ApplicationInDB {
                          response.AbortWithRPCError(c, rpcerror.NotFoundError.WithErrMsg(err.Error()))
                          return
          Severity: Major
          Found in core/http/api/v2/application/apis.go and 1 other location - About 2 hrs to fix
          core/http/api/v2/application/apis.go on lines 297..310

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

          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 clusterGitopsRepo.UpgradeCluster has 25 return statements (exceeds 4 allowed).
          Open

          func (g *clusterGitopsRepo) UpgradeCluster(ctx context.Context,
              param *UpgradeValuesParam) (string, error) {
              const op = "cluster git repo: upgrade cluster"
              defer wlog.Start(ctx, op).StopPrint()
              currentUser, err := common.UserFromContext(ctx)
          Severity: Major
          Found in pkg/cluster/gitrepo/gitrepo_cluster.go - About 2 hrs to fix
            Severity
            Category
            Status
            Source
            Language