saltstack/salt

View on GitHub
salt/utils/dns.py

Summary

Maintainability
F
1 wk
Test Coverage

File dns.py has 1004 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# -*- coding: utf-8 -*-
'''
Compendium of generic DNS utilities
# Examples:
dns.lookup(name, rdtype, ...)
Severity: Major
Found in salt/utils/dns.py - About 2 days to fix

    Function parse_resolv has a Cognitive Complexity of 51 (exceeds 5 allowed). Consider refactoring.
    Open

    def parse_resolv(src='/etc/resolv.conf'):
        '''
        Parse a resolver configuration file (traditionally /etc/resolv.conf)
        '''
    
    
    Severity: Minor
    Found in salt/utils/dns.py - About 7 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 lookup has a Cognitive Complexity of 38 (exceeds 5 allowed). Consider refactoring.
    Open

    def lookup(
        name,
        rdtype,
        method=None,
        servers=None,
    Severity: Minor
    Found in salt/utils/dns.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

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

    def services(services_file='/etc/services'):
        '''
        Parse through system-known services
        :return: {
            'svc': [
    Severity: Minor
    Found in salt/utils/dns.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

    Function _lookup_nslookup has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
    Open

    def _lookup_nslookup(name, rdtype, timeout=None, server=None):
        '''
        Use nslookup to lookup addresses
        :param name: Name of record to search
        :param rdtype: DNS record type
    Severity: Minor
    Found in salt/utils/dns.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

    Cyclomatic complexity is too high in function parse_resolv. (28)
    Open

    def parse_resolv(src='/etc/resolv.conf'):
        '''
        Parse a resolver configuration file (traditionally /etc/resolv.conf)
        '''
    
    
    Severity: Minor
    Found in salt/utils/dns.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

    Cyclomatic complexity is too high in function lookup. (27)
    Open

    def lookup(
        name,
        rdtype,
        method=None,
        servers=None,
    Severity: Minor
    Found in salt/utils/dns.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 spf_rec has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
    Open

    def spf_rec(rdata):
        '''
        Validate and parse DNS record data for SPF record(s)
        :param rdata: DNS record data
        :return: dict w/fields
    Severity: Minor
    Found in salt/utils/dns.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 _lookup_drill has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
    Open

    def _lookup_drill(name, rdtype, timeout=None, servers=None, secure=None):
        '''
        Use drill to lookup addresses
        :param name: Name of record to search
        :param rdtype: DNS record type
    Severity: Minor
    Found in salt/utils/dns.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 _lookup_dig has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

    def _lookup_dig(name, rdtype, timeout=None, servers=None, secure=None):
        '''
        Use dig to lookup addresses
        :param name: Name of record to search
        :param rdtype: DNS record type
    Severity: Minor
    Found in salt/utils/dns.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 _lookup_host has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

    def _lookup_host(name, rdtype, timeout=None, server=None):
        '''
        Use host to lookup addresses
        :param name: Name of record to search
        :param server: Server to query
    Severity: Minor
    Found in salt/utils/dns.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 caa_rec has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

    def caa_rec(rdatas):
        '''
        Validate and parse DNS record data for a CAA record
        :param rdata: DNS record data
        :return: dict w/fields
    Severity: Minor
    Found in salt/utils/dns.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 query has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

    def query(
        name,
        rdtype,
        method=None,
        servers=None,
    Severity: Minor
    Found in salt/utils/dns.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 _tree has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

    def _tree(domain, tld=False):
        '''
        Split out a domain in its parents
    
        Leverages tldextract to take the TLDs from publicsuffix.org
    Severity: Minor
    Found in salt/utils/dns.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

    Avoid deeply nested control flow statements.
    Open

                        if comment:
                            svc['desc'] = comment
                        svc_res[port] = svc
    Severity: Major
    Found in salt/utils/dns.py - About 45 mins to fix

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

      def _data2rec_group(schema, recs_data, group_key):
          if not isinstance(recs_data, (list, tuple)):
              recs_data = [recs_data]
      
          res = OrderedDict()
      Severity: Minor
      Found in salt/utils/dns.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 deeply nested control flow statements.
      Open

                                      if '/' not in ip_raw:
                                          # No netmask has been provided, guess
                                          # the "natural" one
                                          if ip_net.version == 4:
                                              ip_addr = six.text_type(ip_net.network_address)
      Severity: Major
      Found in salt/utils/dns.py - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                            if comment:
                                if not curr_desc:
                                    pp_res['desc'] = comment
                                elif comment != curr_desc:
                                    pp_res['desc'] = '{0}, {1}'.format(curr_desc, comment)
        Severity: Major
        Found in salt/utils/dns.py - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                              if isinstance(curr_proto, (list, tuple)):
                                  curr_proto.append(proto)
                              else:
                                  pp_res['proto'] = [curr_proto, proto]
          
          
          Severity: Major
          Found in salt/utils/dns.py - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                                            if ip_net not in sortlist:
                                                sortlist.append(ip_net)
                                elif directive == 'options':
            Severity: Major
            Found in salt/utils/dns.py - About 45 mins to fix

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

              def host(name, ip4=True, ip6=True, **kwargs):
                  '''
                  Return a list of addresses for name
              
                  ip6:
              Severity: Minor
              Found in salt/utils/dns.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

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

              def _weighted_order(recs):
                  res = []
                  weights = [rec['weight'] for rec in recs]
                  while weights:
                      rnd = random.random() * sum(weights)
              Severity: Minor
              Found in salt/utils/dns.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

              There are no issues that match your filters.

              Category
              Status