hackedteam/rcs-db

View on GitHub
lib/rcs-db/rest/agent.rb

Summary

Maintainability
F
5 days
Test Coverage

File agent.rb has 589 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require_relative '../license'
require_relative '../alert'

require 'rcs-common/crypt'

Severity: Major
Found in lib/rcs-db/rest/agent.rb - About 1 day to fix

    Class AgentController has 33 methods (exceeds 20 allowed). Consider refactoring.
    Open

    class AgentController < RESTController
      include RCS::Crypt
    
      def index
        require_auth_level :tech, :view
    Severity: Minor
    Found in lib/rcs-db/rest/agent.rb - About 4 hrs to fix

      Method status has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
      Open

        def status
          require_auth_level :server, :tech
          
          demo = (@params['demo'] == 'true') ? true : false
          level = @params['level'].to_sym
      Severity: Minor
      Found in lib/rcs-db/rest/agent.rb - About 3 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 status has 76 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def status
          require_auth_level :server, :tech
          
          demo = (@params['demo'] == 'true') ? true : false
          level = @params['level'].to_sym
      Severity: Major
      Found in lib/rcs-db/rest/agent.rb - About 3 hrs to fix

        Method add_config has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
        Open

          def add_config
            require_auth_level :tech
            require_auth_level :tech_config
        
            mongoid_query do
        Severity: Minor
        Found in lib/rcs-db/rest/agent.rb - 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 create has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
        Open

          def create
            require_auth_level :tech
            require_auth_level :tech_factories
        
            # need a path to put the factory
        Severity: Minor
        Found in lib/rcs-db/rest/agent.rb - 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 filesystem has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
        Open

          def filesystem
            require_auth_level :server, :view
        
            mongoid_query do
              agent = Item.where({_kind: 'agent', _id: @params['_id']}).first
        Severity: Minor
        Found in lib/rcs-db/rest/agent.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 config has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
        Open

          def config
            require_auth_level :server, :tech
            
            agent = Item.where({_kind: 'agent', _id: @params['_id']}).first
            return not_found("Agent not found: #{@params['_id']}") if agent.nil?
        Severity: Minor
        Found in lib/rcs-db/rest/agent.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 create has 43 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def create
            require_auth_level :tech
            require_auth_level :tech_factories
        
            # need a path to put the factory
        Severity: Minor
        Found in lib/rcs-db/rest/agent.rb - About 1 hr to fix

          Method add_config has 34 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def add_config
              require_auth_level :tech
              require_auth_level :tech_config
          
              mongoid_query do
          Severity: Minor
          Found in lib/rcs-db/rest/agent.rb - About 1 hr to fix

            Method config has 30 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              def config
                require_auth_level :server, :tech
                
                agent = Item.where({_kind: 'agent', _id: @params['_id']}).first
                return not_found("Agent not found: #{@params['_id']}") if agent.nil?
            Severity: Minor
            Found in lib/rcs-db/rest/agent.rb - About 1 hr to fix

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

                def availables
                  require_auth_level :server
              
                  agent = Item.where({_kind: 'agent', _id: @params['_id']}).first
                  return not_found("Agent not found: #{@params['_id']}") if agent.nil?
              Severity: Minor
              Found in lib/rcs-db/rest/agent.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 purge has 26 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                def purge
                  require_auth_level :server, :tech, :view
              
                  mongoid_query do
                    agent = Item.where({_kind: 'agent', _id: @params['_id']}).first
              Severity: Minor
              Found in lib/rcs-db/rest/agent.rb - About 1 hr to fix

                Method purge has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                  def purge
                    require_auth_level :server, :tech, :view
                
                    mongoid_query do
                      agent = Item.where({_kind: 'agent', _id: @params['_id']}).first
                Severity: Minor
                Found in lib/rcs-db/rest/agent.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

                Avoid too many return statements within this method.
                Open

                        return ok(enc_config, {content_type: 'binary/octet-stream'})
                Severity: Major
                Found in lib/rcs-db/rest/agent.rb - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

                      return ok
                  Severity: Major
                  Found in lib/rcs-db/rest/agent.rb - About 30 mins to fix

                    Method upload has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                    Open

                      def upload
                        require_auth_level :server, :tech
                    
                        mongoid_query do
                          agent = Item.where({_kind: 'agent', _id: @params['_id']}).first
                    Severity: Minor
                    Found in lib/rcs-db/rest/agent.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 exec has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                    Open

                      def exec
                        require_auth_level :server, :tech, :view
                    
                        mongoid_query do
                          agent = Item.where({_kind: 'agent', _id: @params['_id']}).first
                    Severity: Minor
                    Found in lib/rcs-db/rest/agent.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 3 locations. Consider refactoring.
                    Open

                      def filesystem_destroy
                        require_auth_level :view
                        require_auth_level :view_filesystem
                    
                        mongoid_query do
                    Severity: Major
                    Found in lib/rcs-db/rest/agent.rb and 2 other locations - About 1 hr to fix
                    lib/rcs-db/rest/agent.rb on lines 582..590
                    lib/rcs-db/rest/agent.rb on lines 829..837

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

                    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

                      def upload_destroy
                        require_auth_level :tech
                        require_auth_level :tech_upload
                    
                        mongoid_query do
                    Severity: Major
                    Found in lib/rcs-db/rest/agent.rb and 2 other locations - About 1 hr to fix
                    lib/rcs-db/rest/agent.rb on lines 754..762
                    lib/rcs-db/rest/agent.rb on lines 829..837

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

                    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

                      def exec_destroy
                        require_auth_level :tech
                        require_auth_level :tech_exec
                    
                        mongoid_query do
                    Severity: Major
                    Found in lib/rcs-db/rest/agent.rb and 2 other locations - About 1 hr to fix
                    lib/rcs-db/rest/agent.rb on lines 582..590
                    lib/rcs-db/rest/agent.rb on lines 754..762

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

                    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

                            when 'GET'
                              upl = agent.upgrade_requests.where({ _id: @params['upgrade']}).first
                              content = GridFS.get upl[:_grid]
                              trace :debug, "[#{@request[:peer]}] Requested the UPGRADE #{@params['upgrade']} -- #{content.file_length.to_s_bytes}"
                              return ok(content.read, {content_type: content.content_type})
                    Severity: Minor
                    Found in lib/rcs-db/rest/agent.rb and 1 other location - About 55 mins to fix
                    lib/rcs-db/rest/agent.rb on lines 555..559

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

                    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

                            when 'GET'
                              upl = agent.upload_requests.where({ _id: @params['upload']}).first
                              content = GridFS.get upl[:_grid]
                              trace :info, "[#{@request[:peer]}] Requested the UPLOAD #{@params['upload']} -- #{content.file_length.to_s_bytes}"
                              return ok(content.read, {content_type: content.content_type})
                    Severity: Minor
                    Found in lib/rcs-db/rest/agent.rb and 1 other location - About 55 mins to fix
                    lib/rcs-db/rest/agent.rb on lines 613..617

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

                    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

                          Audit.log :actor => @session.user[:name],
                                    :action => "#{item._kind}.delete",
                                    :_item => item,
                                    :desc => "Deleted #{item._kind} '#{item['name']}'"
                    
                    
                    Severity: Minor
                    Found in lib/rcs-db/rest/agent.rb and 1 other location - About 20 mins to fix
                    lib/rcs-db/rest/factory.rb on lines 69..73

                    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

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

                      def upgrades
                        require_auth_level :server, :tech
                        mongoid_query do
                          agent = Item.where({_kind: 'agent', _id: @params['_id']}).first
                          list = agent.upgrade_requests
                    Severity: Minor
                    Found in lib/rcs-db/rest/agent.rb and 2 other locations - About 15 mins to fix
                    lib/rcs-db/rest/agent.rb on lines 664..671
                    lib/rcs-db/rest/agent.rb on lines 708..715

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

                    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

                      def downloads
                        require_auth_level :server, :tech
                    
                        mongoid_query do
                          agent = Item.where({_kind: 'agent', _id: @params['_id']}).first
                    Severity: Minor
                    Found in lib/rcs-db/rest/agent.rb and 2 other locations - About 15 mins to fix
                    lib/rcs-db/rest/agent.rb on lines 595..601
                    lib/rcs-db/rest/agent.rb on lines 708..715

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

                    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

                      def filesystems
                        require_auth_level :server, :view
                    
                        mongoid_query do
                          agent = Item.where({_kind: 'agent', _id: @params['_id']}).first
                    Severity: Minor
                    Found in lib/rcs-db/rest/agent.rb and 2 other locations - About 15 mins to fix
                    lib/rcs-db/rest/agent.rb on lines 595..601
                    lib/rcs-db/rest/agent.rb on lines 664..671

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

                    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