fix: what bandit and the remaining lint rules found

- ipmi: a failed logout on close is logged at debug level instead of
  passed over (B110); the session still times out on the BMC.
- ipmi: the pyghmi imports are this driver's protocol, the fallback for
  BMCs without Redfish, documented as insecure in the module and in
  docs/security.md (nosec B415).
- parsers.accounts: the empty password is NAPALM's get_users field;
  Redfish never returns one (nosec B105).
This commit is contained in:
Christian Manivong committed 2026-10-23 08:40:23 +02:00
1 parent 09029ca0a4
commit 01b2a2ae58
2 files changed
+11 -5

No files matched your search

+9 -4
View File
@@ -8,14 +8,19 @@ sensors, the power state and the system event log, and switches the server's pow
from __future__ import annotations
import logging
from typing import Any
from napalm.base.exceptions import ConnectionException
from napalm_device_types import HealthMetricsMixin, ManagementControllerDriver
from napalm_device_types.models import POWER_ACTIONS
from pyghmi.exceptions import IpmiException
from pyghmi.ipmi.command import Command
from pyghmi.ipmi.private.session import Session
# IPMI is this driver's protocol: the fallback for BMCs without Redfish (see above).
from pyghmi.exceptions import IpmiException # nosec B415
from pyghmi.ipmi.command import Command # nosec B415
from pyghmi.ipmi.private.session import Session # nosec B415
LOG = logging.getLogger(__name__)
_JsonDict = dict[str, Any]
@@ -93,7 +98,7 @@ class IpmiDriver(HealthMetricsMixin, ManagementControllerDriver):
try:
ipmi.ipmi_session.logout()
except Exception: # a session left open times out on the BMC
pass
LOG.debug("%s: ignored", self.hostname, exc_info=True)
self._forget_session()
def _forget_session(self) -> None:
+2 -1
View File
@@ -35,7 +35,8 @@ def to_napalm_users(accounts: Iterable[Mapping[str, Any] | None]) -> dict[str, d
continue
users[acc["username"]] = {
"level": ROLE_LEVELS.get(acc.get("role_id") or "", 0),
"password": "",
# NAPALM's get_users field; Redfish never returns a password, so it stays empty.
"password": "", # nosec B105
"sshkeys": [],
}
return users