oceanprotocol/provider

View on GitHub

Showing 67 of 71 total issues

File compute.py has 538 lines of code (exceeds 250 allowed). Consider refactoring.
Open

#
# Copyright 2023 Ocean Protocol Foundation
# SPDX-License-Identifier: Apache-2.0
#
import functools
Severity: Major
Found in ocean_provider/routes/compute.py - About 1 day to fix

    File algo.py has 476 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    #
    # Copyright 2023 Ocean Protocol Foundation
    # SPDX-License-Identifier: Apache-2.0
    #
    import json
    Severity: Minor
    Found in ocean_provider/validation/algo.py - About 7 hrs to fix

      File consume.py has 380 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      #
      # Copyright 2023 Ocean Protocol Foundation
      # SPDX-License-Identifier: Apache-2.0
      #
      import json
      Severity: Minor
      Found in ocean_provider/routes/consume.py - About 5 hrs to fix

        File provider_requests.py has 358 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        #
        # Copyright 2023 Ocean Protocol Foundation
        # SPDX-License-Identifier: Apache-2.0
        #
        import logging
        Severity: Minor
        Found in ocean_provider/validation/provider_requests.py - About 4 hrs to fix

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

              def check_details(self, with_checksum=False):
                  """
                  If the url argument is invalid, returns False and empty dictionary.
                  Otherwise it returns True and a dictionary containing contentType and
                  contentLength. If the with_checksum flag is set to True, it also returns
          Severity: Minor
          Found in ocean_provider/file_types/definitions.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 check_details has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
          Open

              def check_details(self, with_checksum=False):
                  """
                  If the url argument is invalid, returns False and empty dictionary.
                  Otherwise it returns True and a dictionary containing contentType and
                  contentLength. File name remains empty.
          Severity: Minor
          Found in ocean_provider/file_types/file_types.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 validate_input has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
          Open

              def validate_input(self, index=0):
                  """Validates input dictionary."""
                  main_input = self.data["dataset"]
                  additional_inputs = self.data.get("additionalDatasets", list())
          
          
          Severity: Minor
          Found in ocean_provider/validation/algo.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 build_download_response has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
          Open

              def build_download_response(
                  self,
                  request,
                  validate_url=True,
              ):
          Severity: Minor
          Found in ocean_provider/file_types/definitions.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 validate has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
          Open

              def validate(self):
                  required_keys = (
                      ["documentId", "transferTxId"] if self.check_usage else ["documentId"]
                  )
          
          
          Severity: Minor
          Found in ocean_provider/validation/algo.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 _validate_trusted_algos has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
          Open

              def _validate_trusted_algos(
                  self, algorithm_did, trusted_algorithms, trusted_publishers
              ):
                  if not trusted_algorithms and not trusted_publishers:
                      return True
          Severity: Minor
          Found in ocean_provider/validation/algo.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 _build_and_validate_algo has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
          Open

              def _build_and_validate_algo(self, algo_data):
                  """Returns False if invalid, otherwise sets the validated_algo_dict attribute."""
                  algorithm_did = algo_data.get("documentId")
                  self.algo_service = None
                  self.algo = None
          Severity: Minor
          Found in ocean_provider/validation/algo.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_order_tx has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
          Open

          def verify_order_tx(
              web3: Web3,
              datatoken_address: HexAddress,
              tx_id: HexStr,
              service: Service,
          Severity: Minor
          Found in ocean_provider/utils/datatoken.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 initialize has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
          Open

          def initialize():
              """Initialize a service access request.
              In order to consume a data service the user is required to send
              one datatoken to the provider.
          
          
          Severity: Minor
          Found in ocean_provider/routes/consume.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 initializeCompute has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

          def initializeCompute():
              """Initialize a compute service request, with possible additional access requests.
              In order to consume a data service the user is required to send
              one datatoken to the provider, as well as provider fees for the compute job.
          
          
          Severity: Minor
          Found in ocean_provider/routes/compute.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_service_files_list has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

          def get_service_files_list(
              service: Service, provider_wallet: LocalAccount, asset: Asset = None
          ) -> list:
              version = asset.version if asset is not None and asset.version else "4.0.0"
              if asset is None or version == "4.0.0":
          Severity: Minor
          Found in ocean_provider/utils/util.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_provider_fees_or_remote has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
          Open

          def get_provider_fees_or_remote(
              asset, service, consumer_address, valid_until, compute_env, force_zero, dataset
          ):
              valid_order = None
              if "transferTxId" in dataset:
          Severity: Minor
          Found in ocean_provider/utils/provider_fees.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 validate_dict has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
          Open

              def validate_dict(self) -> Tuple[bool, Any]:
                  if not self.address:
                      return False, "malformed smartcontract type, missing contract address"
                  # validate abi
          
          
          Severity: Minor
          Found in ocean_provider/file_types/types/smartcontract.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 __init__ has 10 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              def __init__(
          Severity: Major
          Found in ocean_provider/utils/services.py - About 1 hr to fix

            Function fileinfo has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
            Open

            def fileinfo():
                """Retrieves Content-Type and Content-Length from the given URL or asset. Supports a payload of either url or did.
                This can be used by the publisher of an asset to check basic information
                about the URL(s). For now, this information consists of the Content-Type
                and Content-Length of the request, using primarily OPTIONS, with fallback
            Severity: Minor
            Found in ocean_provider/routes/consume.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 _decrypt has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

            def _decrypt(
                decrypter_address: HexStr,
                chain_id: int,
                transaction_id: Optional[HexStr],
                data_nft_address: HexStr,
            Severity: Minor
            Found in ocean_provider/routes/decrypt.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

            Severity
            Category
            Status
            Source
            Language