saltstack/salt

View on GitHub
salt/modules/capirca_acl.py

Summary

Maintainability
F
1 wk
Test Coverage

File capirca_acl.py has 1026 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# -*- coding: utf-8 -*-
'''
Capirca ACL
===========

Severity: Major
Found in salt/modules/capirca_acl.py - About 2 days to fix

    Function _clean_term_opts has a Cognitive Complexity of 40 (exceeds 5 allowed). Consider refactoring.
    Open

    def _clean_term_opts(term_opts):
        '''
        Cleanup the term opts:
    
        - strip Null and empty valuee, defaulting their value to their base definition from _TERM_FIELDS
    Severity: Minor
    Found in salt/modules/capirca_acl.py - About 6 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 _make_it_list has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
    Open

    def _make_it_list(dict_, field_name, value):
        '''
        Return the object list.
        '''
        prev_value = []
    Severity: Minor
    Found in salt/modules/capirca_acl.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 _revision_tag has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
    Open

    def _revision_tag(text,
                      revision_id=None,
                      revision_no=None,
                      revision_date=True,
                      revision_date_format='%Y/%m/%d'):
    Severity: Minor
    Found in salt/modules/capirca_acl.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

    Cyclomatic complexity is too high in function _clean_term_opts. (21)
    Open

    def _clean_term_opts(term_opts):
        '''
        Cleanup the term opts:
    
        - strip Null and empty valuee, defaulting their value to their base definition from _TERM_FIELDS
    Severity: Minor
    Found in salt/modules/capirca_acl.py by radon

    Cyclomatic Complexity

    Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

    Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

    Construct Effect on CC Reasoning
    if +1 An if statement is a single decision.
    elif +1 The elif statement adds another decision.
    else +0 The else statement does not cause a new decision. The decision is at the if.
    for +1 There is a decision at the start of the loop.
    while +1 There is a decision at the while statement.
    except +1 Each except branch adds a new conditional path of execution.
    finally +0 The finally block is unconditionally executed.
    with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
    assert +1 The assert statement internally roughly equals a conditional statement.
    Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
    Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

    Source: http://radon.readthedocs.org/en/latest/intro.html

    Function _merge_list_of_dict has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

    def _merge_list_of_dict(first, second, prepend=True):
        '''
        Merge lists of dictionaries.
        Each element of the list is a dictionary having one single key.
        That key is then used as unique lookup.
    Severity: Minor
    Found in salt/modules/capirca_acl.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_policy_object has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

    def _get_policy_object(platform,
                           filters=None,
                           pillar_key='acl',
                           pillarenv=None,
                           saltenv=None,
    Severity: Minor
    Found in salt/modules/capirca_acl.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 _import_platform_generator has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

    def _import_platform_generator(platform):
        '''
        Given a specific platform (under the Capirca conventions),
        return the generator class.
        The generator class is identified looking under the <platform> module
    Severity: Minor
    Found in salt/modules/capirca_acl.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_services_mapping has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

    def _get_services_mapping():
        '''
        Build a map of services based on the IANA assignment list:
        http://www.iana.org/assignments/port-numbers
    
    
    Severity: Minor
    Found in salt/modules/capirca_acl.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 deeply nested control flow statements.
    Open

                        if six.PY2:
                            addr = six.text_type(addr)
                            # Adding this, as ipaddress would complain about valid
                            # addresses not being valid. #pythonIsFun
                        ip_values.append(capirca.lib.policy.nacaddr.IP(addr))
    Severity: Major
    Found in salt/modules/capirca_acl.py - About 45 mins to fix

      Function _lookup_element has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

      def _lookup_element(lst, key):
          '''
          Find an dictionary in a list of dictionaries, given its main key.
          '''
          if not lst:
      Severity: Minor
      Found in salt/modules/capirca_acl.py - About 35 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 list(set(prev_value + [value]))
      Severity: Major
      Found in salt/modules/capirca_acl.py - About 30 mins to fix

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

        def get_filter_config(platform,
                              filter_name,
                              filter_options=None,
                              terms=None,
                              prepend=True,
        Severity: Minor
        Found in salt/modules/capirca_acl.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

                elif field == 'destination_service' and value:
                    if isinstance(value, six.string_types):
                        value = _make_it_list(clean_opts, field, value)
                    log.debug('Processing special destination services:')
                    log.debug(value)
        Severity: Major
        Found in salt/modules/capirca_acl.py and 1 other location - About 1 day to fix
        salt/modules/capirca_acl.py on lines 336..354

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

        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 field == 'source_service' and value:
                    if isinstance(value, six.string_types):
                        value = _make_it_list(clean_opts, field, value)
                    log.debug('Processing special source services:')
                    log.debug(value)
        Severity: Major
        Found in salt/modules/capirca_acl.py and 1 other location - About 1 day to fix
        salt/modules/capirca_acl.py on lines 355..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 168.

        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

            return get_filter_config(platform,
                                     filter_name,
        Severity: Minor
        Found in salt/modules/capirca_acl.py and 1 other location - About 40 mins to fix
        salt/modules/lxc.py on lines 3768..3769

        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