Last active
December 5, 2020 01:00
-
-
Save atoonk/e96359501fcfceba007561c59f1d5ee0 to your computer and use it in GitHub Desktop.
mysocket example code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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="[email protected]" | |
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