saltstack/salt

View on GitHub
salt/netapi/rest_cherrypy/app.py

Summary

Maintainability
F
1 wk
Test Coverage

File app.py has 2181 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# encoding: utf-8
'''
A REST API for Salt
===================

Severity: Major
Found in salt/netapi/rest_cherrypy/app.py - About 6 days to fix

    Function exec_lowstate has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
    Open

        def exec_lowstate(self, client=None, token=None):
            '''
            Pull a Low State data structure from request and execute the low-data
            chunks through Salt. The low-data chunks will be updated to include the
            authorization token for the current session.
    Severity: Minor
    Found in salt/netapi/rest_cherrypy/app.py - 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

    Function salt_api_acl_tool has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
    Open

    def salt_api_acl_tool(username, request):
        '''
        ..versionadded:: 2016.3.0
    
        Verifies user requests against the API whitelist. (User/IP pair)
    Severity: Minor
    Found in salt/netapi/rest_cherrypy/app.py - 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

    Function GET has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
    Open

        def GET(self, token=None, **kwargs):
            '''
            Return a websocket connection of Salt's event stream
    
            .. http:get:: /ws/(token)
    Severity: Minor
    Found in salt/netapi/rest_cherrypy/app.py - 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 POST has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
    Open

        def POST(self, **kwargs):
            '''
            :ref:`Authenticate  <rest_cherrypy-auth>` against Salt's eauth system
    
            .. http:post:: /login
    Severity: Minor
    Found in salt/netapi/rest_cherrypy/app.py - 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 hypermedia_handler has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

    def hypermedia_handler(*args, **kwargs):
        '''
        Determine the best output format based on the Accept header, execute the
        regular handler, and transform the output to the request content type (even
        if it's an error).
    Severity: Minor
    Found in salt/netapi/rest_cherrypy/app.py - 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

    Function GET has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

        def GET(self, jid=None, timeout=''):
            '''
            A convenience URL for getting lists of previously run jobs or getting
            the return from a single job
    
    
    Severity: Minor
    Found in salt/netapi/rest_cherrypy/app.py - 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

    Function salt_ip_verify_tool has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

    def salt_ip_verify_tool():
        '''
        If there is a list of restricted IPs, verify current
        client is coming from one of those IPs.
        '''
    Severity: Minor
    Found in salt/netapi/rest_cherrypy/app.py - 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

    Avoid too many return statements within this function.
    Open

            return True
    Severity: Major
    Found in salt/netapi/rest_cherrypy/app.py - About 30 mins to fix

      Avoid too many return statements within this function.
      Open

                      return False
      Severity: Major
      Found in salt/netapi/rest_cherrypy/app.py - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

                    return
        Severity: Major
        Found in salt/netapi/rest_cherrypy/app.py - About 30 mins to fix

          Function get_conf has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              def get_conf(self):
                  '''
                  Combine the CherryPy configuration with the rest_cherrypy config values
                  pulled from the master config and return the CherryPy configuration
                  '''
          Severity: Minor
          Found in salt/netapi/rest_cherrypy/app.py - 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

          Function html_override_tool has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

          def html_override_tool():
              '''
              Bypass the normal handler and serve HTML for all URLs
          
              The ``app_path`` setting must be non-empty and the request must ask for
          Severity: Minor
          Found in salt/netapi/rest_cherrypy/app.py - 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

          Function cors_tool has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

          def cors_tool():
              '''
              Handle both simple and complex CORS requests
          
              Add CORS headers to each response. If the request is a CORS preflight
          Severity: Minor
          Found in salt/netapi/rest_cherrypy/app.py - 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

                          if 'groups' in token and token['groups']:
                              user_groups = set(token['groups'])
                              eauth_groups = set([i.rstrip('%') for i in eauth.keys() if i.endswith('%')])
          
                              for group in user_groups & eauth_groups:
          Severity: Major
          Found in salt/netapi/rest_cherrypy/app.py and 1 other location - About 5 hrs to fix
          salt/netapi/rest_tornado/saltnado.py on lines 751..756

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

          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 six.PY2:
                  body = entity.fp.read()
              else:
                  # https://github.com/cherrypy/cherrypy/pull/1572
                  contents = BytesIO()
          Severity: Major
          Found in salt/netapi/rest_cherrypy/app.py and 1 other location - About 3 hrs to fix
          salt/netapi/rest_cherrypy/app.py on lines 1029..1036

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

          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 six.PY2:
                  body = entity.fp.read()
              else:
                  # https://github.com/cherrypy/cherrypy/pull/1572
                  contents = BytesIO()
          Severity: Major
          Found in salt/netapi/rest_cherrypy/app.py and 1 other location - About 3 hrs to fix
          salt/netapi/rest_cherrypy/app.py on lines 1003..1010

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

          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

                      event = salt.utils.event.get_event(
                              'master',
                              sock_dir=self.opts['sock_dir'],
                              transport=self.opts['transport'],
                              opts=self.opts,
          Severity: Major
          Found in salt/netapi/rest_cherrypy/app.py and 1 other location - About 1 hr to fix
          salt/netapi/rest_cherrypy/app.py on lines 2365..2369

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

          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

                      event = salt.utils.event.get_event(
                              'master',
                              sock_dir=self.opts['sock_dir'],
                              transport=self.opts['transport'],
                              opts=self.opts,
          Severity: Major
          Found in salt/netapi/rest_cherrypy/app.py and 1 other location - About 1 hr to fix
          salt/netapi/rest_cherrypy/app.py on lines 2538..2542

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

          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 'token' in chunk:
                          # Make sure that auth token is hex
                          try:
                              int(chunk['token'], 16)
                          except (TypeError, ValueError):
          Severity: Major
          Found in salt/netapi/rest_cherrypy/app.py and 1 other location - About 1 hr to fix
          salt/netapi/rest_cherrypy/app.py on lines 1179..1184

          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

                      if 'token' in chunk:
                          # Make sure that auth token is hex
                          try:
                              int(chunk['token'], 16)
                          except (TypeError, ValueError):
          Severity: Major
          Found in salt/netapi/rest_cherrypy/app.py and 1 other location - About 1 hr to fix
          salt/netapi/rest_cherrypy/app.py on lines 1186..1191

          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

                  if 'arg' in data and not isinstance(data['arg'], list):  # pylint: disable=unsupported-membership-test
                      data['arg'] = [data['arg']]
          Severity: Major
          Found in salt/netapi/rest_cherrypy/app.py and 1 other location - About 1 hr to fix
          salt/netapi/rest_cherrypy/app.py on lines 1198..1199

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

          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 'arg' in chunk and not isinstance(chunk['arg'], list):
                          chunk['arg'] = [chunk['arg']]
          Severity: Major
          Found in salt/netapi/rest_cherrypy/app.py and 1 other location - About 1 hr to fix
          salt/netapi/rest_cherrypy/app.py on lines 1094..1095

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

          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