Skip to content

Commit 9720a5c

Browse files
committed
Address SonarCloud / Bandit / ruff findings
Five SonarCloud findings cleared, two Bandit B104 suppressions tightened, one stray ruff F401 removed. - pyproject.toml (text:S8565) — add uv.lock so transitive versions are reproducible across CI / contributor machines (207 packages locked). - host_service.py:403 (python:S8572) — replace ``logging.error("...: %r", error)`` with ``logging.exception(...)`` so the traceback lands in the daemon's log. - webrtc_transport.py:323 (python:S7483) — fix the NOSONAR placement syntax. The em-dash separator confused Sonar's parser; explicit rule key + ``# reason:`` clause makes the suppression registered. The underlying use of ``asyncio.wait_for(timeout=...)`` stays because ``asyncio.timeout()`` only landed in 3.11 and the project supports 3.10. - web_viewer/index.html:1224 (javascript:S7785) — same fix as above for the service-worker registration: this file is a plain ``<script>`` so top-level await is not legal. - auto_control_exception_test.py:17 (python:S8518) — iterate the value directly out of the enumerate(); drop the now-unused index. Bandit B104 (hardcoded 0.0.0.0 bind): - tls_acme/challenge.py and usbip/server.py — both already had ``# noqa: S104 # NOSONAR python:S5332 # reason: ...`` justifying the external reachability requirement, but Bandit needs its own ``# nosec B104`` token on the same line. Added without removing the existing context. ruff F401: - visual_regression/compare.py — drop the unused ``List`` import.
1 parent b3a695b commit 9720a5c

8 files changed

Lines changed: 4133 additions & 12 deletions

File tree

je_auto_control/utils/remote_desktop/host_service.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,8 +399,8 @@ def SvcDoRun(self) -> None: # noqa: N802 pywin32 API
399399
)
400400
try:
401401
config = load_config()
402-
except (OSError, ValueError) as error:
403-
logging.error("config load failed: %r", error)
402+
except (OSError, ValueError):
403+
logging.exception("config load failed")
404404
return
405405
run_daemon(config)
406406
except ImportError:

je_auto_control/utils/remote_desktop/web_viewer/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1221,7 +1221,7 @@
12211221
// This file is a plain <script>, not a module, so top-level await is
12221222
// not legal here. Service-worker registration is best-effort: any
12231223
// rejection is silently swallowed.
1224-
navigator.serviceWorker.register("sw.js").catch(() => {}); // NOSONAR — non-module script: top-level await not allowed
1224+
navigator.serviceWorker.register("sw.js").catch(() => {}); // NOSONAR javascript:S7785 — non-module script: top-level await not allowed
12251225
}
12261226
</script>
12271227
</body>

je_auto_control/utils/remote_desktop/webrtc_transport.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ def _on_change() -> None:
335335
# asyncio.timeout() context manager only landed in Python 3.11;
336336
# this project supports 3.10, where wait_for(timeout=...) is the
337337
# idiomatic primitive.
338-
await asyncio.wait_for(future, timeout=timeout) # NOSONAR — Python 3.10 compatibility (asyncio.timeout requires 3.11+)
338+
await asyncio.wait_for(future, timeout=timeout) # NOSONAR python:S7483 # reason: asyncio.timeout() needs 3.11+; project supports 3.10
339339
except asyncio.TimeoutError:
340340
autocontrol_logger.warning(
341341
"webrtc: ICE gather timeout; sending what we have",

je_auto_control/utils/tls_acme/challenge.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class HttpChallengeServer:
5151
flow, stop.
5252
"""
5353

54-
def __init__(self, *, host: str = "0.0.0.0", # noqa: S104 # NOSONAR python:S5332 # reason: server must be reachable by Let's Encrypt's HTTP-01 validator from the public internet
54+
def __init__(self, *, host: str = "0.0.0.0", # noqa: S104 # nosec B104 # NOSONAR python:S5332 # reason: server must be reachable by Let's Encrypt's HTTP-01 validator from the public internet
5555
port: int = 80) -> None:
5656
self._host = host
5757
self._port = int(port)

je_auto_control/utils/usbip/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class UsbIpServer:
3232
"""Thread-per-connection USB/IP server bound to ``UrbBackend``."""
3333

3434
def __init__(self, backend: UrbBackend, *,
35-
host: str = "0.0.0.0", # noqa: S104 # NOSONAR python:S5332 # reason: USB/IP clients connect from other machines on the LAN
35+
host: str = "0.0.0.0", # noqa: S104 # nosec B104 # NOSONAR python:S5332 # reason: USB/IP clients connect from other machines on the LAN
3636
port: int = 3240) -> None:
3737
self._backend = backend
3838
self._host = host

je_auto_control/utils/visual_regression/compare.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import os
55
from dataclasses import dataclass, field
66
from pathlib import Path
7-
from typing import List, Optional, Sequence, Tuple
7+
from typing import Optional, Sequence, Tuple
88

99
from PIL import Image, ImageChops, ImageDraw
1010

test/unit_test/exception/auto_control_exception_test.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@
1414
ImageNotFoundException
1515
]
1616

17-
for index, value in enumerate(exception_list):
17+
for value in exception_list:
1818
try:
1919
print(value)
20-
if exception_list[index] != ImageNotFoundException:
21-
raise exception_list[index]()
22-
else:
23-
raise exception_list[index]("test.png")
20+
if value is not ImageNotFoundException:
21+
raise value()
22+
raise value("test.png")
2423
except Exception as error:
2524
print(repr(error))

uv.lock

Lines changed: 4122 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)