GRM-24: fix: resolve bandit security warnings in source code and tests
This commit is contained in:
+3
-3
@@ -6,7 +6,7 @@ Usage:
|
||||
"""
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
import subprocess # nosec B404
|
||||
import sys
|
||||
|
||||
import click
|
||||
@@ -19,7 +19,7 @@ from gitea_runner_manager.i18n import _
|
||||
|
||||
def build_package() -> None:
|
||||
"""Build the Python package using python -m build."""
|
||||
result = subprocess.run(
|
||||
result = subprocess.run( # nosec B603
|
||||
[sys.executable, "-m", "build"],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
@@ -36,7 +36,7 @@ def build_package() -> None:
|
||||
|
||||
def publish_to_pypi(token: str) -> None:
|
||||
"""Publish built packages to PyPI using twine."""
|
||||
result = subprocess.run(
|
||||
result = subprocess.run( # nosec B603
|
||||
[
|
||||
sys.executable,
|
||||
"-m",
|
||||
|
||||
@@ -8,7 +8,7 @@ Rules:
|
||||
"""
|
||||
|
||||
import re
|
||||
import subprocess
|
||||
import subprocess # nosec B404
|
||||
|
||||
import click
|
||||
|
||||
@@ -24,7 +24,7 @@ def first_line(text: str) -> str:
|
||||
|
||||
def get_branch() -> str:
|
||||
try:
|
||||
result = subprocess.run(
|
||||
result = subprocess.run( # nosec
|
||||
["git", "symbolic-ref", "--short", "HEAD"],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
|
||||
@@ -5,7 +5,7 @@ from __future__ import annotations
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
import subprocess # nosec B404
|
||||
import sys
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
@@ -62,14 +62,14 @@ class AnsibleExecutor:
|
||||
"""Execute command, streaming stdout+stderr to log file. Returns exit code."""
|
||||
env = os.environ.copy()
|
||||
with open(log_file, "a") as f:
|
||||
proc = subprocess.Popen(
|
||||
proc = subprocess.Popen( # nosec B603
|
||||
cmd,
|
||||
env=env,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT,
|
||||
text=True,
|
||||
)
|
||||
assert proc.stdout is not None
|
||||
assert proc.stdout is not None # nosec B101
|
||||
try:
|
||||
for line in proc.stdout:
|
||||
f.write(line)
|
||||
@@ -108,7 +108,7 @@ class AnsibleExecutor:
|
||||
cmd.append("--ask-become-pass")
|
||||
|
||||
env = os.environ.copy()
|
||||
proc = subprocess.run(
|
||||
proc = subprocess.run( # nosec B603
|
||||
cmd,
|
||||
env=env,
|
||||
capture_output=True,
|
||||
@@ -137,6 +137,6 @@ class AnsibleExecutor:
|
||||
)
|
||||
if match:
|
||||
return match.group(1).replace("\\n", " ").strip()
|
||||
except Exception:
|
||||
pass
|
||||
except OSError:
|
||||
return None
|
||||
return None
|
||||
|
||||
@@ -330,7 +330,7 @@ class RunnerManager:
|
||||
ask_become_pass=True,
|
||||
check=False,
|
||||
)
|
||||
except Exception:
|
||||
except AnsibleError:
|
||||
continue
|
||||
status = self._parse_status(stdout)
|
||||
if status != "unknown":
|
||||
@@ -351,7 +351,7 @@ class RunnerManager:
|
||||
check=False,
|
||||
)
|
||||
service_status = self._parse_status(stdout)
|
||||
except Exception:
|
||||
except AnsibleError:
|
||||
service_status = "unknown"
|
||||
else:
|
||||
try:
|
||||
@@ -366,7 +366,7 @@ class RunnerManager:
|
||||
check=False,
|
||||
)
|
||||
service_status = self._parse_status(stdout)
|
||||
except Exception:
|
||||
except AnsibleError:
|
||||
service_status = "unknown"
|
||||
# Translate known status values
|
||||
translated_status = _(
|
||||
|
||||
@@ -518,7 +518,7 @@ class TestRunnerManager:
|
||||
}
|
||||
manager = RunnerManager(registry=mock_registry)
|
||||
mock_executor = MagicMock()
|
||||
mock_executor.run_ad_hoc.side_effect = Exception("ssh fail")
|
||||
mock_executor.run_ad_hoc.side_effect = AnsibleError("ssh fail")
|
||||
manager._executor = mock_executor
|
||||
|
||||
runners = manager.list_runners()
|
||||
@@ -579,7 +579,7 @@ class TestRunnerManager:
|
||||
}
|
||||
manager = RunnerManager(registry=mock_registry)
|
||||
mock_executor = MagicMock()
|
||||
mock_executor.run_ad_hoc.side_effect = [Exception("ssh fail"), "running"]
|
||||
mock_executor.run_ad_hoc.side_effect = [AnsibleError("ssh fail"), "running"]
|
||||
manager._executor = mock_executor
|
||||
|
||||
runners = manager.list_runners()
|
||||
@@ -593,7 +593,7 @@ class TestRunnerManager:
|
||||
}
|
||||
manager = RunnerManager(registry=mock_registry)
|
||||
mock_executor = MagicMock()
|
||||
mock_executor.run_ad_hoc.side_effect = Exception("ssh fail")
|
||||
mock_executor.run_ad_hoc.side_effect = AnsibleError("ssh fail")
|
||||
manager._executor = mock_executor
|
||||
|
||||
runners = manager.list_runners()
|
||||
|
||||
Reference in New Issue
Block a user