scitran/core

View on GitHub
api/web/base.py

Summary

Maintainability
D
2 days
Test Coverage

Function initialization_auth has a Cognitive Complexity of 34 (exceeds 5 allowed). Consider refactoring.
Open

    def initialization_auth(self):
        drone_request = False
        job_context = None
        session_token = self.request.headers.get('Authorization', None)
        drone_secret = self.request.headers.get('X-SciTran-Auth', None)
Severity: Minor
Found in api/web/base.py - About 5 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

File base.py has 333 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import base64
import datetime
import jsonschema
import os
import pymongo
Severity: Minor
Found in api/web/base.py - About 4 hrs to fix

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

        def log_user_access(self, access_type, cont_name=None, cont_id=None, filename=None, multifile=False, origin_override=None):
    
            if not config.get_item('core', 'access_log_enabled'):
                return
    
    
    Severity: Minor
    Found in api/web/base.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 authenticate_user_token has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
    Open

        def authenticate_user_token(self, session_token):
            """
            AuthN for user accounts. Calls self.abort on failure.
    
            Returns the user's UID.
    Severity: Minor
    Found in api/web/base.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 handle_exception has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
    Open

        def handle_exception(self, exception, debug, return_json=False): # pylint: disable=arguments-differ
            """
            Send JSON response for exception
    
            For HTTP and other known exceptions, use its error code
    Severity: Minor
    Found in api/web/base.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 log_user_access has 6 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def log_user_access(self, access_type, cont_name=None, cont_id=None, filename=None, multifile=False, origin_override=None):
    Severity: Minor
    Found in api/web/base.py - About 45 mins to fix

      Function set_origin has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          def set_origin(self, drone_request, job_context):
              """
              Add an origin to the request object. Used later in request handler logic.
      
              Pretty clear duplication of logic with superuser_request / drone_request;
      Severity: Minor
      Found in api/web/base.py - 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

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

              try:
                  auth_provider = AuthProvider.factory(auth_type)
              except NotImplementedError as e:
                  self.abort(400, str(e))
      Severity: Minor
      Found in api/web/base.py and 1 other location - About 40 mins to fix
      api/web/base.py on lines 163..166

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

      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

                          try:
                              auth_provider = AuthProvider.factory(auth_type)
                          except NotImplementedError as e:
                              self.abort(401, str(e))
      Severity: Minor
      Found in api/web/base.py and 1 other location - About 40 mins to fix
      api/web/base.py on lines 210..213

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

      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