-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Session ID and constructor #400
Changes from 13 commits
9ae6018
dbf00ab
72d735c
ee24282
f30d62a
65f9d94
150803b
489c78b
dd97de9
704e50f
e2025ed
88d2453
a91f391
4dc40d6
e989c33
2474872
01fc825
64bf1f9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -1525,14 +1525,33 @@ def __init__(self, username=None, passwd=None, client_obj=None, group=None, | |||
self.ice_config = [os.path.abspath(str(x)) for x in [_f for _f in self.ice_config if _f]] | ||||
|
||||
self.host = host | ||||
if self.c is not None: | ||||
hc = self.c.getProperty("omero.host") | ||||
if self.host is None: | ||||
self.host = hc | ||||
elif hc != self.host: | ||||
raise Exception("hosts %s and %s do not match" % (hc, self.host)) | ||||
self.port = port | ||||
if self.c is not None: | ||||
pc = self.c.getProperty("omero.port") | ||||
if self.port is None: | ||||
self.port = pc | ||||
elif pc != self.port: | ||||
raise Exception("ports %s and %s do not match" % (pc, self.port)) | ||||
self.secure = secure | ||||
if self.c is not None: | ||||
self.secure = self.c.isSecure() | ||||
self.useragent = useragent | ||||
self.userip = userip | ||||
|
||||
self._sessionUuid = None | ||||
self._session_cb = None | ||||
self._session = None | ||||
if self.c is not None: | ||||
try: | ||||
self._sessionUuid = self.c.getSessionId() | ||||
except omero.ClientError: # no session available | ||||
pass | ||||
self._lastGroupId = None | ||||
self._anonymous = anonymous | ||||
self._defaultOmeroGroup = None | ||||
|
@@ -1936,6 +1955,7 @@ def close(self, hard=True): # pragma: no cover | |||
oldC = None | ||||
self.c = None | ||||
self._session = None | ||||
#self._sessionUuid = None | ||||
sbesson marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
|
||||
self._proxies = NoProxies() | ||||
logger.info("closed connection (uuid=%s)" % str(self._sessionUuid)) | ||||
|
@@ -2029,7 +2049,7 @@ def isSecure(self): | |||
Returns 'True' if the underlying omero.clients.BaseClient is connected | ||||
using SSL | ||||
""" | ||||
return hasattr(self.c, 'isSecure') and self.c.isSecure() or False | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't that modifying the contract of the API before a connection happens e.g. in a scenario like the following
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This raises another question in that case There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The initial connection will (and should) always use an encrypted client. But omero-py/src/omero/gateway/__init__.py Line 2074 in 4dc40d6
_createSession might create an unencrypted client depending on the state of secure :
>>> conn=BlitzGateway(username=user,passwd=password,host="localhost")
>>> conn.connect()
True
>>> conn.isSecure()
False
>>> conn.close()
>>> conn=BlitzGateway(username=user,passwd=password,host="localhost",secure=True)
>>> conn.connect()
True
>>> conn.isSecure()
True There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i get that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So the scenario we are discussing is
Interestingly, part of the changes proposed here are to throw an exception on the following use cases
My feeling would be to say |
||||
return self.secure | ||||
|
||||
def _getSessionId(self): | ||||
return self.c.getSessionId() | ||||
|
@@ -2082,8 +2102,11 @@ def _resetOmeroClient(self): | |||
logger.debug(self.ice_config) | ||||
|
||||
if self.c is not None: | ||||
self.c.__del__() | ||||
self.c = None | ||||
try: | ||||
self.c.__del__() | ||||
self.c = None | ||||
except omero.ClientError: # no session available | ||||
pass | ||||
|
||||
if self.host is not None: | ||||
if self.port is not None: | ||||
|
@@ -2125,6 +2148,16 @@ def connect(self, sUuid=None): | |||
logger.debug("Ooops. no self._c") | ||||
return False | ||||
try: | ||||
if self.c is not None: | ||||
jburel marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
try: | ||||
sid = self.c.getSessionId() | ||||
# we have a session already from the client | ||||
if sUuid is None or sid == sUuid: | ||||
logger.debug('connected via client') | ||||
return True | ||||
except omero.ClientError: # no session available | ||||
pass | ||||
|
||||
if self._sessionUuid is None and sUuid: | ||||
self._sessionUuid = sUuid | ||||
if self._sessionUuid is not None: | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not overly important, but should there be a mismatch test here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had a similar question while performing code review but this was marked as resolved. Was this addressed somewhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tested added there https://github.com/ome/openmicroscopy/pull/6381/files
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My interpretation of @joshmoore's question was: what should happen if a gateway object is constructed with an initialized client object and
secure={True,False}
and the encryption state of the client as returned byself.c.isSecure()
does not match thesecure
keyword?