Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
#!/usr/bin/env python3
import os
import time
import jwt as jwt
from mysocketctl.tunnel import new_tunnel, delete_tunnel
from mysocketctl.login import get_token
from mysocketctl.utils import ssh_tunnel
username = os.getenv("email")
password = os.getenv("password")
socket_id = os.getenv("socket_id")
token = get_token(username, password)
global authorization_header
authorization_header = {
"x-access-token": token["token"],
"accept": "application/json",
"Content-Type": "application/json",
def get_user_id_from_token():
data = jwt.decode(token["token"], verify=False)
if "user_id" in data:
return data["user_id"].replace("-", "")
return False
# Create Tunnel
tunnel = new_tunnel(authorization_header, socket_id)
#few seconds to have it propagate
#fetch username
ssh_user = get_user_id_from_token()
ssh_server = ""
port = 8000 # local port of our app
#set up tunnel
ssh_tunnel(port, tunnel["local_port"], ssh_server, ssh_user)
#delete tunnel when done
delete_tunnel(authorization_header, socket_id, tunnel["tunnel_id"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment