kuasha/cosmos

View on GitHub
cosmos/service/oauth2service.py

Summary

Maintainability
F
3 days
Test Coverage

File oauth2service.py has 268 lines of code (exceeds 250 allowed). Consider refactoring.
Open

"""
 Copyright (C) 2014 Maruf Maniruzzaman
 Website: http://cosmosframework.com
 Author: Maruf Maniruzzaman
 License :: OSI Approved :: MIT License
Severity: Minor
Found in cosmos/service/oauth2service.py - About 2 hrs to fix

    Function _do_token has 48 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def _do_token(self, requesting_user, params):
            code = params.get("code", None)
            grant_type = params.get("grant_type", None)
            redirect_uri = params.get("redirect_uri", None)
            resource = params.get("resource", None)
    Severity: Minor
    Found in cosmos/service/oauth2service.py - About 1 hr to fix

      Function _do_token has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

          def _do_token(self, requesting_user, params):
              code = params.get("code", None)
              grant_type = params.get("grant_type", None)
              redirect_uri = params.get("redirect_uri", None)
              resource = params.get("resource", None)
      Severity: Minor
      Found in cosmos/service/oauth2service.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 _do_authorize has 36 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def _do_authorize(self, user, params):
              response_type = params.get("response_type", None)
              if not "code" == response_type:
                  raise OAuth2RequestException("Response type must be code")
      
      
      Severity: Minor
      Found in cosmos/service/oauth2service.py - About 1 hr to fix

        Function get has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

            def get(self, tenant_id, function):
                try:
                    req_id = None
                    auth_request = None
                    serve_request = self.get_argument("serve_request", None)
        Severity: Minor
        Found in cosmos/service/oauth2service.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

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

            @gen.coroutine
            def load_user(self, user_id):
                obj_serv = self.settings['object_service']
                cursor = obj_serv.load(SYSTEM_USER, COSMOS_USERS_OBJECT_NAME, user_id, [])
                user = yield cursor
        Severity: Major
        Found in cosmos/service/oauth2service.py and 2 other locations - About 2 hrs to fix
        cosmos/service/oauth2service.py on lines 302..307
        cosmos/service/oauth2service.py on lines 323..328

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

        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

            @gen.coroutine
            def load_auth_request(self, req_id):
                obj_serv = self.settings['object_service']
                cursor = obj_serv.load(SYSTEM_USER, OAUTH2_REQUESTS_OBJECT_NAME, req_id, [])
                request = yield cursor
        Severity: Major
        Found in cosmos/service/oauth2service.py and 2 other locations - About 2 hrs to fix
        cosmos/service/oauth2service.py on lines 323..328
        cosmos/service/oauth2service.py on lines 330..335

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

        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

            @gen.coroutine
            def load_code_status(self, code_status_id):
                obj_serv = self.settings['object_service']
                promise = obj_serv.load(SYSTEM_USER, OAUTH2_CODE_STATUS_OBJECT_NAME, code_status_id, [])
                code_status = yield promise
        Severity: Major
        Found in cosmos/service/oauth2service.py and 2 other locations - About 2 hrs to fix
        cosmos/service/oauth2service.py on lines 302..307
        cosmos/service/oauth2service.py on lines 330..335

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

        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

            @gen.coroutine
            def insert_auth_request(self, params):
                obj_serv = self.settings['object_service']
                promise = obj_serv.insert(SYSTEM_USER, OAUTH2_REQUESTS_OBJECT_NAME, params)
                req_id = yield promise
        Severity: Major
        Found in cosmos/service/oauth2service.py and 2 other locations - About 2 hrs to fix
        cosmos/service/oauth2service.py on lines 309..314
        cosmos/service/oauth2service.py on lines 316..321

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

        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

            @gen.coroutine
            def insert_code_status(self, response):
                obj_serv = self.settings['object_service']
                promise = obj_serv.insert(SYSTEM_USER, OAUTH2_CODE_STATUS_OBJECT_NAME, response)
                code_status_id = yield promise
        Severity: Major
        Found in cosmos/service/oauth2service.py and 2 other locations - About 2 hrs to fix
        cosmos/service/oauth2service.py on lines 295..300
        cosmos/service/oauth2service.py on lines 316..321

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

        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

            @gen.coroutine
            def update_code_status(self, code_status):
                obj_serv = self.settings['object_service']
                promise = obj_serv.save(SYSTEM_USER, OAUTH2_CODE_STATUS_OBJECT_NAME, code_status)
                code_status_id = yield promise
        Severity: Major
        Found in cosmos/service/oauth2service.py and 2 other locations - About 2 hrs to fix
        cosmos/service/oauth2service.py on lines 295..300
        cosmos/service/oauth2service.py on lines 309..314

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

        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

            def get_private_key_handler(self):
                oauth2_settings = self.settings['oauth2_settings']
                oauth2_private_key_pem = oauth2_settings.get("oauth2_private_key_pem")
                oauth2_private_key_handler = RSA.importKey(oauth2_private_key_pem)
                return oauth2_private_key_handler
        Severity: Major
        Found in cosmos/service/oauth2service.py and 1 other location - About 1 hr to fix
        cosmos/service/oauth2service.py on lines 273..277

        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

            def get_public_key_handler(self):
                oauth2_settings = self.settings['oauth2_settings']
                oauth2_public_key_pem = oauth2_settings.get("oauth2_public_key_pem")
                oauth2_public_key_handler = RSA.importKey(oauth2_public_key_pem)
                return oauth2_public_key_handler
        Severity: Major
        Found in cosmos/service/oauth2service.py and 1 other location - About 1 hr to fix
        cosmos/service/oauth2service.py on lines 279..283

        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

        There are no issues that match your filters.

        Category
        Status