kuasha/cosmos

View on GitHub
cosmos/service/auth.py

Summary

Maintainability
D
2 days
Test Coverage

File auth.py has 380 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/auth.py - About 5 hrs to fix

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

        def _authenticate_user(self, user_identity):
            self.current_identity = user_identity
    
            identity_type = user_identity.get("identity_type", None)
    
    
    Severity: Minor
    Found in cosmos/service/auth.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 post has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

        def post(self):
            username = self.get_argument("username", default=None)
            password = self.get_argument("password", default=None)
            redirect_url = self.get_argument("next", default='/')
    
    
    Severity: Minor
    Found in cosmos/service/auth.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 before_user_insert has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

    def before_user_insert(object_service, object_name, data, access_type):
        assert isinstance(hmac_key, object)
        assert object_name == COSMOS_USERS_OBJECT_NAME
        assert isinstance(data, dict)
        assert access_type == AccessType.INSERT or access_type == AccessType.UPDATE
    Severity: Minor
    Found in cosmos/service/auth.py - 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

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

            if self.get_argument('code', False):
                # The url must match what was used during authorize phase.
                # It can not accept if there is any mismatch including parameters
                user = yield self.get_authenticated_user(redirect_uri=urls, code=self.get_argument('code'))
    
    
    Severity: Major
    Found in cosmos/service/auth.py and 1 other location - About 4 hrs to fix
    cosmos/service/auth.py on lines 257..267

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

    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 self.get_argument('code', False):
                # The url must match what was used during authorize phase.
                # It can not accept if there is any mismatch including parameters
                user = yield self.get_authenticated_user(redirect_uri=urls, code=self.get_argument('code'))
    
    
    Severity: Major
    Found in cosmos/service/auth.py and 1 other location - About 4 hrs to fix
    cosmos/service/auth.py on lines 318..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 83.

    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(yield cursor.fetch_next):
                user = cursor.next_object()
                if user:
                    raise tornado.web.HTTPError(409, "Conflict: Duplicate username")
    Severity: Minor
    Found in cosmos/service/auth.py and 1 other location - About 35 mins to fix
    cosmos/processors/__init__.py on lines 39..42

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

    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

            elif identity_type == IDENTITY_TYPE_GITHUB_OAUTH2:
                gh_userid = user_identity["id"]
                query={"id": gh_userid, "identity_type": IDENTITY_TYPE_GITHUB_OAUTH2}
                columns = ["identity_type", "id", "user_id"]
    Severity: Minor
    Found in cosmos/service/auth.py and 1 other location - About 30 mins to fix
    cosmos/service/auth.py on lines 132..135

    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 identity_type == IDENTITY_TYPE_FB_GRAPH:
                fb_userid = user_identity["id"]
                query={"id": fb_userid, "identity_type": IDENTITY_TYPE_FB_GRAPH}
                columns = ["identity_type", "id", "user_id"]
    Severity: Minor
    Found in cosmos/service/auth.py and 1 other location - About 30 mins to fix
    cosmos/service/auth.py on lines 142..145

    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

    There are no issues that match your filters.

    Category
    Status