Katello/katello

View on GitHub
app/controllers/katello/api/v2/repositories_controller.rb

Summary

Maintainability
F
4 days
Test Coverage

File repositories_controller.rb has 654 lines of code (exceeds 250 allowed). Consider refactoring.
Open

module Katello
  class Api::V2::RepositoriesController < Api::V2::ApiController # rubocop:disable Metrics/ClassLength
    include Katello::Concerns::FilteredAutoCompleteSearch

    generic_repo_wrap_params = []
Severity: Major
Found in app/controllers/katello/api/v2/repositories_controller.rb - About 1 day to fix

    Class RepositoriesController has 39 methods (exceeds 20 allowed). Consider refactoring.
    Open

      class Api::V2::RepositoriesController < Api::V2::ApiController # rubocop:disable Metrics/ClassLength
        include Katello::Concerns::FilteredAutoCompleteSearch
    
        generic_repo_wrap_params = []
        RepositoryTypeManager.generic_remote_options(defined_only: true).each do |option|
    Severity: Minor
    Found in app/controllers/katello/api/v2/repositories_controller.rb - About 5 hrs to fix

      Method construct_repo_from_params has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
      Open

          def construct_repo_from_params(repo_params) # rubocop:disable Metrics/AbcSize
            root = @product.add_repo(repo_params.slice(:label, :name, :description, :url, :content_type, :arch, :unprotected,
                                                                  :gpg_key, :ssl_ca_cert, :ssl_client_cert, :ssl_client_key,
                                                                  :checksum_type, :download_policy, :http_proxy_policy,
                                                                  :metadata_expire).to_h.with_indifferent_access)
      Severity: Minor
      Found in app/controllers/katello/api/v2/repositories_controller.rb - 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 construct_repo_from_params has 36 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def construct_repo_from_params(repo_params) # rubocop:disable Metrics/AbcSize
            root = @product.add_repo(repo_params.slice(:label, :name, :description, :url, :content_type, :arch, :unprotected,
                                                                  :gpg_key, :ssl_ca_cert, :ssl_client_cert, :ssl_client_key,
                                                                  :checksum_type, :download_policy, :http_proxy_policy,
                                                                  :metadata_expire).to_h.with_indifferent_access)
      Severity: Minor
      Found in app/controllers/katello/api/v2/repositories_controller.rb - About 1 hr to fix

        Method upload_content has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

            def upload_content
              fail Katello::Errors::InvalidRepositoryContent, _("Cannot upload Container Image content.") if @repository.docker?
              fail Katello::Errors::InvalidRepositoryContent, _("Cannot upload Ansible collections.") if @repository.ansible_collection?
              unless params[:content_type].empty? || RepositoryTypeManager.uploadable_content_types.map(&:label).include?(params[:content_type])
                msg = _("Invalid params provided - content_type must be one of %s") %
        Severity: Minor
        Found in app/controllers/katello/api/v2/repositories_controller.rb - About 1 hr 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 repository_params has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

            def repository_params
              keys = [:download_policy, :mirroring_policy, :sync_policy, :arch, :verify_ssl_on_sync, :upstream_password,
                      :upstream_username, :download_concurrency, :metadata_expire,
                      {:os_versions => []}, :deb_releases, :deb_components, :deb_architectures, :description,
                      :http_proxy_policy, :http_proxy_id, :retain_package_versions_count, {:ignorable_content => []}
        Severity: Minor
        Found in app/controllers/katello/api/v2/repositories_controller.rb - About 1 hr 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 index has 31 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def index
              unless params[:content_type].empty? || RepositoryTypeManager.find(params[:content_type])
                msg = _("Invalid params provided - content_type must be one of %s") %
                  RepositoryTypeManager.enabled_repository_types.keys.sort.join(",")
                fail HttpErrors::UnprocessableEntity, msg
        Severity: Minor
        Found in app/controllers/katello/api/v2/repositories_controller.rb - About 1 hr to fix

          Method import_uploads has 28 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              def import_uploads
                generate_metadata = ::Foreman::Cast.to_bool(params.fetch(:publish_repository, true))
                sync_capsule = ::Foreman::Cast.to_bool(params.fetch(:sync_capsule, true))
                async = ::Foreman::Cast.to_bool(params.fetch(:async, false))
                if params['uploads'].empty?
          Severity: Minor
          Found in app/controllers/katello/api/v2/repositories_controller.rb - About 1 hr to fix

            Method index_relation_environment has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

                def index_relation_environment(query)
                  if params[:environment_id] && !params[:library]
                    query = query.where(:environment_id => params[:environment_id])
                  elsif params[:environment_id] && params[:library]
                    instances = query.where(:environment_id => params[:environment_id])
            Severity: Minor
            Found in app/controllers/katello/api/v2/repositories_controller.rb - About 1 hr 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 index_relation_content_unit has 26 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                def index_relation_content_unit(query)
                  if params[:deb_id]
                    query = query.joins(:debs)
                      .where("#{Deb.table_name}.id" => Deb.with_identifiers(params[:deb_id]))
                  end
            Severity: Minor
            Found in app/controllers/katello/api/v2/repositories_controller.rb - About 1 hr to fix

              Method find_content has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

                  def find_content
                    content_type = params[:content_type]
              
                    if content_type
                      RepositoryTypeManager.check_content_matches_repo_type!(@repository, params[:content_type]) if params[:content_type]
              Severity: Minor
              Found in app/controllers/katello/api/v2/repositories_controller.rb - About 55 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 import_uploads has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

                  def import_uploads
                    generate_metadata = ::Foreman::Cast.to_bool(params.fetch(:publish_repository, true))
                    sync_capsule = ::Foreman::Cast.to_bool(params.fetch(:sync_capsule, true))
                    async = ::Foreman::Cast.to_bool(params.fetch(:async, false))
                    if params['uploads'].empty?
              Severity: Minor
              Found in app/controllers/katello/api/v2/repositories_controller.rb - 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 create has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

                  def create
                    repo_params = repository_params
                    unless RepositoryTypeManager.creatable_by_user?(repo_params[:content_type], false)
                      msg = _("Invalid params provided - content_type must be one of %s") %
                        RepositoryTypeManager.creatable_repository_types.keys.sort.join(",")
              Severity: Minor
              Found in app/controllers/katello/api/v2/repositories_controller.rb - 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 filter_by_content_view has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                  def filter_by_content_view(query, content_view_id, environment_id, is_available_for)
                    if is_available_for
                      params[:library] = true
                      sub_query = ContentViewRepository.where(:content_view_id => content_view_id).pluck(:repository_id)
                      query = query.where("#{Repository.table_name}.id not in (#{sub_query.join(',')})") unless sub_query.empty?
              Severity: Minor
              Found in app/controllers/katello/api/v2/repositories_controller.rb - 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 index_relation_content_view has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                  def index_relation_content_view(query)
                    if params[:content_view_version_id]
                      query = query.where(:content_view_version_id => params[:content_view_version_id])
                      query = query.archived if ::Foreman::Cast.to_bool params[:archived]
                      query = Katello::Repository.where(:id => query.select(:library_instance_id)) if params[:library]
              Severity: Minor
              Found in app/controllers/katello/api/v2/repositories_controller.rb - About 25 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 sync has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                  def sync
                    fail HttpErrors::BadRequest, _("attempted to sync a non-library repository.") unless @repository.library_instance?
                    sync_options = {
                      :skip_metadata_check => ::Foreman::Cast.to_bool(params[:skip_metadata_check]),
                      :validate_contents => ::Foreman::Cast.to_bool(params[:validate_contents]),
              Severity: Minor
              Found in app/controllers/katello/api/v2/repositories_controller.rb - About 25 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 index_relation_content_unit has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                  def index_relation_content_unit(query)
                    if params[:deb_id]
                      query = query.joins(:debs)
                        .where("#{Deb.table_name}.id" => Deb.with_identifiers(params[:deb_id]))
                    end
              Severity: Minor
              Found in app/controllers/katello/api/v2/repositories_controller.rb - About 25 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 index has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                  def index
                    unless params[:content_type].empty? || RepositoryTypeManager.find(params[:content_type])
                      msg = _("Invalid params provided - content_type must be one of %s") %
                        RepositoryTypeManager.enabled_repository_types.keys.sort.join(",")
                      fail HttpErrors::UnprocessableEntity, msg
              Severity: Minor
              Found in app/controllers/katello/api/v2/repositories_controller.rb - About 25 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 2 locations. Consider refactoring.
              Open

                    unless params[:content_type].empty? || RepositoryTypeManager.removable_content_types.map(&:label).include?(params[:content_type])
                      msg = _("Invalid params provided - content_type must be one of %s") %
                        RepositoryTypeManager.removable_content_types.map(&:label).sort.join(",")
                      fail HttpErrors::UnprocessableEntity, msg
                    end
              Severity: Minor
              Found in app/controllers/katello/api/v2/repositories_controller.rb and 1 other location - About 30 mins to fix
              app/controllers/katello/api/v2/repositories_controller.rb on lines 449..453

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

              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

                    unless params[:content_type].empty? || RepositoryTypeManager.uploadable_content_types.map(&:label).include?(params[:content_type])
                      msg = _("Invalid params provided - content_type must be one of %s") %
                        RepositoryTypeManager.uploadable_content_types.map(&:label).sort.join(",")
                      fail HttpErrors::UnprocessableEntity, msg
                    end
              Severity: Minor
              Found in app/controllers/katello/api/v2/repositories_controller.rb and 1 other location - About 30 mins to fix
              app/controllers/katello/api/v2/repositories_controller.rb on lines 432..436

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

              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

                    if root.deb?
                      root.deb_releases = repo_params[:deb_releases] if repo_params[:deb_releases]
                      root.deb_components = repo_params[:deb_components] if repo_params[:deb_components]
                      root.deb_architectures = repo_params[:deb_architectures] if repo_params[:deb_architectures]
              Severity: Minor
              Found in app/controllers/katello/api/v2/repositories_controller.rb and 1 other location - About 25 mins to fix
              app/controllers/katello/api/v2/repositories_controller.rb on lines 656..659

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

              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

                    if root.ansible_collection?
                      root.ansible_collection_requirements = repo_params[:ansible_collection_requirements] if repo_params[:ansible_collection_requirements]
                      root.ansible_collection_auth_url = repo_params[:ansible_collection_auth_url] if repo_params[:ansible_collection_auth_url]
                      root.ansible_collection_auth_token = repo_params[:ansible_collection_auth_token] if repo_params[:ansible_collection_auth_token]
              Severity: Minor
              Found in app/controllers/katello/api/v2/repositories_controller.rb and 1 other location - About 25 mins to fix
              app/controllers/katello/api/v2/repositories_controller.rb on lines 650..653

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

              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 @versions.count != params[:content_view_version_ids].uniq.length
                      missing = params[:content_view_version_ids] - @versions.pluck(:id)
                      fail HttpErrors::NotFound, _("Couldn't find content view versions '%s'") % missing.join(',')
              Severity: Minor
              Found in app/controllers/katello/api/v2/repositories_controller.rb and 1 other location - About 20 mins to fix
              app/controllers/katello/concerns/api/v2/repository_content_controller.rb on lines 57..59

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

              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

              There are no issues that match your filters.

              Category
              Status