File tree Expand file tree Collapse file tree 4 files changed +19
-1
lines changed Expand file tree Collapse file tree 4 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -143,6 +143,7 @@ Contributors:
143143 * Doug Harris (dougharris)
144144 * Jay Knight (jay-knight)
145145 * fbdb
146+ * Charbel Jacquin (charbeljc)
146147
147148Creator:
148149--------
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ Features:
88 * Provide `init-command ` in the config file
99 * Support dsn specific init-command in the config file
1010* Add suggestion when setting the search_path
11+ * Allow per dsn_alias ssh tunnel selection
1112
1213Internal:
1314---------
Original file line number Diff line number Diff line change @@ -290,6 +290,7 @@ def __init__(
290290
291291 self .prompt_app = None
292292
293+ self .dsn_ssh_tunnel_config = c .get ("dsn ssh tunnels" )
293294 self .ssh_tunnel_config = c .get ("ssh tunnels" )
294295 self .ssh_tunnel_url = ssh_tunnel_url
295296 self .ssh_tunnel = None
@@ -643,6 +644,12 @@ def should_ask_for_password(exc):
643644 if "port" in parsed_dsn :
644645 port = parsed_dsn ["port" ]
645646
647+ if self .dsn_alias and self .dsn_ssh_tunnel_config and not self .ssh_tunnel_url :
648+ for dsn_regex , tunnel_url in self .dsn_ssh_tunnel_config .items ():
649+ if re .search (dsn_regex , self .dsn_alias ):
650+ self .ssh_tunnel_url = tunnel_url
651+ break
652+
646653 if self .ssh_tunnel_config and not self .ssh_tunnel_url :
647654 for db_host_regex , tunnel_url in self .ssh_tunnel_config .items ():
648655 if re .search (db_host_regex , host ):
@@ -1540,8 +1547,8 @@ def cli(
15401547 fg = "red" ,
15411548 )
15421549 sys .exit (1 )
1543- pgcli .connect_uri (dsn_config )
15441550 pgcli .dsn_alias = dsn
1551+ pgcli .connect_uri (dsn_config )
15451552 elif "://" in database :
15461553 pgcli .connect_uri (database )
15471554 elif "=" in database and service is None :
Original file line number Diff line number Diff line change @@ -258,3 +258,12 @@ float = ""
258258[column_date_formats]
259259# use strftime format, e.g.
260260# created = "%Y-%m-%d"
261+
262+ # Per host ssh tunnel configuration
263+ [ssh tunnels]
264+ # ^example.*\.host$ = myuser:[email protected] :4000265+ # .*\.net = another.tunnel.com
266+
267+ # Per dsn_alias ssh tunnel configuration
268+ [dsn ssh tunnels]
269+ # ^example_dsn$ = myuser:[email protected] :4000
You can’t perform that action at this time.
0 commit comments