34 lines
1.1 KiB
Python
34 lines
1.1 KiB
Python
#!/usr/bin/env python3
|
|
"""Look up which user account to attach the swarm-program token to."""
|
|
import os, sys, paramiko
|
|
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect("20.24.50.121", 22, "heicode", os.environ["MGR_PASS"],
|
|
look_for_keys=False, allow_agent=False, timeout=30)
|
|
|
|
sql = '''
|
|
SELECT id, username, email, "group", role, status
|
|
FROM users
|
|
WHERE email IN ('zsbgnw@gmail.com', 'chenchen@xinghanlab.com')
|
|
OR username = 'chenchen'
|
|
OR role >= 10
|
|
ORDER BY id
|
|
LIMIT 10;
|
|
'''
|
|
# Wrap via psql exec inside the heicode container.
|
|
cmd = (
|
|
'sudo docker exec heicode sh -c '
|
|
+ '"PGPASSWORD=\\"Myadmin@123456.\\" psql '
|
|
+ '-h heicode.postgres.database.azure.com -U heicode heicode '
|
|
+ "-c \\\"" + sql.replace("\n", " ").replace('"', '\\"\\"') + "\\\"\""
|
|
)
|
|
_, o, e = c.exec_command(cmd, timeout=60, get_pty=True)
|
|
for line in iter(o.readline, ""):
|
|
if not line: break
|
|
sys.stdout.write(line.encode("ascii","replace").decode("ascii"))
|
|
sys.stdout.flush()
|
|
err = e.read().decode("ascii","replace")
|
|
if err.strip():
|
|
sys.stderr.write(err)
|