refactor(hardening): the transport in a module of its own, not in linux.py (NetOrk/netork#2706)
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
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
linux.py is at napalm-standard's recorded size; LinuxHardeningMixin rides along with the other readings' transports instead.
This commit is contained in:
1 parent
2aba6babcf
commit
b67c1b3c53
3 files changed
+45
-11
No files matched your search
@@ -0,0 +1,34 @@
|
||||
"""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
|
||||
Reference in new issue
Block a user