Skip to main content

Connect to databases via ssh tunnel

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tunneler-0.1.1490677240.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

tunneler-0.1.1490677240-py2.py3-none-any.whl (6.9 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file tunneler-0.1.1490677240.tar.gz.

File metadata

File hashes

Hashes for tunneler-0.1.1490677240.tar.gz
Algorithm Hash digest
SHA256 d957e79286b738f3142a9346f803114d758df47b83a08df0fab20880a7795ffc
MD5 aab54daaaf2bd923419a499bab56b64a
BLAKE2b-256 5610b80dedd6c5ce8d46bb069e0770b5b4e6e31bd5ab324f33c9d7fe1098443b

See more details on using hashes here.

File details

Details for the file tunneler-0.1.1490677240-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for tunneler-0.1.1490677240-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 f4580ea3a85973c5ce54d800c9260d98605ccbe5fd546e587a665a07110e7919
MD5 2f3324421baac6c450b3c14c043fc30b
BLAKE2b-256 60236c5289571bc42b5dcca5813a873f3648dfb07e0745db1de8933876aaed1c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page