MagicStack / asyncpg

A fast PostgreSQL Database Client Library for Python/asyncio.
Apache License 2.0
6.73k stars 392 forks source link

connect through socks5 proxy #1136

Open nagylzs opened 3 months ago

nagylzs commented 3 months ago

I would like to use asyncpg through a socks 5 proxy. I need this because the postgresql instances are running inside a docker overlay network (swarm). The IP addresses of the servers are not fixed, and it is not possible to access them directly.

If I had a single postgres server, then it would not be a problem to manually create a tunnel. But I need to connect to several different servers, and their ip addresses are changing. Manually creating a bunch of host aliases and creating multiple tunnels is just not practical.

Would it be possible to add a layer that would allow me to add my own callback for creating the TCP socket for a given host name + port pair?

eltoder commented 3 months ago

If you only want a callback functionality and going to implement the proxy handling code yourself, as opposed to having asyngpg natively support socks5, this is similar to https://github.com/MagicStack/asyncpg/issues/1054

nagylzs commented 3 months ago

I think that would be wonderful, and the cleanest solution. I think we can close this ticket in favour of #1054.