From a1ff4f37348f862bbab72f396fe3e8a2babc40d5 Mon Sep 17 00:00:00 2001 From: Hendrik Dumith Louzada Date: Fri, 18 Oct 2024 15:16:23 -0300 Subject: [PATCH 1/2] fix(ipythonconsole): provide username, host and port from hostname info in ssh tunnels --- spyder/plugins/ipythonconsole/utils/client.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/spyder/plugins/ipythonconsole/utils/client.py b/spyder/plugins/ipythonconsole/utils/client.py index de964d9a690..c17fc983a62 100644 --- a/spyder/plugins/ipythonconsole/utils/client.py +++ b/spyder/plugins/ipythonconsole/utils/client.py @@ -102,14 +102,14 @@ def tunnel_to_kernel( ) elif sshkey is not None: self.__tunnel_handler = KernelClientTunneler.new_connection( - tunnel=hostname, password=password, client_keys=[sshkey], + **self._split_shh_address(hostname), ) - else: + else: self.__tunnel_handler = KernelClientTunneler.new_connection( - tunnel=hostname, password=password, + **self._split_shh_address(hostname), ) ( @@ -129,3 +129,12 @@ def tunnel_to_kernel( ) ) self.ip = "127.0.0.1" # Tunneled to localhost + + @staticmethod + def _split_shh_address(address): + """Split ssh address into host and port.""" + user_host, _, port = address.partition(':') + user, _, host = user_host.rpartition('@') + return {'username': user if user else None, + 'host': host if host else None, + 'port': int(port) if port else None} From 789ffc984f4ddb2b5aca7aecc0acc88e7c692667 Mon Sep 17 00:00:00 2001 From: Carlos Cordoba Date: Mon, 28 Oct 2024 12:18:47 -0500 Subject: [PATCH 2/2] Apply suggestions from code review --- spyder/plugins/ipythonconsole/utils/client.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/spyder/plugins/ipythonconsole/utils/client.py b/spyder/plugins/ipythonconsole/utils/client.py index c17fc983a62..7f10a69bc5d 100644 --- a/spyder/plugins/ipythonconsole/utils/client.py +++ b/spyder/plugins/ipythonconsole/utils/client.py @@ -106,7 +106,7 @@ def tunnel_to_kernel( client_keys=[sshkey], **self._split_shh_address(hostname), ) - else: + else: self.__tunnel_handler = KernelClientTunneler.new_connection( password=password, **self._split_shh_address(hostname), @@ -135,6 +135,8 @@ def _split_shh_address(address): """Split ssh address into host and port.""" user_host, _, port = address.partition(':') user, _, host = user_host.rpartition('@') - return {'username': user if user else None, - 'host': host if host else None, - 'port': int(port) if port else None} + return { + 'username': user if user else None, + 'host': host if host else None, + 'port': int(port) if port else None + }