fix: what bandit and the remaining lint rules found

- The six except Exception: pass (REST logout, the extra-ports lookup, the
  per-port detail in get_interfaces, closing CLI and REST sessions) now log
  at debug level (B110), so a swallowed failure leaves a trace.
- nosec for comparing a reported address with 0.0.0.0 (B104) and for the
  empty password field of get_users (B105, now a named constant); both are
  false positives.
- A long error message is split into adjacent f-strings; the unused ARP
  entry type is named _entry_type.
- tests: the failed-open test expects ConnectionException instead of any
  Exception; raise ... from exc.
This commit is contained in:
Christian Manivong committed 2026-10-23 08:34:55 +02:00
1 parent c2a788fa7a
commit fc24495b83
5 files changed
+19 -13

No files matched your search

+7 -3
View File
@@ -9,6 +9,9 @@ backends.
import re
#: get_users' password field: the switch never shows a password, so it stays empty.
_PASSWORD_NOT_SHOWN = "" # nosec B105
# ---------------------------------------------------------------------------
# MAC address helpers
# ---------------------------------------------------------------------------
@@ -330,7 +333,8 @@ def parse_ip_interfaces(output: str) -> dict[str, dict]:
# Single VLAN output (no header): detect from "IP Address" line
if re.search(r"IP\s+Address\s*:", line, re.I):
ip = line.split(":", 1)[-1].strip()
if ip and ip not in ("0.0.0.0", ""):
# An unset address reported by the switch, not a bind address.
if ip and ip != "0.0.0.0": # nosec B104
current_ip = ip
if not current_vlan:
current_vlan = "VLAN1"
@@ -375,7 +379,7 @@ def parse_arp_table(output: str) -> list[dict]:
m = _ARP_RE.search(line)
if not m:
continue
ip, mac, entry_type, port = (m.group(1), m.group(2), m.group(3), m.group(4) or "")
ip, mac, _entry_type, port = (m.group(1), m.group(2), m.group(3), m.group(4) or "")
table.append(
{
"interface": port,
@@ -665,7 +669,7 @@ def parse_users(output: str) -> dict[str, dict]:
priv = 1
users[uname] = {
"level": priv,
"password": "",
"password": _PASSWORD_NOT_SHOWN,
"sshkeys": [],
}
return users