@@ -66,34 +66,41 @@ def setter(server, port, user, password, time_to_idle):
66
66
client .closeSession ()
67
67
68
68
69
- def login ():
69
+ def get_token ():
70
70
"""
71
- Returns an omero.client object from the current user token. The
72
- session the token refers to has had a join attempt made upon it. If
73
- the token file does not exist a FileNotFoundError will be raised.
71
+ Returns the current user token
72
+ Raises FileNotFoundError if the token file does not exist
74
73
"""
75
- token_path = assert_and_get_token_path ()
76
- with open (token_path , 'r' ) as token_file :
77
- token = token_file .read ().strip ()
78
- omero_session_key = token [:token .find ('@' )]
79
- host , port = token [token .find ('@' ) + 1 :].split (':' )
80
- client = omero .client (host , int (port ))
81
- try :
82
- session = client .joinSession (omero_session_key )
83
- session .detachOnDestroy ()
84
- except Exception :
85
- pass
86
- return client
74
+ with open (assert_and_get_token_path (), 'r' ) as token_path :
75
+ return token_path .read ().strip ()
76
+
77
+
78
+ def login (token ):
79
+ """
80
+ Returns an omero.client object from a valid token. The
81
+ session the token refers to has had a join attempt made upon it.
82
+ """
83
+ omero_session_key = token [:token .find ('@' )]
84
+ host , port = token [token .find ('@' ) + 1 :].split (':' )
85
+ client = omero .client (host , int (port ))
86
+ try :
87
+ session = client .joinSession (omero_session_key )
88
+ session .detachOnDestroy ()
89
+ except Exception :
90
+ pass
91
+ return client
87
92
88
93
89
94
def getter ():
90
95
try :
91
- client = login ()
96
+ token = get_token ()
97
+ client = login (token )
92
98
try :
93
99
client .getSession ()
94
100
except Exception :
95
101
sys .exit ('ERROR: Token is invalid!' )
96
102
finally :
97
103
client .closeSession ()
104
+ return token
98
105
except FileNotFoundError :
99
106
sys .exit ('ERROR: No token available, `omero_user_token set` required!' )
0 commit comments