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:
1 parent
09029ca0a4
commit
01b2a2ae58
2 files changed
+11
-5
No files matched your search
@@ -8,14 +8,19 @@ sensors, the power state and the system event log, and switches the server's pow
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import logging
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from napalm.base.exceptions import ConnectionException
|
from napalm.base.exceptions import ConnectionException
|
||||||
from napalm_device_types import HealthMetricsMixin, ManagementControllerDriver
|
from napalm_device_types import HealthMetricsMixin, ManagementControllerDriver
|
||||||
from napalm_device_types.models import POWER_ACTIONS
|
from napalm_device_types.models import POWER_ACTIONS
|
||||||
from pyghmi.exceptions import IpmiException
|
|
||||||
from pyghmi.ipmi.command import Command
|
# IPMI is this driver's protocol: the fallback for BMCs without Redfish (see above).
|
||||||
from pyghmi.ipmi.private.session import Session
|
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]
|
_JsonDict = dict[str, Any]
|
||||||
|
|
||||||
@@ -93,7 +98,7 @@ class IpmiDriver(HealthMetricsMixin, ManagementControllerDriver):
|
|||||||
try:
|
try:
|
||||||
ipmi.ipmi_session.logout()
|
ipmi.ipmi_session.logout()
|
||||||
except Exception: # a session left open times out on the BMC
|
except Exception: # a session left open times out on the BMC
|
||||||
pass
|
LOG.debug("%s: ignored", self.hostname, exc_info=True)
|
||||||
self._forget_session()
|
self._forget_session()
|
||||||
|
|
||||||
def _forget_session(self) -> None:
|
def _forget_session(self) -> None:
|
||||||
|
|||||||
@@ -35,7 +35,8 @@ def to_napalm_users(accounts: Iterable[Mapping[str, Any] | None]) -> dict[str, d
|
|||||||
continue
|
continue
|
||||||
users[acc["username"]] = {
|
users[acc["username"]] = {
|
||||||
"level": ROLE_LEVELS.get(acc.get("role_id") or "", 0),
|
"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": [],
|
"sshkeys": [],
|
||||||
}
|
}
|
||||||
return users
|
return users
|
||||||
Reference in new issue
Block a user