saltstack/salt

View on GitHub
salt/states/netusers.py

Summary

Maintainability
D
1 day
Test Coverage

File netusers.py has 319 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# -*- coding: utf-8 -*-
'''
Network Users
=============

Severity: Minor
Found in salt/states/netusers.py - About 3 hrs to fix

    Function managed has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
    Open

    def managed(name, users=None, defaults=None):
    
        '''
        Manages the configuration of the users on the device, as specified in the state SLS file. Users not defined in that
        file will be remove whilst users not configured on the device, will be added.
    Severity: Minor
    Found in salt/states/netusers.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 managed has 26 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    def managed(name, users=None, defaults=None):
    
        '''
        Manages the configuration of the users on the device, as specified in the state SLS file. Users not defined in that
        file will be remove whilst users not configured on the device, will be added.
    Severity: Minor
    Found in salt/states/netusers.py - About 1 hr to fix

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

      def _compute_diff(configured, expected):
      
          '''Computes the differences between the actual config and the expected config'''
      
          diff = {
      Severity: Minor
      Found in salt/states/netusers.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

      Avoid too many return statements within this function.
      Open

          return ret
      Severity: Major
      Found in salt/states/netusers.py - About 30 mins to fix

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

        def _check_users(users):
        
            '''Checks if the input dictionary of users is valid.'''
        
            messg = ''
        Severity: Minor
        Found in salt/states/netusers.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 6 locations. Consider refactoring.
        Open

            if users_to_add:
                _set = _set_users(users_to_add)
                if _set.get('result'):
                    expected_config_change = True
                else:  # something went wrong...
        Severity: Major
        Found in salt/states/netusers.py and 5 other locations - About 1 hr to fix
        salt/states/netusers.py on lines 404..411
        salt/states/netusers.py on lines 414..421
        salt/states/probes.py on lines 395..402
        salt/states/probes.py on lines 405..412
        salt/states/probes.py on lines 415..422

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

        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 6 locations. Consider refactoring.
        Open

            if users_to_remove:
                _delete = _delete_users(users_to_remove)
                if _delete.get('result'):
                    expected_config_change = True
                else:  # something went wrong...
        Severity: Major
        Found in salt/states/netusers.py and 5 other locations - About 1 hr to fix
        salt/states/netusers.py on lines 394..401
        salt/states/netusers.py on lines 404..411
        salt/states/probes.py on lines 395..402
        salt/states/probes.py on lines 405..412
        salt/states/probes.py on lines 415..422

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

        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 6 locations. Consider refactoring.
        Open

            if users_to_update:
                _update = _update_users(users_to_update)
                if _update.get('result'):
                    expected_config_change = True
                else:  # something went wrong...
        Severity: Major
        Found in salt/states/netusers.py and 5 other locations - About 1 hr to fix
        salt/states/netusers.py on lines 394..401
        salt/states/netusers.py on lines 414..421
        salt/states/probes.py on lines 395..402
        salt/states/probes.py on lines 405..412
        salt/states/probes.py on lines 415..422

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

        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 not users_output.get('result'):
                ret['comment'] = 'Cannot retrieve users from the device: {reason}'.format(
                    reason=users_output.get('comment')
                )
                return ret
        Severity: Minor
        Found in salt/states/netusers.py and 1 other location - About 40 mins to fix
        salt/states/netsnmp.py on lines 369..373

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

        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