Connect to databases via ssh tunnel
A command tool and library to connect to databases with minimal fuss.
$ pip install tunneler
$ tunneler name_of_task name_of_connection
As the above command shows, there are two concepts to understand when running tunneler, connections and tasks.
Define connections in a connections.yaml file in your current directory, as follows:
prod: remote_host: publicjumpboxservername ssh_username: username ssh_pkey: | -----BEGIN RSA PRIVATE KEY----- ....................................... ....................................... -----END RSA PRIVATE KEY----- private_dburl: postgres://username:password@privatedbservername/databasename local_port: 5433 dev: .....
Tunneler will use this information to set up a local tunneled post where you can access this database directly.
A connection URL to this local port will then be provided to each task.
There are three inbuilt tasks:
- test_connection (run this one to check your config is correct)
So for example to dump the production schema we’d run the following command:
$ tunneler do_schema_pg_dump prod
Want to define your own tasks? Simply create a tasks.py file (or module) in the current directory.
Define a top level method in this file that accepts a connection url, and that method name will be available as a task.
For instance, the test connection task could be re-implemented as follows:
from sqlbag import S def test_connection_custom(dburl): with S(dburl) as s: s.execute('select 1')
You’d then run this as follows:
$ tunneler test_connection_custom prod
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size||File type||Python version||Upload date||Hashes|
|Filename, size tunneler-0.1.1490665985-py2.py3-none-any.whl (6.9 kB)||File type Wheel||Python version 3.6||Upload date||Hashes View|
|Filename, size tunneler-0.1.1490665985.tar.gz (3.8 kB)||File type Source||Python version None||Upload date||Hashes View|
Hashes for tunneler-0.1.1490665985-py2.py3-none-any.whl