Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SSHHook expose auth_timeout parameter #43048

Merged
merged 2 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions providers/src/airflow/providers/ssh/hooks/ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class SSHHook(BaseHook):
iterable of algorithm identifiers, which will be disabled for the
lifetime of the transport
:param ciphers: list of ciphers to use in order of preference
:param auth_timeout: timeout (in seconds) for the attempt to authenticate with the remote_host
"""

# List of classes to try loading private keys as, ordered (roughly) by most common to least common
Expand Down Expand Up @@ -121,6 +122,7 @@ def __init__(
banner_timeout: float = 30.0,
disabled_algorithms: dict | None = None,
ciphers: list[str] | None = None,
auth_timeout: int | None = None,
) -> None:
super().__init__()
self.ssh_conn_id = ssh_conn_id
Expand All @@ -138,6 +140,7 @@ def __init__(
self.disabled_algorithms = disabled_algorithms
self.ciphers = ciphers
self.host_proxy_cmd = None
self.auth_timeout = auth_timeout

# Default values, overridable from Connection
self.compress = True
Expand Down Expand Up @@ -332,6 +335,7 @@ def get_conn(self) -> paramiko.SSHClient:
"sock": self.host_proxy,
"look_for_keys": self.look_for_keys,
"banner_timeout": self.banner_timeout,
"auth_timeout": self.auth_timeout,
}

if self.password:
Expand Down
12 changes: 12 additions & 0 deletions providers/tests/ssh/hooks/test_ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ def test_ssh_connection_with_password(self, ssh_mock):
port="port",
sock=None,
look_for_keys=True,
auth_timeout=None,
)

@mock.patch("airflow.providers.ssh.hooks.ssh.paramiko.SSHClient")
Expand All @@ -381,6 +382,7 @@ def test_ssh_connection_without_password(self, ssh_mock):
port="port",
sock=None,
look_for_keys=True,
auth_timeout=None,
)

@mock.patch("airflow.providers.ssh.hooks.ssh.SSHTunnelForwarder")
Expand Down Expand Up @@ -569,6 +571,7 @@ def test_ssh_connection_with_private_key_extra(self, ssh_mock):
port="port",
sock=None,
look_for_keys=True,
auth_timeout=None,
)

@mock.patch("airflow.providers.ssh.hooks.ssh.paramiko.SSHClient")
Expand All @@ -592,6 +595,7 @@ def test_ssh_connection_with_private_key_passphrase_extra(self, ssh_mock):
port="port",
sock=None,
look_for_keys=True,
auth_timeout=None,
)

@mock.patch("airflow.providers.ssh.hooks.ssh.paramiko.SSHClient")
Expand Down Expand Up @@ -654,6 +658,7 @@ def test_ssh_connection_with_conn_timeout(self, ssh_mock):
password="password",
conn_timeout=20,
key_file="fake.file",
auth_timeout=10,
)

with hook.get_conn():
Expand All @@ -668,6 +673,7 @@ def test_ssh_connection_with_conn_timeout(self, ssh_mock):
port="port",
sock=None,
look_for_keys=True,
auth_timeout=10,
)

@mock.patch("airflow.providers.ssh.hooks.ssh.paramiko.SSHClient")
Expand Down Expand Up @@ -695,6 +701,7 @@ def test_ssh_connection_with_conn_timeout_and_timeout(self, ssh_mock):
port="port",
sock=None,
look_for_keys=True,
auth_timeout=None,
)

@mock.patch("airflow.providers.ssh.hooks.ssh.paramiko.SSHClient")
Expand All @@ -718,6 +725,7 @@ def test_ssh_connection_with_timeout_extra(self, ssh_mock):
port="port",
sock=None,
look_for_keys=True,
auth_timeout=None,
)

@mock.patch("airflow.providers.ssh.hooks.ssh.paramiko.SSHClient")
Expand All @@ -743,6 +751,7 @@ def test_ssh_connection_with_conn_timeout_extra(self, ssh_mock):
port="port",
sock=None,
look_for_keys=True,
auth_timeout=None,
)

@mock.patch("airflow.providers.ssh.hooks.ssh.paramiko.SSHClient")
Expand All @@ -768,6 +777,7 @@ def test_ssh_connection_with_timeout_extra_and_conn_timeout_extra(self, ssh_mock
port="port",
sock=None,
look_for_keys=True,
auth_timeout=None,
)

@pytest.mark.parametrize(
Expand Down Expand Up @@ -837,6 +847,7 @@ def test_ssh_connection_with_all_timeout_param_and_extra_combinations(
port="port",
sock=None,
look_for_keys=True,
auth_timeout=None,
)

@pytest.mark.parametrize(
Expand Down Expand Up @@ -901,6 +912,7 @@ def test_ssh_with_extra_disabled_algorithms(self, ssh_mock):
sock=None,
look_for_keys=True,
disabled_algorithms=TEST_DISABLED_ALGORITHMS,
auth_timeout=None,
)

@mock.patch("airflow.providers.ssh.hooks.ssh.paramiko.SSHClient")
Expand Down