Skip to content

Instantly share code, notes, and snippets.

@atoonk
Last active December 5, 2020 01:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atoonk/e96359501fcfceba007561c59f1d5ee0 to your computer and use it in GitHub Desktop.
Save atoonk/e96359501fcfceba007561c59f1d5ee0 to your computer and use it in GitHub Desktop.
mysocket example code
from mysocketctl.socket import get_sockets, new_socket
from mysocketctl.tunnel import new_tunnel
from mysocketctl.login import get_token
from mysocketctl.ssh import SystemSSH, Paramiko
import jwt
username="xxx@gmail.com"
password="xxx"
token = get_token(username,password)
print(token)
global authorization_header
authorization_header = {
"x-access-token": token['token'],
"accept": "application/json",
"Content-Type": "application/json",
}
s = new_socket(authorization_header, "mysocket from python", False , '', '', 'http')
print(s)
sockets = get_sockets(authorization_header)
for s in sockets:
print(s['name'])
"""
Some more examples:
#Create Tunnel
tunnel = new_tunnel(authorization_header, socket['socket_id'])
def get_user_id_from_token():
data = jwt.decode(authorization_header['x-access-token'], verify=False)
if "user_id" in data:
return data["user_id"]
else:
return False
ssh_user = get_user_id_from_token().replace('-','')
ssh_server = "ssh.mysocket.io"
#client = SystemSSH()
client = Paramiko()
client.connect(port, tunnel["local_port"], ssh_server, ssh_user)
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment