forked from irods/python-irodsclient
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient_init.py
More file actions
33 lines (29 loc) · 1.09 KB
/
client_init.py
File metadata and controls
33 lines (29 loc) · 1.09 KB
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
import irods.client_configuration as cfg
import irods.password_obfuscation as obf
import irods.helpers as h
import getpass
import sys
def write_credentials_with_native_password( password ):
s = h.make_session()
assert(not s.auth_file)
open(s.pool.account.derived_auth_file,'w').write(obf.encode(password))
return True
def write_credentials_with_pam_password( password ):
s = h.make_session()
assert(not s.auth_file)
s.pool.account.password = password
with cfg.loadlines( [dict(setting='legacy_auth.pam.password_for_auto_renew',value='')] ):
to_encode = s.pam_pw_negotiated
if to_encode:
open(s.pool.account.derived_auth_file,'w').write(obf.encode(to_encode[0]))
return True
return False
if __name__ == '__main__':
vector = {
'pam': write_credentials_with_pam_password,
'native': write_credentials_with_native_password,
}
if sys.argv[1] in vector:
vector[sys.argv[1]](getpass.getpass(prompt=f'{sys.argv[1]} password: '))
else:
print('did not recognize authentication scheme argument',file = sys.stderr)