fix: what bandit and the remaining lint rules found
- driver.py: the logger is defined after the imports (E402). The lazy paramiko client is annotated Any, as _node_ssh already is; the quoted paramiko.SSHClient named a module that is never imported there (F821). - Unused locals are gone: get_facts' hostname, get_users' groups (both read a value nobody used), the ARP flags column is _flags; the output is unchanged. - Long lines are wrapped: the apt-get and snmpd.conf commands are split into adjacent string literals, the power-action error message and the system mixin's docstring are wrapped; the text is unchanged. - get_vm_status re-raises with raise ... from e (B904). - The two except Exception: pass (closing the SSH session, the is_alive probe) now log at debug level (B110), so a swallowed failure leaves a trace. - nosec for the empty "password" field of NAPALM's get_users shape and the ssh_password_auth flag (B105); all three are false positives. - tests: unused loop variables.
This commit is contained in:
1 parent
3b873d91fe
commit
3365207c98
6 files changed
+28
-19
No files matched your search
@@ -12,7 +12,10 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
"""System-level NAPALM getters for Proxmox VE nodes (environment, NTP, SNMP, users, packages, services, updates, disk SMART)."""
|
||||
"""System-level NAPALM getters for Proxmox VE nodes.
|
||||
|
||||
Environment, NTP, SNMP, users, packages, services, updates and disk SMART.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
@@ -224,7 +227,6 @@ class ProxmoxSystemMixin:
|
||||
if not uid:
|
||||
continue
|
||||
# Proxmox roles: Administrator -> 15, otherwise 1
|
||||
groups = user.get("groups", "") or ""
|
||||
level = 1
|
||||
try:
|
||||
roles = self._api.access.users(uid).get() or {} # type: ignore[union-attr]
|
||||
@@ -234,7 +236,8 @@ class ProxmoxSystemMixin:
|
||||
logger.debug("Failed to fetch roles for user %s: %s", uid, exc)
|
||||
result[uid] = {
|
||||
"level": level,
|
||||
"password": "",
|
||||
# NAPALM's get_users shape; the password is never read.
|
||||
"password": "", # nosec B105
|
||||
"sshkeys": [],
|
||||
}
|
||||
|
||||
@@ -252,7 +255,8 @@ class ProxmoxSystemMixin:
|
||||
if uname not in result and uid_int < 1000 or uid_int == 0:
|
||||
result[uname] = {
|
||||
"level": 15 if uid_int == 0 else 0,
|
||||
"password": "",
|
||||
# NAPALM's get_users shape; the password is never read.
|
||||
"password": "", # nosec B105
|
||||
"sshkeys": [],
|
||||
}
|
||||
|
||||
@@ -445,7 +449,8 @@ class ProxmoxSystemMixin:
|
||||
raise ValueError(f"Invalid package name: {pkg!r}")
|
||||
pkg_args = " ".join(packages)
|
||||
output = self._exec_ssh_command(
|
||||
f"DEBIAN_FRONTEND=noninteractive apt-get install --only-upgrade -y {pkg_args} 2>&1 || true"
|
||||
"DEBIAN_FRONTEND=noninteractive apt-get install --only-upgrade -y "
|
||||
f"{pkg_args} 2>&1 || true"
|
||||
)
|
||||
return {"success": True, "output": output}
|
||||
|
||||
@@ -475,7 +480,8 @@ class ProxmoxSystemMixin:
|
||||
port = 161
|
||||
try:
|
||||
conf = self._exec_ssh_command(
|
||||
"grep -E '^[[:space:]]*(ro|rw)?community' /etc/snmp/snmpd.conf 2>/dev/null | head -5"
|
||||
"grep -E '^[[:space:]]*(ro|rw)?community' /etc/snmp/snmpd.conf "
|
||||
"2>/dev/null | head -5"
|
||||
)
|
||||
for line in conf.splitlines():
|
||||
parts = line.split()
|
||||
@@ -809,7 +815,8 @@ class ProxmoxSystemMixin:
|
||||
"timezone": None,
|
||||
"ntp_servers": [],
|
||||
"ssh_port": 22,
|
||||
"ssh_password_auth": False,
|
||||
# A flag, not a password.
|
||||
"ssh_password_auth": False, # nosec B105
|
||||
}
|
||||
|
||||
# Cluster name and node list from /cluster/status
|
||||
|
||||
Reference in new issue
Block a user