tunneler: Connect to databases via ssh tunnel
A command tool and library to connect to databases with minimal fuss.
To install:
$ pip install tunneler
To run:
$ 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)
do_full_pg_dump
do_schema_pg_dump
So for example to dump the production schema we’d run the following command:
$ tunneler do_schema_pg_dump prod
Custom tasks
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
Pretty simple.
Metadata
Release files for tunneler 0.1.1490665985
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| tunneler-0.1.1490665985.tar.gz | 3.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| tunneler-0.1.1490665985-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details |
Total release size: 10.7 kB
Release files / tunneler-0.1.1490665985.tar.gz
| Download URL | tunneler-0.1.1490665985.tar.gz |
|---|---|
| Size | 3.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f9c58289d0725cfdcf2822fce75315a838fedfb14aa948a3193039ce12f37ebc
|
|
BLAKE2b-256 checksum How to use checksums |
c04ce6f38fbfe05a130c98680d22321d23d8a6679be83f1f7f8886a68373c9c7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / tunneler-0.1.1490665985-py2.py3-none-any.whl
| Download URL | tunneler-0.1.1490665985-py2.py3-none-any.whl |
|---|---|
| Size | 6.9 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
e0296e850cc0ccc982e9a46b3f91da3e3c5c0544dc90e249108d74ef2cdd7145
|
|
BLAKE2b-256 checksum How to use checksums |
2cd75660766e13708cdf4cf807ab01c3b60e2f34ded34430426658f1e608101d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |