dnstats/dnstatsio

View on GitHub
dnstats/celery.py

Summary

Maintainability
C
1 day
Test Coverage

Starting a process with a shell, possible injection detected, security issue.
Open

    os.system("ssh dnstatsio@www.dnstats.io 'ln -s /home/dnstatsio/public_html/{folder_name}/{filename}.js /home/dnstatsio/public_html/'".format(folder_name=folder_name, filename=js_filename))
Severity: Major
Found in dnstats/celery.py by bandit

Starting a process with a shell, possible injection detected, security issue.
Open

    os.system('scp {filename} dnstatsio@www.dnstats.io:/home/dnstatsio/public_html/{folder_name}/index.html'.format(filename=html_filename, folder_name=folder_name))
Severity: Major
Found in dnstats/celery.py by bandit

Starting a process with a shell: Seems safe, but may be changed in the future, consider rewriting without shell
Open

    os.system("ssh dnstatsio@www.dnstats.io 'rm /home/dnstatsio/public_html/index.html'")
Severity: Info
Found in dnstats/celery.py by bandit

Starting a process with a shell, possible injection detected, security issue.
Open

    os.system("ssh dnstatsio@www.dnstats.io 'ln -s /home/dnstatsio/public_html/{folder_name}/index.html /home/dnstatsio/public_html/index.html'".format(folder_name=folder_name, filename=html_filename))
Severity: Major
Found in dnstats/celery.py by bandit

Starting a process with a shell, possible injection detected, security issue.
Open

    os.system("ssh dnstatsio@www.dnstats.io 'mkdir /home/dnstatsio/public_html/{}'".format(folder_name))
Severity: Major
Found in dnstats/celery.py by bandit

Starting a process with a partial executable path
Open

    os.system("ssh dnstatsio@www.dnstats.io 'rm /home/dnstatsio/public_html/index.html'")
Severity: Info
Found in dnstats/celery.py by bandit

Starting a process with a shell, possible injection detected, security issue.
Open

    os.system('scp {filename}.js dnstatsio@www.dnstats.io:/home/dnstatsio/public_html/{folder_name}/{filename}.js'.format(filename=js_filename, folder_name=folder_name))
Severity: Major
Found in dnstats/celery.py by bandit

File celery.py has 387 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import datetime
import os

from celery import Celery, Task
from celery.canvas import chain, group
Severity: Minor
Found in dnstats/celery.py - About 5 hrs to fix

    Function import_list has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

    def import_list():
        new_sites = setup_import_list(logger)
    
        existing_sites = dict()
        with engine.connect() as connection:
    Severity: Minor
    Found in dnstats/celery.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 site_stat has 38 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    def site_stat(site_id: int, run_id: int):
        logger.debug('start site stat site {} run id {}'.format(site_id, run_id))
        result = dict()
        result['start_time'] = datetime.datetime.now()
        site = db_session.query(models.Site).filter(models.Site.id == site_id).scalar()
    Severity: Minor
    Found in dnstats/celery.py - About 1 hr to fix

      Function publish_reports has 26 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      def publish_reports(run_id: int):
          # sr is the alias for site_runs table
          reports = list()
          reports.append({'query': 'sr.mx_records is not null', 'name': 'mx_domains', 'type': 'list'})
          reports.append({'query': 'sr.mx_records is null', 'name': 'no_mx_domains', 'type': 'list'})
      Severity: Minor
      Found in dnstats/celery.py - About 1 hr to fix

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

        def grade_dmarc(site_run_id: int):
            site, site_run = get_site_and_site_run(site_run_id)
            records = site_run.j_dmarc_record
            grade = 0
            dmarcs = list()
        Severity: Minor
        Found in dnstats/celery.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 len(sites_chunked_update) >= 100:
                                chunk_count += 1
                                # loop counter to monitor task creation status
                                logger.debug("existing_sites chunk count: {}".format(chunk_count))
                                logger.info("Creating update task: {}".format(chunk_count))
        Severity: Major
        Found in dnstats/celery.py - About 45 mins to fix

          Function after_return has 6 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              def after_return(self, status, retval, task_id, args, kwargs, einfo):
          Severity: Minor
          Found in dnstats/celery.py - About 45 mins to fix

            Refactor this function to reduce its Cognitive Complexity from 17 to the 15 allowed.
            Open

            def import_list():
            Severity: Critical
            Found in dnstats/celery.py by sonar-python

            Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.

            See

            Line too long (126 > 120 characters)
            Open

                sub_dmarc_policy_db = db_session.query(models.DmarcPolicy).filter_by(policy_string=processed['dmarc_sub_policy']).scalar()
            Severity: Minor
            Found in dnstats/celery.py by pep8

            Limit all lines to a maximum of 79 characters.

            There are still many devices around that are limited to 80 character
            lines; plus, limiting windows to 80 characters makes it possible to
            have several windows side-by-side.  The default wrapping on such
            devices looks ugly.  Therefore, please limit all lines to a maximum
            of 79 characters. For flowing long blocks of text (docstrings or
            comments), limiting the length to 72 characters is recommended.
            
            Reports error E501.

            Line too long (201 > 120 characters)
            Open

                os.system("ssh dnstatsio@www.dnstats.io 'ln -s /home/dnstatsio/public_html/{folder_name}/index.html /home/dnstatsio/public_html/index.html'".format(folder_name=folder_name, filename=html_filename))
            Severity: Minor
            Found in dnstats/celery.py by pep8

            Limit all lines to a maximum of 79 characters.

            There are still many devices around that are limited to 80 character
            lines; plus, limiting windows to 80 characters makes it possible to
            have several windows side-by-side.  The default wrapping on such
            devices looks ugly.  Therefore, please limit all lines to a maximum
            of 79 characters. For flowing long blocks of text (docstrings or
            comments), limiting the length to 72 characters is recommended.
            
            Reports error E501.

            Line too long (152 > 120 characters)
            Open

                                    dnssec_dnskey_algorithm=processed['dnssec_dnskey_algorithm'], has_securitytxt=result['has_dnssec'], has_msdc=result['is_msdcs'],
            Severity: Minor
            Found in dnstats/celery.py by pep8

            Limit all lines to a maximum of 79 characters.

            There are still many devices around that are limited to 80 character
            lines; plus, limiting windows to 80 characters makes it possible to
            have several windows side-by-side.  The default wrapping on such
            devices looks ugly.  Therefore, please limit all lines to a maximum
            of 79 characters. For flowing long blocks of text (docstrings or
            comments), limiting the length to 72 characters is recommended.
            
            Reports error E501.

            Line too long (131 > 120 characters)
            Open

            from dnstats.utils.email import _send_botched_deploy, _send_eoq, _send_published_email, _send_start_email, _send_sites_updated_done
            Severity: Minor
            Found in dnstats/celery.py by pep8

            Limit all lines to a maximum of 79 characters.

            There are still many devices around that are limited to 80 character
            lines; plus, limiting windows to 80 characters makes it possible to
            have several windows side-by-side.  The default wrapping on such
            devices looks ugly.  Therefore, please limit all lines to a maximum
            of 79 characters. For flowing long blocks of text (docstrings or
            comments), limiting the length to 72 characters is recommended.
            
            Reports error E501.

            Expected 2 blank lines, found 1
            Open

            @app.task()
            Severity: Minor
            Found in dnstats/celery.py by pep8

            Separate top-level function and class definitions with two blank lines.

            Method definitions inside a class are separated by a single blank
            line.
            
            Extra blank lines may be used (sparingly) to separate groups of
            related functions.  Blank lines may be omitted between a bunch of
            related one-liners (e.g. a set of dummy implementations).
            
            Use blank lines in functions, sparingly, to indicate logical
            sections.
            
            Okay: def a():\n    pass\n\n\ndef b():\n    pass
            Okay: def a():\n    pass\n\n\nasync def b():\n    pass
            Okay: def a():\n    pass\n\n\n# Foo\n# Bar\n\ndef b():\n    pass
            Okay: default = 1\nfoo = 1
            Okay: classify = 1\nfoo = 1
            
            E301: class Foo:\n    b = 0\n    def bar():\n        pass
            E302: def a():\n    pass\n\ndef b(n):\n    pass
            E302: def a():\n    pass\n\nasync def b(n):\n    pass
            E303: def a():\n    pass\n\n\n\ndef b(n):\n    pass
            E303: def a():\n\n\n\n    pass
            E304: @decorator\n\ndef a():\n    pass
            E305: def a():\n    pass\na()
            E306: def a():\n    def b():\n        pass\n    def c():\n        pass

            Line too long (165 > 120 characters)
            Open

                os.system('scp {filename} dnstatsio@www.dnstats.io:/home/dnstatsio/public_html/{folder_name}/index.html'.format(filename=html_filename, folder_name=folder_name))
            Severity: Minor
            Found in dnstats/celery.py by pep8

            Limit all lines to a maximum of 79 characters.

            There are still many devices around that are limited to 80 character
            lines; plus, limiting windows to 80 characters makes it possible to
            have several windows side-by-side.  The default wrapping on such
            devices looks ugly.  Therefore, please limit all lines to a maximum
            of 79 characters. For flowing long blocks of text (docstrings or
            comments), limiting the length to 72 characters is recommended.
            
            Reports error E501.

            Line too long (131 > 120 characters)
            Open

                                    dmarc_sub_policy_id=sub_dmarc_policy_db.id, has_dmarc_aggregate_reporting=processed['dmarc_has_aggregate'],
            Severity: Minor
            Found in dnstats/celery.py by pep8

            Limit all lines to a maximum of 79 characters.

            There are still many devices around that are limited to 80 character
            lines; plus, limiting windows to 80 characters makes it possible to
            have several windows side-by-side.  The default wrapping on such
            devices looks ugly.  Therefore, please limit all lines to a maximum
            of 79 characters. For flowing long blocks of text (docstrings or
            comments), limiting the length to 72 characters is recommended.
            
            Reports error E501.

            Too many blank lines (3)
            Open

            @app.task(time_limit=320, soft_time_limit=300)
            Severity: Minor
            Found in dnstats/celery.py by pep8

            Separate top-level function and class definitions with two blank lines.

            Method definitions inside a class are separated by a single blank
            line.
            
            Extra blank lines may be used (sparingly) to separate groups of
            related functions.  Blank lines may be omitted between a bunch of
            related one-liners (e.g. a set of dummy implementations).
            
            Use blank lines in functions, sparingly, to indicate logical
            sections.
            
            Okay: def a():\n    pass\n\n\ndef b():\n    pass
            Okay: def a():\n    pass\n\n\nasync def b():\n    pass
            Okay: def a():\n    pass\n\n\n# Foo\n# Bar\n\ndef b():\n    pass
            Okay: default = 1\nfoo = 1
            Okay: classify = 1\nfoo = 1
            
            E301: class Foo:\n    b = 0\n    def bar():\n        pass
            E302: def a():\n    pass\n\ndef b(n):\n    pass
            E302: def a():\n    pass\n\nasync def b(n):\n    pass
            E303: def a():\n    pass\n\n\n\ndef b(n):\n    pass
            E303: def a():\n\n\n\n    pass
            E304: @decorator\n\ndef a():\n    pass
            E305: def a():\n    pass\na()
            E306: def a():\n    def b():\n        pass\n    def c():\n        pass

            Unexpected spaces around keyword / parameter equals
            Open

                    site = models.Site(domain=str(domain), current_rank = domains_ranked[domain])
            Severity: Minor
            Found in dnstats/celery.py by pep8

            Don't use spaces around the '=' sign in function arguments.

            Don't use spaces around the '=' sign when used to indicate a
            keyword argument or a default parameter value, except when
            using a type annotation.
            
            Okay: def complex(real, imag=0.0):
            Okay: return magic(r=real, i=imag)
            Okay: boolean(a == b)
            Okay: boolean(a != b)
            Okay: boolean(a <= b)
            Okay: boolean(a >= b)
            Okay: def foo(arg: int = 42):
            Okay: async def foo(arg: int = 42):
            
            E251: def complex(real, imag = 0.0):
            E251: return magic(r = real, i = imag)
            E252: def complex(real, image: float=0.0):

            Line too long (148 > 120 characters)
            Open

                                    has_dmarc_forensic_reporting=processed['dmarc_has_forensic'], dmarc_record=result['dmarc'], has_spf=processed['spf_exists'],
            Severity: Minor
            Found in dnstats/celery.py by pep8

            Limit all lines to a maximum of 79 characters.

            There are still many devices around that are limited to 80 character
            lines; plus, limiting windows to 80 characters makes it possible to
            have several windows side-by-side.  The default wrapping on such
            devices looks ugly.  Therefore, please limit all lines to a maximum
            of 79 characters. For flowing long blocks of text (docstrings or
            comments), limiting the length to 72 characters is recommended.
            
            Reports error E501.

            Line too long (192 > 120 characters)
            Open

                os.system("ssh dnstatsio@www.dnstats.io 'ln -s /home/dnstatsio/public_html/{folder_name}/{filename}.js /home/dnstatsio/public_html/'".format(folder_name=folder_name, filename=js_filename))
            Severity: Minor
            Found in dnstats/celery.py by pep8

            Limit all lines to a maximum of 79 characters.

            There are still many devices around that are limited to 80 character
            lines; plus, limiting windows to 80 characters makes it possible to
            have several windows side-by-side.  The default wrapping on such
            devices looks ugly.  Therefore, please limit all lines to a maximum
            of 79 characters. For flowing long blocks of text (docstrings or
            comments), limiting the length to 72 characters is recommended.
            
            Reports error E501.

            Line too long (125 > 120 characters)
            Open

                                    spf_policy_id=spf_db.id, txt_records=result['txt'], ds_records=result['ds'], mx_records=result['mx'],
            Severity: Minor
            Found in dnstats/celery.py by pep8

            Limit all lines to a maximum of 79 characters.

            There are still many devices around that are limited to 80 character
            lines; plus, limiting windows to 80 characters makes it possible to
            have several windows side-by-side.  The default wrapping on such
            devices looks ugly.  Therefore, please limit all lines to a maximum
            of 79 characters. For flowing long blocks of text (docstrings or
            comments), limiting the length to 72 characters is recommended.
            
            Reports error E501.

            Unexpected spaces around keyword / parameter equals
            Open

                    site = models.Site(domain=str(domain), current_rank = domains_ranked[domain])
            Severity: Minor
            Found in dnstats/celery.py by pep8

            Don't use spaces around the '=' sign in function arguments.

            Don't use spaces around the '=' sign when used to indicate a
            keyword argument or a default parameter value, except when
            using a type annotation.
            
            Okay: def complex(real, imag=0.0):
            Okay: return magic(r=real, i=imag)
            Okay: boolean(a == b)
            Okay: boolean(a != b)
            Okay: boolean(a <= b)
            Okay: boolean(a >= b)
            Okay: def foo(arg: int = 42):
            Okay: async def foo(arg: int = 42):
            
            E251: def complex(real, imag = 0.0):
            E251: return magic(r = real, i = imag)
            E252: def complex(real, image: float=0.0):

            Line too long (144 > 120 characters)
            Open

                                    ns_records=result['ns'], email_provider_id=processed['email_provider_id'], dns_provider_id=processed['dns_provider_id'],
            Severity: Minor
            Found in dnstats/celery.py by pep8

            Limit all lines to a maximum of 79 characters.

            There are still many devices around that are limited to 80 character
            lines; plus, limiting windows to 80 characters makes it possible to
            have several windows side-by-side.  The default wrapping on such
            devices looks ugly.  Therefore, please limit all lines to a maximum
            of 79 characters. For flowing long blocks of text (docstrings or
            comments), limiting the length to 72 characters is recommended.
            
            Reports error E501.

            Line too long (159 > 120 characters)
            Open

                sr = models.SiteRun(site_id=result['site_id'], run_id=result['run_id'], run_rank=result['rank'], caa_record=result['caa'], has_caa=processed['caa_exists'],
            Severity: Minor
            Found in dnstats/celery.py by pep8

            Limit all lines to a maximum of 79 characters.

            There are still many devices around that are limited to 80 character
            lines; plus, limiting windows to 80 characters makes it possible to
            have several windows side-by-side.  The default wrapping on such
            devices looks ugly.  Therefore, please limit all lines to a maximum
            of 79 characters. For flowing long blocks of text (docstrings or
            comments), limiting the length to 72 characters is recommended.
            
            Reports error E501.

            Line too long (169 > 120 characters)
            Open

                os.system('scp {filename}.js dnstatsio@www.dnstats.io:/home/dnstatsio/public_html/{folder_name}/{filename}.js'.format(filename=js_filename, folder_name=folder_name))
            Severity: Minor
            Found in dnstats/celery.py by pep8

            Limit all lines to a maximum of 79 characters.

            There are still many devices around that are limited to 80 character
            lines; plus, limiting windows to 80 characters makes it possible to
            have several windows side-by-side.  The default wrapping on such
            devices looks ugly.  Therefore, please limit all lines to a maximum
            of 79 characters. For flowing long blocks of text (docstrings or
            comments), limiting the length to 72 characters is recommended.
            
            Reports error E501.

            Line too long (171 > 120 characters)
            Open

                                    has_caa_reporting=processed['caa_has_reporting'], caa_issue_count=processed['caa_issue_count'], caa_wildcard_count=processed['caa_wildcard_count'],
            Severity: Minor
            Found in dnstats/celery.py by pep8

            Limit all lines to a maximum of 79 characters.

            There are still many devices around that are limited to 80 character
            lines; plus, limiting windows to 80 characters makes it possible to
            have several windows side-by-side.  The default wrapping on such
            devices looks ugly.  Therefore, please limit all lines to a maximum
            of 79 characters. For flowing long blocks of text (docstrings or
            comments), limiting the length to 72 characters is recommended.
            
            Reports error E501.

            There are no issues that match your filters.

            Category
            Status