Skip to content

Commit

Permalink
Merge branch 'develop' into fix-doc-link
Browse files Browse the repository at this point in the history
  • Loading branch information
ktbyers committed May 3, 2024
2 parents 8d0684e + 707e9d9 commit dc5cc9b
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ jobs:
name: linters
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Setup python
uses: actions/setup-python@v1
uses: actions/setup-python@v5
id: cp311
with:
python-version: '3.11'
Expand Down Expand Up @@ -62,21 +62,15 @@ jobs:

runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Setup python
uses: actions/setup-python@v1
uses: actions/setup-python@v5
id: py_ver
with:
python-version: ${{ matrix.python-version }}
architecture: x64

- name: Setup python
uses: actions/setup-python@v1
with:
python-version: '3.11'
architecture: x64

- name: Install Poetry
uses: snok/install-poetry@v1
with:
Expand Down
4 changes: 3 additions & 1 deletion netmiko/base_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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."""
Expand Down
12 changes: 8 additions & 4 deletions netmiko/sophos/sophos_sfos_ssh.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions netmiko/ssh_autodetect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
12 changes: 11 additions & 1 deletion tests/unit/test_base_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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

0 comments on commit dc5cc9b

Please sign in to comment.