Skip to main content

A connection helper.

Project description

Conexao

A connection helper. Current features:

  • Management of multiple remote MongoDB connection profiles.
  • Faster permanent remote Docker connections.
  • SSH port forward proxies.

Django (ORM)

Add a JSON file to ~/.config/conexao/config.json.

Example:

{
  "profiles": {
    "myapp": {
      "django": {"settings": "myapp.settings"},
      "ssh": {
        "host": "my-vps.example.com",
        "forwards": ["localhost:5432:localhost:5432"]
      }
    }
  }
}

The Django project must be installed in the used Python environment. Maybe doing pip install -e . , from the Django project's folder.

Then use:

from conexao.django import configure
configure('myapp')  # Must come before model import!
from myapp.models import MyModel

MyModel.objects.all()

or:

from conexao.django.auto import myapp  # Must come before model import!
from myapp.models import MyModel

MyModel.objects.all()

MongoDB

Add a JSON file to ~/.config/conexao/config.json.

Example:

{
  "profiles": {
    "simpleMongo": {
      "mongo": {
        "host": "simple-mongo.example.com"
      },
    },
    "mongoInsideDockerVPS": {
      "mongo": {
        "host": "127.0.0.1"
      },
      "ssh": {
        "host": "my-vps.example.com",
        "forwards": ["127.0.0.1:27017:123.docker.container.ip.456:27017"]
      }
    }
  }
}

Then use:

from conexao.mongodb import create_client

client1 = create_client('simpleMongo')
client2 = create_client('mongoInsideDockerVPS')

or:

from conexao.mongodb.auto import simpleMongo as client1, mongoInsideDockerVPS as client2

Docker

Opens a permanent SSH forward for faster remote Docker command execution. Based on: https://forums.docker.com/t/setting-docker-host-to-ssh-results-in-slow-workflow-can-ssh-connection-be-reused/98754

conexao docker <host>

This feature doesn't use the config.json file.

Limitations

This program uses a Python Shelve to store SSH PIDs of all running forwards. Shelve isn't concurrent safe, so avoid calling this program multiple times in parallel. Once the program returns it should be safe to call it again to add more connections.

Development

Install locally using symlinks:

pip install -e .

Build:

python -m build

Publish (need auth):

twine upload dist/*

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

conexao-0.0.10.tar.gz (18.0 kB view hashes)

Uploaded Source

Built Distribution

conexao-0.0.10-py3-none-any.whl (19.1 kB view hashes)

Uploaded Python 3

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