-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #120 from analyst-collective/feature/ssh-forwarding
ssh forwarding
- Loading branch information
Showing
5 changed files
with
83 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
|
||
from sshtunnel import SSHTunnelForwarder, BaseSSHTunnelForwarderError | ||
import logging | ||
|
||
# modules are only imported once -- make sure that we don't have > 1 | ||
# because subsequent tunnels will block waiting to acquire the port | ||
|
||
server = None | ||
|
||
def get_or_create_tunnel(host, port, user, remote_host, remote_port): | ||
global server | ||
if server is None: | ||
logger = logging.getLogger(__name__) | ||
|
||
bind_from = (host, port) | ||
bind_to = (remote_host, remote_port) | ||
|
||
server = SSHTunnelForwarder(bind_from, ssh_username=user, remote_bind_address=bind_to, logger=logger) | ||
try: | ||
server.start() | ||
except BaseSSHTunnelForwarderError as e: | ||
raise RuntimeError("Problem connecting through {}:{}: {}".format(host, port, str(e))) | ||
|
||
return server |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,5 @@ psycopg2==2.6.1 | |
sqlparse==0.1.19 | ||
networkx==1.11 | ||
csvkit==0.9.1 | ||
paramiko==2.0.1 | ||
sshtunnel==0.0.8.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,5 +29,7 @@ | |
'sqlparse==0.1.19', | ||
'networkx==1.11', | ||
'csvkit==0.9.1', | ||
'paramiko==2.0.1', | ||
'sshtunnel==0.0.8.2' | ||
], | ||
) |