Showing 23 of 248 total issues

File ssm2.py has 477 lines of code (exceeds 250 allowed). Consider refactoring.
Open

"""
   Copyright (C) 2012 STFC

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
Severity: Minor
Found in ssm/ssm2.py - About 7 hrs to fix

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

        def __init__(self, hosts_and_ports, qpath, cert, key, dest=None, listen=None,
                     capath=None, check_crls=False, use_ssl=True, enc_cert=None,
                     verify_enc_cert=True, pidfile=None, path_type='dirq',
                     protocol=STOMP_MESSAGING, project=None, token=''):
            """Create an SSM2 object.
    Severity: Minor
    Found in ssm/ssm2.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

    Ssm2 has 25 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class Ssm2(stomp.ConnectionListener):
        """Minimal SSM implementation."""
    
        # Schema for the dirq message queue.
        QSCHEMA = {'body': 'string', 'signer': 'string', 'empaid': 'string?'}
    Severity: Minor
    Found in ssm/ssm2.py - About 2 hrs to fix

      File agents.py has 266 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      #!/usr/bin/env python
      
      # Copyright 2021 UK Research and Innovation
      #
      # Licensed under the Apache License, Version 2.0 (the "License");
      Severity: Minor
      Found in ssm/agents.py - About 2 hrs to fix

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

            def send_all(self):
                """
                Send all the messages in the outgoing queue.
        
                Either via STOMP or HTTPS (to an Argo Message Broker).
        Severity: Minor
        Found in ssm/ssm2.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 __init__ has 16 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            def __init__(self, hosts_and_ports, qpath, cert, key, dest=None, listen=None,
        Severity: Major
        Found in ssm/ssm2.py - About 2 hrs to fix

          Function run_receiver has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
          Open

          def run_receiver(protocol, brokers, project, token, cp, log, dn_file):
              """Run Ssm2 as a receiver daemon."""
              if DaemonContext is None:
                  log.error("Receiving SSMs must use python-daemon, but the "
                            "python-daemon module wasn't found.")
          Severity: Minor
          Found in ssm/agents.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 run_sender has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
          Open

          def run_sender(protocol, brokers, project, token, cp, log):
              """Run Ssm2 as a sender."""
              try:
                  server_cert = None
                  verify_server_cert = True
          Severity: Minor
          Found in ssm/agents.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_ssm_args has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
          Open

          def get_ssm_args(protocol, cp, log):
              """Return brokers, project, and token from config based on protocol."""
              if protocol == Ssm2.STOMP_MESSAGING:
                  # Set defaults for AMS variables that Ssm2 constructor requires below.
                  project = None
          Severity: Minor
          Found in ssm/agents.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 handle_connect has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
          Open

              def handle_connect(self):
                  """Connect to broker.
          
                  Assuming that the SSM has retrieved the details of the broker or
                  brokers it wants to connect to, connect to one.
          Severity: Minor
          Found in ssm/ssm2.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 verify has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

          def verify(signed_text, capath, check_crl):
              """Verify the signed message has been signed by the certificate.
          
              Verify the signed message has been signed by the certificate (attached to
              the supplied SMIME message) it claims to have, by one of the accepted CAs
          Severity: Minor
          Found in ssm/crypto.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 run_receiver has 7 arguments (exceeds 4 allowed). Consider refactoring.
          Open

          def run_receiver(protocol, brokers, project, token, cp, log, dn_file):
          Severity: Major
          Found in ssm/agents.py - About 50 mins to fix

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

                def _handle_msg(self, text):
                    """Deal with the raw message contents appropriately.
            
                    Namely:
                    - decrypt if necessary
            Severity: Minor
            Found in ssm/ssm2.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

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

            def get_dns(dn_file, log):
                """Retrieve a list of DNs from a file."""
                dns = []
                f = None
                try:
            Severity: Minor
            Found in ssm/agents.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

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

            def run_sender(protocol, brokers, project, token, cp, log):
            Severity: Minor
            Found in ssm/agents.py - About 45 mins to fix

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

                  def _save_msg_to_queue(self, body, empaid):
                      """Extract message contents and add to the accept or reject queue."""
                      if isinstance(body, bytes):
                          body = body.decode('ascii')
              
              
              Severity: Minor
              Found in ssm/ssm2.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

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

              def verify_cert(certstring, capath, check_crls=True):
                  """Verify that the certificate is signed by a CA with a cert in capath.
              
                  Note that I've had to compare strings in the output of openssl to check
                  for verification, which may make this brittle.
              Severity: Minor
              Found in ssm/crypto.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

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

                  def start_connection(self):
                      """Start existing connection and subscribe to the relevant topics.
              
                      If the timeout is reached without receiving confirmation of
                      connection, raise an exception.
              Severity: Minor
              Found in ssm/ssm2.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 message, signer, None
              Severity: Major
              Found in ssm/ssm2.py - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                    return certificate_public_key.strip() == private_public_key.strip()
                Severity: Major
                Found in ssm/crypto.py - About 30 mins to fix
                  Severity
                  Category
                  Status
                  Source
                  Language