Skip to content

Commit 1eb9a92

Browse files
author
vshepard
committed
Update establish_ssh_tunnel
1 parent fffb23c commit 1eb9a92

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
readme = f.read()
2828

2929
setup(
30-
version='1.10.1',
30+
version='1.10.2',
3131
name='testgres',
3232
packages=['testgres', 'testgres.operations', 'testgres.helpers'],
3333
description='Testing utility for PostgreSQL and its extensions',

testgres/operations/remote_ops.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,14 @@ def is_port_open(host, port):
7676
except socket.error:
7777
return False
7878

79-
def establish_ssh_tunnel(self, local_port, remote_port):
79+
def establish_ssh_tunnel(self, local_port, remote_port, host):
8080
"""
8181
Establish an SSH tunnel from a local port to a remote PostgreSQL port.
8282
"""
83-
ssh_cmd = ['-N', '-L', f"{local_port}:localhost:{remote_port}"]
83+
if host != 'localhost':
84+
ssh_cmd = ['-N', '-L', f"localhost:{local_port}:{host}:{remote_port}"]
85+
else:
86+
ssh_cmd = ['-N', '-L', f"{local_port}:{host}:{remote_port}"]
8487
self.tunnel_process = self.exec_command(ssh_cmd, get_process=True, timeout=300)
8588
timeout = 10
8689
start_time = time.time()
@@ -412,10 +415,10 @@ def db_connect(self, dbname, user, password=None, host="localhost", port=5432):
412415
"""
413416
local_port = reserve_port()
414417
self.tunnel_port = local_port
415-
self.establish_ssh_tunnel(local_port=local_port, remote_port=port)
418+
self.establish_ssh_tunnel(local_port=local_port, remote_port=port, host=host)
416419
try:
417420
conn = pglib.connect(
418-
host=host,
421+
host='localhost',
419422
port=local_port,
420423
database=dbname,
421424
user=user,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy