mirror of
https://github.com/freedomofpress/dangerzone.git
synced 2025-04-29 10:12:38 +02:00
add type get_container_runtime & handle no runtime
There was no code to handle if at this stage the runtime existed. This caused issues with type hints since `shutil.which()` can return None, which had not previously been accounted for. We did not use the opportunity to consolidate all the code for detecting the runtime, to make this review easier.
This commit is contained in:
parent
665e4d54f7
commit
6ddd411be8
2 changed files with 13 additions and 3 deletions
|
@ -52,11 +52,17 @@ def exec(args, stdout_callback=None):
|
||||||
def exec_container(command, extra_args=[], stdout_callback=None):
|
def exec_container(command, extra_args=[], stdout_callback=None):
|
||||||
if container_tech == "podman":
|
if container_tech == "podman":
|
||||||
container_runtime = shutil.which("podman")
|
container_runtime = shutil.which("podman")
|
||||||
|
if container_runtime is None:
|
||||||
|
raise Exception(f"podman is not installed")
|
||||||
|
|
||||||
platform_args = []
|
platform_args = []
|
||||||
security_args = ["--security-opt", "no-new-privileges"]
|
security_args = ["--security-opt", "no-new-privileges"]
|
||||||
security_args += ["--userns", "keep-id"]
|
security_args += ["--userns", "keep-id"]
|
||||||
else:
|
else:
|
||||||
container_runtime = shutil.which("docker")
|
container_runtime = shutil.which("docker")
|
||||||
|
if container_runtime is None:
|
||||||
|
raise Exception(f"docker is not installed")
|
||||||
|
|
||||||
platform_args = ["--platform", "linux/amd64"]
|
platform_args = ["--platform", "linux/amd64"]
|
||||||
security_args = ["--security-opt=no-new-privileges:true"]
|
security_args = ["--security-opt=no-new-privileges:true"]
|
||||||
|
|
||||||
|
|
|
@ -386,11 +386,15 @@ class GlobalCommon(object):
|
||||||
)
|
)
|
||||||
print(Back.BLACK + Fore.YELLOW + Style.DIM + "╰──────────────────────────╯")
|
print(Back.BLACK + Fore.YELLOW + Style.DIM + "╰──────────────────────────╯")
|
||||||
|
|
||||||
def get_container_runtime(self):
|
def get_container_runtime(self) -> str:
|
||||||
if platform.system() == "Linux":
|
if platform.system() == "Linux":
|
||||||
return shutil.which("podman")
|
runtime_name = "podman"
|
||||||
else:
|
else:
|
||||||
return shutil.which("docker")
|
runtime_name = "docker"
|
||||||
|
runtime = shutil.which(runtime_name)
|
||||||
|
if runtime is None:
|
||||||
|
raise Exception(f"{runtime_name} is not installed")
|
||||||
|
return runtime
|
||||||
|
|
||||||
def get_resource_path(self, filename: str) -> str:
|
def get_resource_path(self, filename: str) -> str:
|
||||||
if getattr(sys, "dangerzone_dev", False):
|
if getattr(sys, "dangerzone_dev", False):
|
||||||
|
|
Loading…
Reference in a new issue