how to do ssh port forwarding and connect database in Rust language

245 views Asked by At

I'm trying to set up SSH port forwarding with a Rust app I'm writing, I need it because all database access needs to use the VM as jumphost (*security reasons).

The basic idea is that this rust app will open port forwarding and then i can connect database (postgre, mysql) and do the some logic in the app from my local server.

before i did it in python and its very easy to implement.

    with SSHTunnelForwarder((ssh_open['ssh_srv_name'], 22),
                    ssh_username=ssh_open['ssh_username'],
                    ssh_pkey=ssh_open['ssh_pkey'],
                    local_bind_address=('127.0.0.1', 3304),
                    remote_bind_address=(ssh_open['ssh_remote_bind_address'], int(ssh_open['ssh_remoteport']))) as server:
    if config['dbms'] == 'mysql':
        res_df = get_data_mysql(db,config['connstr'],qry)
    else:
        res_df = get_data_postgre(db,config['connstr'],qry_postgre)
    server.stop()

but in Rust language I haven't found an example this easy. is there a Rust library/example that can do the same thing in python?

0

There are 0 answers