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

Refactor sshtunnel #1808

Merged
merged 2 commits into from
Sep 19, 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
22 changes: 12 additions & 10 deletions src/teamster/libraries/ssh/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from dagster_ssh import SSHResource as DagsterSSHResource
from paramiko import AutoAddPolicy, SFTPAttributes, SFTPClient, SSHClient

from teamster.libraries.ssh.sshtunnel import SSHTunnelForwarder
from teamster.libraries.ssh.sshtunnel.forwarder import SSHTunnelForwarder


class SSHResource(DagsterSSHResource):
Expand Down Expand Up @@ -80,13 +80,15 @@ def get_connection(self) -> SSHClient:
def get_tunnel(
self, remote_port, remote_host="localhost", local_port=None
) -> SSHTunnelForwarder:
if self.tunnel_remote_host is not None:
remote_host = self.tunnel_remote_host

_check.int_param(obj=remote_port, param_name="remote_port")
_check.str_param(obj=remote_host, param_name="remote_host")
_check.int_param(obj=remote_port, param_name="remote_port")
_check.opt_int_param(obj=local_port, param_name="local_port")

if self.tunnel_remote_host is not None:
remote_bind_address = (self.tunnel_remote_host, remote_port)
else:
remote_bind_address = (remote_host, remote_port)

if local_port is not None:
local_bind_address = ("localhost", local_port)
else:
Expand All @@ -103,20 +105,20 @@ def get_tunnel(

if self.password and self.password.strip():
client = SSHTunnelForwarder(
self.remote_host,
ssh_port=self.remote_port,
ssh_address_or_host=self.remote_host,
ssh_port=int(self.remote_port),
ssh_username=self.username,
ssh_password=self.password,
ssh_pkey=pkey,
ssh_proxy=self._host_proxy,
local_bind_address=local_bind_address,
remote_bind_address=(remote_host, remote_port),
remote_bind_address=remote_bind_address,
logger=self._logger,
)
else:
client = SSHTunnelForwarder(
self.remote_host,
ssh_port=self.remote_port,
ssh_address_or_host=self.remote_host,
ssh_port=int(self.remote_port),
ssh_username=self.username,
ssh_pkey=pkey,
ssh_proxy=self._host_proxy,
Expand Down
14 changes: 14 additions & 0 deletions src/teamster/libraries/ssh/sshtunnel/errors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class BaseSSHTunnelForwarderError(Exception):
"""Exception raised by :class:`SSHTunnelForwarder` errors"""

def __init__(self, *args, **kwargs):
self.value = kwargs.pop("value", args[0] if args else "")

def __str__(self):
return self.value


class HandlerSSHTunnelForwarderError(BaseSSHTunnelForwarderError):
"""Exception for Tunnel forwarder errors"""

pass
Loading
Loading