"git@sissource.ethz.ch:sispub/openbis.git" did not exist on "be17730810dbf097dba2d4fd77d7ac008322dda8"
Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#! /usr/bin/env python
# Copyright © 2019 Uwe Schitt <uwe.schmitt@id.ethz.ch>
import pexpect
import sys
import time
import pdb
from pexpect.exceptions import TIMEOUT
credentials = [line.split() for line in open("credentials.txt")]
EULER = "euler.ethz.ch"
def open_conn(cmd):
print(cmd)
conn = pexpect.spawn(cmd, echo=True, encoding="utf-8")
conn.logfile = sys.stdout
return conn
def auth_pw(conn, password):
conn.expect("password:")
conn.sendline(password)
def accept_license_agreements(user, password):
ssh_conn = open_conn(f"ssh {user}@{EULER}")
auth_pw(ssh_conn, password)
try:
ssh_conn.expect("to exit: ", timeout=1)
ssh_conn.sendline("Yes")
time.sleep(.5)
except TIMEOUT:
pass
ssh_conn.close()
def create_ssh_folders(user, password):
ssh_conn = open_conn(f"ssh {user}@{EULER} 'mkdir -p .ssh; ls -al .ssh'")
auth_pw(ssh_conn, password)
ssh_conn.expect(pexpect.EOF)
ssh_conn.close()
def deploy_ssh_keys(user, password):
ssh_conn = open_conn(f"scp id_rsa.pub {user}@{EULER}:.ssh/authorized_keys")
auth_pw(ssh_conn, password)
ssh_conn.expect(pexpect.EOF)
ssh_conn.close()
def check_passwordless_login(user):
ssh_conn = open_conn(f"ssh -i id_rsa {user}@{EULER}")
try:
ssh_conn.expect("password: ", timeout=1)
except TIMEOUT:
return True
else:
return False
finally:
ssh_conn.close()
flags = []
for user, password in credentials:
accept_license_agreements(user, password)
create_ssh_folders(user, password)
deploy_ssh_keys(user, password)
ok = check_passwordless_login(user)
flags.append(ok)
assert all(flags)