csirtgadgets/csirtg-indicator-py

View on GitHub

Showing 32 of 54 total issues

Function resolve_itype has a Cognitive Complexity of 73 (exceeds 5 allowed). Consider refactoring.
Open

def resolve_itype(indicator, test_broken=False):
    def _ipv6(s):
        try:
            socket.inet_pton(socket.AF_INET6, s)
            return True
Severity: Minor
Found in csirtg_indicator/utils/__init__.py - About 1 day 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 parse_timestamp has a Cognitive Complexity of 44 (exceeds 5 allowed). Consider refactoring.
Open

def parse_timestamp(ts):
    if isinstance(ts, arrow.Arrow):
        return ts

    t = human_to_dt(ts)
Severity: Minor
Found in csirtg_indicator/utils/ztime.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 __init__ has a Cognitive Complexity of 35 (exceeds 5 allowed). Consider refactoring.
Open

    def __init__(self, indicator=None, version=PROTOCOL_VERSION, **kwargs):
        self.version = version
        if 'lowercase' in kwargs:
            self._lowercase = kwargs.get('lowercase')
            # indicate lowercase arg was explicitly passed by user rather than just a default value
Severity: Minor
Found in csirtg_indicator/indicator.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

Indicator has 33 functions (exceeds 20 allowed). Consider refactoring.
Open

class Indicator(object):

    def __init__(self, indicator=None, version=PROTOCOL_VERSION, **kwargs):
        self.version = version
        if 'lowercase' in kwargs:
Severity: Minor
Found in csirtg_indicator/indicator.py - About 4 hrs to fix

    Function __repr__ has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
    Open

        def __repr__(self):
            output = StringIO()
    
            csvWriter = csv.DictWriter(output, self.cols, quoting=csv.QUOTE_ALL)
            csvWriter.writeheader()
    Severity: Minor
    Found in csirtg_indicator/format/zcsv.py - About 4 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 get_lines has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
    Open

    def get_lines(data, cols=COLUMNS, quoting=csv.QUOTE_ALL):
        output = StringIO()
        csvWriter = csv.DictWriter(output, cols, quoting=quoting)
        csvWriter.writeheader()
    
    
    Severity: Minor
    Found in csirtg_indicator/format/zcsv.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 _i_to_zeek has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
    Open

    def _i_to_zeek(i, cols):
        if isinstance(i, Indicator):
            i = i.__dict__()
    
        cols = ['indicator', 'itype', 'description', 'tags', 'confidence', 'provider']
    Severity: Minor
    Found in csirtg_indicator/format/zzeek.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 _create_indicator has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
    Open

        def _create_indicator(self, d):
            def _hash(keypair, hash_type):
                hash_type = 'TYPE_{}'.format(hash_type.upper())
                h = Hash(keypair.get('indicator'), getattr(Hash, hash_type))
                f = File()
    Severity: Minor
    Found in csirtg_indicator/format/zstix.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 _indicator_row has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
    Open

    def _indicator_row(i, cols, max_field_size):
        if isinstance(i, Indicator):
            i = i.__dict__()
    
        r = []
    Severity: Minor
    Found in csirtg_indicator/format/ztable.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 __repr__ has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
    Open

        def __repr__(self):
            i = {}
            for k in FIELDS:
    
                v = getattr(self, k)
    Severity: Minor
    Found in csirtg_indicator/indicator.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

    File indicator.py has 271 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    # -*- coding: utf-8 -*-
    from pprint import pprint
    import uuid
    import logging
    from .constants import PYVERSION, IPV4_PRIVATE_NETS, PROTOCOL_VERSION, FIELDS, FIELDS_TIME, LOG_FORMAT
    Severity: Minor
    Found in csirtg_indicator/indicator.py - About 2 hrs to fix

      Function format_keys has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

          def format_keys(self):
              d = self.__dict__()
              for k in d:
                  if PYVERSION == 2:
                      if not isinstance(d[k], unicode):
      Severity: Minor
      Found in csirtg_indicator/indicator.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_lines has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

      def get_lines(data, filename=OUTPUT_PATH):
          output = StringIO()
          text = [
              ";;; generated by: {} at {}".format('csirtg-indicator', time.strftime('%Y-%m-%dT%H:%M:%S %Z')),
              ';RPZ DATA!',
      Severity: Minor
      Found in csirtg_indicator/format/zbindrpz.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_lines has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

      def get_lines(data, filename=OUTPUT_PATH):
          output = StringIO()
          text = [
              ";;; generated by: {} at {}".format('csirtg-indicator', time.strftime('%Y-%m-%dT%H:%M:%S %Z')),
              ';RPZ-IP DATA!',
      Severity: Minor
      Found in csirtg_indicator/format/zbindrpzip.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 normalize_indicator has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

      def normalize_indicator(i, itype=None, lowercase=False, lowercase_explicit=False):
          if itype == 'fqdn':
              i = i.rstrip('.')
              # only don't lowercase if lowercase=False and lowercase_explicit=True (set by user)
              if lowercase or not lowercase_explicit:
      Severity: Minor
      Found in csirtg_indicator/utils/__init__.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

      Function _indicator_row has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

      def _indicator_row(i, cols):
          if isinstance(i, Indicator):
              i = i.__dict__()
      
          r = dict()
      Severity: Minor
      Found in csirtg_indicator/format/zjson.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

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

          def indicator(self, i):
              if not i:
                  self._indicator = None
                  return
      
      
      Severity: Minor
      Found in csirtg_indicator/indicator.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 ',' in x:
                                  tmp_list.extend([y.strip() for y in x.split(',') if y])
                              else:
                                  tmp_list.append(x.strip())
                          kwargs[k] = tmp_list
      Severity: Major
      Found in csirtg_indicator/indicator.py - About 45 mins to fix

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

        def get_lines(data, filename=OUTPUT_PATH):
            output = StringIO()
            output.write("// generated by: {} at {}\n".format('csirtg-indicator', time.strftime('%Y-%m-%dT%H:%M:%S %Z')))
        
            for i in data:
        Severity: Minor
        Found in csirtg_indicator/format/zbind.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 t
        Severity: Major
        Found in csirtg_indicator/utils/ztime.py - About 30 mins to fix
          Severity
          Category
          Status
          Source
          Language