localstack/localstack

View on GitHub
localstack/utils/container_utils/docker_sdk_client.py

Summary

Maintainability
F
4 days
Test Coverage

File docker_sdk_client.py has 787 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import base64
import json
import logging
import os
import queue
Severity: Major
Found in localstack/utils/container_utils/docker_sdk_client.py - About 1 day to fix

    SdkDockerClient has 39 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class SdkDockerClient(ContainerClient):
        """
        Class for managing Docker (or Podman) using the Python Docker SDK.
    
        The client also supports targeting Podman engines, as Podman is almost a drop-in replacement
    Severity: Minor
    Found in localstack/utils/container_utils/docker_sdk_client.py - About 5 hrs to fix

      Function run_container has 27 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def run_container(
      Severity: Major
      Found in localstack/utils/container_utils/docker_sdk_client.py - About 3 hrs to fix

        Function create_container has 26 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            def create_container(
        Severity: Major
        Found in localstack/utils/container_utils/docker_sdk_client.py - About 3 hrs to fix

          Function create_container has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
          Open

              def create_container(
                  self,
                  image_name: str,
                  *,
                  name: Optional[str] = None,
          Severity: Minor
          Found in localstack/utils/container_utils/docker_sdk_client.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 start_container has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
          Open

              def start_container(
                  self,
                  container_name_or_id: str,
                  stdin=None,
                  interactive: bool = False,
          Severity: Minor
          Found in localstack/utils/container_utils/docker_sdk_client.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 exec_in_container has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
          Open

              def exec_in_container(
                  self,
                  container_name_or_id: str,
                  command: Union[List[str], str],
                  interactive=False,
          Severity: Minor
          Found in localstack/utils/container_utils/docker_sdk_client.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 push_image has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
          Open

              def push_image(self, docker_image: str) -> None:
                  LOG.debug("Pushing Docker image: %s", docker_image)
                  try:
                      result = self.client().images.push(docker_image)
                      # some SDK clients (e.g., 5.0.0) seem to return an error string, instead of raising
          Severity: Minor
          Found in localstack/utils/container_utils/docker_sdk_client.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 exec_in_container has 8 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              def exec_in_container(
          Severity: Major
          Found in localstack/utils/container_utils/docker_sdk_client.py - About 1 hr to fix

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

                def inspect_image(
                    self,
                    image_name: str,
                    pull: bool = True,
                    strip_wellknown_repo_prefixes: bool = True,
            Severity: Minor
            Found in localstack/utils/container_utils/docker_sdk_client.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 start_container has 5 arguments (exceeds 4 allowed). Consider refactoring.
            Open

                def start_container(
            Severity: Minor
            Found in localstack/utils/container_utils/docker_sdk_client.py - About 35 mins to fix

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

                  def remove_image(self, image: str, force: bool = True):
                      LOG.debug("Removing image %s %s", image, "(forced)" if force else "")
                      try:
                          self.client().images.remove(image=image, force=force)
                      except ImageNotFound:
              Severity: Minor
              Found in localstack/utils/container_utils/docker_sdk_client.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 _create_client has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                  def _create_client():
                      from localstack.config import DOCKER_SDK_DEFAULT_RETRIES, DOCKER_SDK_DEFAULT_TIMEOUT_SECONDS
              
                      for attempt in range(0, DOCKER_SDK_DEFAULT_RETRIES + 1):
                          try:
              Severity: Minor
              Found in localstack/utils/container_utils/docker_sdk_client.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 list_containers has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                  def list_containers(self, filter: Union[List[str], str, None] = None, all=True) -> List[dict]:
                      if filter:
                          filter = [filter] if isinstance(filter, str) else filter
                          filter = dict([f.split("=", 1) for f in filter])
                      LOG.debug("Listing containers with filters: %s", filter)
              Severity: Minor
              Found in localstack/utils/container_utils/docker_sdk_client.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 get_container_logs has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                  def get_container_logs(self, container_name_or_id: str, safe: bool = False) -> str:
                      try:
                          container = self.client().containers.get(container_name_or_id)
                          return to_str(container.logs())
                      except NotFound:
              Severity: Minor
              Found in localstack/utils/container_utils/docker_sdk_client.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