Files
napalm-linux/napalm_linux/_hardening.py
T
Christian Manivong b67c1b3c53
driver / lint (pull_request) Successful in 12s
driver / standard (pull_request) Successful in 15s
driver / types (pull_request) Successful in 58s
driver / test (3.13) (pull_request) Successful in 53s
driver / test (3.12) (pull_request) Successful in 59s
driver / lowest (pull_request) Successful in 27s
driver / build (pull_request) Successful in 27s
driver / security (pull_request) Successful in 1m2s
CI / driver (pull_request) Successful in 2m10s
driver / publish (pull_request) Skipped
refactor(hardening): the transport in a module of its own, not in linux.py (NetOrk/netork#2706)
linux.py is at napalm-standard's recorded size; LinuxHardeningMixin rides
along with the other readings' transports instead.
2026-11-27 01:49:07 +01:00

35 lines
1.2 KiB
Python

"""How the host is hardened: napalm-device-types' ``HardeningMixin`` (NetOrk/netork#2706).
The command and its parse are napalm-device-types'; this is only how the command
reaches the host. An exec channel, since ``aa-status --json`` prints one line longer
than the PTY netmiko holds reliably takes. Read-only either way; root only for
AppArmor's profiles, and the mixin falls back to the login user where it is refused.
"""
from __future__ import annotations
from typing import TYPE_CHECKING
from napalm_device_types import CommandResult, HardeningMixin
#: Seconds the reading may take: a handful of small files and two quick tools.
_READ_TIMEOUT = 60
class LinuxHardeningMixin(HardeningMixin):
"""The transport for ``get_hardening``."""
if TYPE_CHECKING: # pragma: no cover - the driver's own, declared for type checkers
def run_command(
self,
command: str,
*,
privileged: bool = False,
timeout: float = 60,
stdin: bytes | None = None,
) -> CommandResult: ...
def _run_hardening_command(self, command: str, *, privileged: bool) -> str:
return self.run_command(command, privileged=privileged, timeout=_READ_TIMEOUT).stdout