From 919abb1b7bf178a55a5a4958daa9708a9093ddd5 Mon Sep 17 00:00:00 2001 From: Meni Yakove Date: Mon, 25 Nov 2024 14:09:01 +0200 Subject: [PATCH 1/2] run_command, do not decode out and err --- webhook_server_container/libs/github_api.py | 5 ++++- webhook_server_container/utils/helpers.py | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/webhook_server_container/libs/github_api.py b/webhook_server_container/libs/github_api.py index 4ccb21d4..029981d9 100644 --- a/webhook_server_container/libs/github_api.py +++ b/webhook_server_container/libs/github_api.py @@ -2016,7 +2016,10 @@ def fix_podman_bug(self) -> None: shutil.rmtree("/tmp/storage-run-1000/libpod/tmp", ignore_errors=True) def run_podman_command(self, command: str, pipe: bool = False) -> Tuple[bool, str, str]: - rc, out, err = run_command(command=command, log_prefix=self.log_prefix, pipe=pipe) + rc, _out, _err = run_command(command=command, log_prefix=self.log_prefix, pipe=pipe) + out = _out.decode() if isinstance(_out, bytes) else _out + err = _err.decode() if isinstance(_err, bytes) else _err + if rc: return rc, out, err diff --git a/webhook_server_container/utils/helpers.py b/webhook_server_container/utils/helpers.py index 8a624cc5..4cd318d1 100644 --- a/webhook_server_container/utils/helpers.py +++ b/webhook_server_container/utils/helpers.py @@ -71,7 +71,7 @@ def run_command( check: bool = False, pipe: bool = False, **kwargs: Any, -) -> Tuple[bool, str, str]: +) -> Tuple[bool, Any, Any]: """ Run command locally. @@ -111,8 +111,8 @@ def run_command( timeout=timeout, **kwargs, ) - out_decoded = sub_process.stdout.decode() if isinstance(sub_process.stdout, bytes) else sub_process.stdout - err_decoded = sub_process.stderr.decode() if isinstance(sub_process.stderr, bytes) else sub_process.stderr + out_decoded = sub_process.stdout + err_decoded = sub_process.stderr error_msg = ( f"{log_prefix} Failed to run '{command}'. " From e13f4c214c3cdd365a497f72a298d77675ef0888 Mon Sep 17 00:00:00 2001 From: Meni Yakove Date: Mon, 25 Nov 2024 14:35:23 +0200 Subject: [PATCH 2/2] run_command, do not decode out and err --- webhook_server_container/libs/github_api.py | 4 +--- webhook_server_container/utils/helpers.py | 8 ++++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/webhook_server_container/libs/github_api.py b/webhook_server_container/libs/github_api.py index 029981d9..8419e580 100644 --- a/webhook_server_container/libs/github_api.py +++ b/webhook_server_container/libs/github_api.py @@ -2016,9 +2016,7 @@ def fix_podman_bug(self) -> None: shutil.rmtree("/tmp/storage-run-1000/libpod/tmp", ignore_errors=True) def run_podman_command(self, command: str, pipe: bool = False) -> Tuple[bool, str, str]: - rc, _out, _err = run_command(command=command, log_prefix=self.log_prefix, pipe=pipe) - out = _out.decode() if isinstance(_out, bytes) else _out - err = _err.decode() if isinstance(_err, bytes) else _err + rc, out, err = run_command(command=command, log_prefix=self.log_prefix, pipe=pipe) if rc: return rc, out, err diff --git a/webhook_server_container/utils/helpers.py b/webhook_server_container/utils/helpers.py index 4cd318d1..433c94b0 100644 --- a/webhook_server_container/utils/helpers.py +++ b/webhook_server_container/utils/helpers.py @@ -111,8 +111,12 @@ def run_command( timeout=timeout, **kwargs, ) - out_decoded = sub_process.stdout - err_decoded = sub_process.stderr + out_decoded = ( + sub_process.stdout.decode(errors="ignore") if isinstance(sub_process.stdout, bytes) else sub_process.stdout + ) + err_decoded = ( + sub_process.stderr.decode(errors="ignore") if isinstance(sub_process.stderr, bytes) else sub_process.stderr + ) error_msg = ( f"{log_prefix} Failed to run '{command}'. "