diff --git a/netmiko/base_connection.py b/netmiko/base_connection.py index 39bac3b92..8433fc49f 100644 --- a/netmiko/base_connection.py +++ b/netmiko/base_connection.py @@ -388,7 +388,8 @@ def __init__( if self.secret: no_log["secret"] = self.secret # Always sanitize username and password - log.addFilter(SecretsFilter(no_log=no_log)) + self._secrets_filter = SecretsFilter(no_log=no_log) + log.addFilter(self._secrets_filter) # Netmiko will close the session_log if we open the file if session_log is not None: @@ -2480,6 +2481,7 @@ def disconnect(self) -> None: self.remote_conn = None if self.session_log: self.session_log.close() + log.removeFilter(self._secrets_filter) def commit(self) -> str: """Commit method for platforms that support this.""" diff --git a/netmiko/sophos/sophos_sfos_ssh.py b/netmiko/sophos/sophos_sfos_ssh.py index 27b34ee20..c1295c0bd 100644 --- a/netmiko/sophos/sophos_sfos_ssh.py +++ b/netmiko/sophos/sophos_sfos_ssh.py @@ -1,16 +1,20 @@ """SophosXG (SFOS) Firewall support""" -import time from typing import Any +import time +import os from netmiko.no_enable import NoEnable from netmiko.no_config import NoConfig from netmiko.cisco_base_connection import CiscoSSHConnection +SOPHOS_MENU_DEFAULT = os.getenv("NETMIKO_SOPHOS_MENU", "4") + + class SophosSfosSSH(NoEnable, NoConfig, CiscoSSHConnection): def session_preparation(self) -> None: """Prepare the session after the connection has been established.""" - self._test_channel_read() + self._test_channel_read(pattern=r"Main Menu") """ Sophos Firmware Version SFOS 18.0.0 GA-Build339 @@ -27,8 +31,8 @@ def session_preparation(self) -> None: Select Menu Number [0-7]: """ - self.write_channel("4" + self.RETURN) - self._test_channel_read(pattern=r"[console>]") + self.write_channel(SOPHOS_MENU_DEFAULT + self.RETURN) + self._test_channel_read(pattern=r"[#>]") self.set_base_prompt() # Clear the read buffer time.sleep(0.3 * self.global_delay_factor) diff --git a/netmiko/ssh_autodetect.py b/netmiko/ssh_autodetect.py index 186b8fd98..1722688d4 100644 --- a/netmiko/ssh_autodetect.py +++ b/netmiko/ssh_autodetect.py @@ -94,6 +94,12 @@ "priority": 99, "dispatch": "_autodetect_std", }, + "cisco_ftd": { + "cmd": "show version", + "search_patterns": [r"Cisco Firepower"], + "priority": 99, + "dispatch": "_autodetect_std", + }, "cisco_ios": { "cmd": "show version", "search_patterns": [ diff --git a/tests/unit/test_base_connection.py b/tests/unit/test_base_connection.py index 350586402..1e8b7d037 100755 --- a/tests/unit/test_base_connection.py +++ b/tests/unit/test_base_connection.py @@ -4,7 +4,7 @@ from os.path import dirname, join from threading import Lock -from netmiko import NetmikoTimeoutException +from netmiko import NetmikoTimeoutException, log from netmiko.base_connection import BaseConnection RESOURCE_FOLDER = join(dirname(dirname(__file__)), "etc") @@ -480,3 +480,13 @@ def test_strip_ansi_codes(): # code_next_line must be substituted with a return assert connection.strip_ansi_escape_codes("\x1bE") == "\n" + + +def test_remove_SecretsFilter_after_disconnection(): + connection = BaseConnection( + host="testhost", # Enter the hostname to pass initialization + auto_connect=False, # No need to connect for the test purposes + ) + connection.disconnect() + + assert not log.filters