From 9ae601872ade567759405b6f02b48e4cde9415f7 Mon Sep 17 00:00:00 2001 From: Jean-Marie Burel Date: Fri, 1 Mar 2024 21:32:20 +0000 Subject: [PATCH 01/18] set host and port from client if available --- src/omero/gateway/__init__.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/omero/gateway/__init__.py b/src/omero/gateway/__init__.py index 2a4f1fdfb..3b6850f28 100644 --- a/src/omero/gateway/__init__.py +++ b/src/omero/gateway/__init__.py @@ -1525,7 +1525,11 @@ 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: + self.host = self.c.getProperty("omero.host") self.port = port + if self.c is not None: + self.port = self.c.getProperty("omero.port") self.secure = secure self.useragent = useragent self.userip = userip From dbf00ab782ffa5386151a8d4b47d5a4da9c02eb0 Mon Sep 17 00:00:00 2001 From: Jean-Marie Burel Date: Fri, 1 Mar 2024 21:40:27 +0000 Subject: [PATCH 02/18] set session from client --- src/omero/gateway/__init__.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/omero/gateway/__init__.py b/src/omero/gateway/__init__.py index 3b6850f28..da42cb4b2 100644 --- a/src/omero/gateway/__init__.py +++ b/src/omero/gateway/__init__.py @@ -1537,6 +1537,12 @@ def __init__(self, username=None, passwd=None, client_obj=None, group=None, self._sessionUuid = None self._session_cb = None self._session = None + if self.c is not None: + try: + self._sessionUuid = self.c.getSessionId() + self._session = self.c.getSession() + except omero.ClientError: # no session available + pass self._lastGroupId = None self._anonymous = anonymous self._defaultOmeroGroup = None From 72d735c306e854539f8bee5eda903f9634426d41 Mon Sep 17 00:00:00 2001 From: Jean-Marie Burel Date: Fri, 1 Mar 2024 21:46:28 +0000 Subject: [PATCH 03/18] do not close session associated to client --- src/omero/gateway/__init__.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/omero/gateway/__init__.py b/src/omero/gateway/__init__.py index da42cb4b2..a955c2214 100644 --- a/src/omero/gateway/__init__.py +++ b/src/omero/gateway/__init__.py @@ -2092,8 +2092,14 @@ def _resetOmeroClient(self): logger.debug(self.ice_config) if self.c is not None: - self.c.__del__() - self.c = None + try: + if self.c.getSessionId() != self._sessionUuid: + self.c.__del__() + self.c = None + except omero.ClientError: # no session available + self.c.__del__() + self.c = None + pass if self.host is not None: if self.port is not None: From ee24282c986886f7d1860ecd269b28b811f32160 Mon Sep 17 00:00:00 2001 From: Jean-Marie Burel Date: Fri, 1 Mar 2024 22:05:53 +0000 Subject: [PATCH 04/18] remove uncessary check --- src/omero/gateway/__init__.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/omero/gateway/__init__.py b/src/omero/gateway/__init__.py index a955c2214..7eb1c46ba 100644 --- a/src/omero/gateway/__init__.py +++ b/src/omero/gateway/__init__.py @@ -2097,8 +2097,6 @@ def _resetOmeroClient(self): self.c.__del__() self.c = None except omero.ClientError: # no session available - self.c.__del__() - self.c = None pass if self.host is not None: From f30d62a482eb623bd6e1dfa3c9a7284d98bf0719 Mon Sep 17 00:00:00 2001 From: Jean-Marie Burel Date: Mon, 4 Mar 2024 22:27:29 +0000 Subject: [PATCH 05/18] raise exception if hosts and ports do not match --- src/omero/gateway/__init__.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/omero/gateway/__init__.py b/src/omero/gateway/__init__.py index 7eb1c46ba..e736f9574 100644 --- a/src/omero/gateway/__init__.py +++ b/src/omero/gateway/__init__.py @@ -1526,10 +1526,18 @@ def __init__(self, username=None, passwd=None, client_obj=None, group=None, self.host = host if self.c is not None: - self.host = self.c.getProperty("omero.host") + hc = self.c.getProperty("omero.host") + if self.host is None: + self.host = hc + else if hc != self.host + raise Exception("hosts %s and %s do not match" % (hc, self.host)) self.port = port if self.c is not None: - self.port = self.c.getProperty("omero.port") + pc = self.c.getProperty("omero.port") + if self.port is None: + self.port = pc + else if pc != self.port + raise Exception("ports %s and %s do not match" % (pc, self.port)) self.secure = secure self.useragent = useragent self.userip = userip From 65f9d9474f312234d2eb60cf59cadbf0ff2bf3ed Mon Sep 17 00:00:00 2001 From: Jean-Marie Burel Date: Mon, 4 Mar 2024 22:32:52 +0000 Subject: [PATCH 06/18] fix syntax --- src/omero/gateway/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/omero/gateway/__init__.py b/src/omero/gateway/__init__.py index e736f9574..e75ce0d6c 100644 --- a/src/omero/gateway/__init__.py +++ b/src/omero/gateway/__init__.py @@ -1529,14 +1529,14 @@ def __init__(self, username=None, passwd=None, client_obj=None, group=None, hc = self.c.getProperty("omero.host") if self.host is None: self.host = hc - else if hc != self.host + 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 - else if pc != self.port + elif pc != self.port: raise Exception("ports %s and %s do not match" % (pc, self.port)) self.secure = secure self.useragent = useragent From 150803b653259f67b84404ba8e1033e84f745931 Mon Sep 17 00:00:00 2001 From: Jean-Marie Burel Date: Mon, 4 Mar 2024 23:17:10 +0000 Subject: [PATCH 07/18] set the parameters explicitly --- src/omero/gateway/scripts/dbhelpers.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/omero/gateway/scripts/dbhelpers.py b/src/omero/gateway/scripts/dbhelpers.py index b00f4bd92..b6baedd64 100644 --- a/src/omero/gateway/scripts/dbhelpers.py +++ b/src/omero/gateway/scripts/dbhelpers.py @@ -96,7 +96,8 @@ def login(self, groupname=None): if groupname is None: groupname = self.groupname client = omero.gateway.BlitzGateway( - self.name, self.passwd, group=groupname, try_super=self.admin) + username=self.name, passwd=self.passwd, + group=groupname, try_super=self.admin) if not client.connect(): print("Can not connect") return None From 489c78bc9a6ab2577169a4e31670706bd0cc82e1 Mon Sep 17 00:00:00 2001 From: Jean-Marie Burel Date: Wed, 6 Mar 2024 03:36:35 +0000 Subject: [PATCH 08/18] set secure flag from client --- src/omero/gateway/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/omero/gateway/__init__.py b/src/omero/gateway/__init__.py index e75ce0d6c..9cf24482c 100644 --- a/src/omero/gateway/__init__.py +++ b/src/omero/gateway/__init__.py @@ -1539,6 +1539,8 @@ def __init__(self, username=None, passwd=None, client_obj=None, group=None, 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 From dd97de97f8928f62f11f3151e69e7398d26551c4 Mon Sep 17 00:00:00 2001 From: Jean-Marie Burel Date: Wed, 6 Mar 2024 03:37:32 +0000 Subject: [PATCH 09/18] return correct flag using isSecure --- src/omero/gateway/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/omero/gateway/__init__.py b/src/omero/gateway/__init__.py index 9cf24482c..d9996f460 100644 --- a/src/omero/gateway/__init__.py +++ b/src/omero/gateway/__init__.py @@ -2049,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 + return hasattr(self.c, 'isSecure') and self.c.isSecure() or self.secure def _getSessionId(self): return self.c.getSessionId() From 704e50f6d170439a1b6976b64bb641b248ec0add Mon Sep 17 00:00:00 2001 From: Jean-Marie Burel Date: Mon, 25 Mar 2024 09:28:50 +0000 Subject: [PATCH 10/18] set session ID only --- src/omero/gateway/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/omero/gateway/__init__.py b/src/omero/gateway/__init__.py index d9996f460..528017eb5 100644 --- a/src/omero/gateway/__init__.py +++ b/src/omero/gateway/__init__.py @@ -1550,7 +1550,6 @@ def __init__(self, username=None, passwd=None, client_obj=None, group=None, if self.c is not None: try: self._sessionUuid = self.c.getSessionId() - self._session = self.c.getSession() except omero.ClientError: # no session available pass self._lastGroupId = None From e2025ed309c877f42855cdf76373a46e525a8fb0 Mon Sep 17 00:00:00 2001 From: Jean-Marie Burel Date: Wed, 27 Mar 2024 15:21:40 +0000 Subject: [PATCH 11/18] reset sessionUuid --- src/omero/gateway/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/omero/gateway/__init__.py b/src/omero/gateway/__init__.py index 528017eb5..19d4f147f 100644 --- a/src/omero/gateway/__init__.py +++ b/src/omero/gateway/__init__.py @@ -1955,6 +1955,7 @@ def close(self, hard=True): # pragma: no cover oldC = None self.c = None self._session = None + self._sessionUuid = None self._proxies = NoProxies() logger.info("closed connection (uuid=%s)" % str(self._sessionUuid)) From 88d245341881d1cee71877378ace80251beec0dd Mon Sep 17 00:00:00 2001 From: Jean-Marie Burel Date: Tue, 2 Apr 2024 10:16:38 +0100 Subject: [PATCH 12/18] return secure flag --- src/omero/gateway/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/omero/gateway/__init__.py b/src/omero/gateway/__init__.py index 19d4f147f..6a8146228 100644 --- a/src/omero/gateway/__init__.py +++ b/src/omero/gateway/__init__.py @@ -1955,7 +1955,7 @@ def close(self, hard=True): # pragma: no cover oldC = None self.c = None self._session = None - self._sessionUuid = None + #self._sessionUuid = None self._proxies = NoProxies() logger.info("closed connection (uuid=%s)" % str(self._sessionUuid)) @@ -2049,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 self.secure + return self.secure def _getSessionId(self): return self.c.getSessionId() From a91f391ec2f957ab5c44839cd9395f7db8b73a8b Mon Sep 17 00:00:00 2001 From: Jean-Marie Burel Date: Tue, 2 Apr 2024 16:02:25 +0100 Subject: [PATCH 13/18] check if it is the same session --- src/omero/gateway/__init__.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/omero/gateway/__init__.py b/src/omero/gateway/__init__.py index 6a8146228..31a03b5e7 100644 --- a/src/omero/gateway/__init__.py +++ b/src/omero/gateway/__init__.py @@ -2103,9 +2103,8 @@ def _resetOmeroClient(self): if self.c is not None: try: - if self.c.getSessionId() != self._sessionUuid: - self.c.__del__() - self.c = None + self.c.__del__() + self.c = None except omero.ClientError: # no session available pass @@ -2149,6 +2148,16 @@ def connect(self, sUuid=None): logger.debug("Ooops. no self._c") return False try: + if self.c is not None: + 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: From 4dc40d68a9e511c4dc81f718c514aeea15029a6e Mon Sep 17 00:00:00 2001 From: Jean-Marie Burel Date: Mon, 8 Apr 2024 16:01:54 +0100 Subject: [PATCH 14/18] remove comment --- src/omero/gateway/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/omero/gateway/__init__.py b/src/omero/gateway/__init__.py index 31a03b5e7..176800d55 100644 --- a/src/omero/gateway/__init__.py +++ b/src/omero/gateway/__init__.py @@ -1955,7 +1955,7 @@ def close(self, hard=True): # pragma: no cover oldC = None self.c = None self._session = None - #self._sessionUuid = None + self._sessionUuid = None self._proxies = NoProxies() logger.info("closed connection (uuid=%s)" % str(self._sessionUuid)) From e989c33fae6adfb3c2fab2cd74d6ebd9318308ed Mon Sep 17 00:00:00 2001 From: Jean-Marie Burel Date: Thu, 11 Apr 2024 11:52:37 +0100 Subject: [PATCH 15/18] remove conditional --- src/omero/gateway/__init__.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/omero/gateway/__init__.py b/src/omero/gateway/__init__.py index 176800d55..ea308f6ba 100644 --- a/src/omero/gateway/__init__.py +++ b/src/omero/gateway/__init__.py @@ -2148,15 +2148,14 @@ def connect(self, sUuid=None): logger.debug("Ooops. no self._c") return False try: - if self.c is not None: - 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 + 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 From 2474872574bce5f99d6eb74a79d7db1616bad685 Mon Sep 17 00:00:00 2001 From: Jean-Marie Burel Date: Thu, 11 Apr 2024 13:41:26 +0100 Subject: [PATCH 16/18] review how secure flag is set --- src/omero/gateway/__init__.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/omero/gateway/__init__.py b/src/omero/gateway/__init__.py index ea308f6ba..a8c139b9f 100644 --- a/src/omero/gateway/__init__.py +++ b/src/omero/gateway/__init__.py @@ -1539,8 +1539,6 @@ def __init__(self, username=None, passwd=None, client_obj=None, group=None, 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 @@ -2049,7 +2047,7 @@ def isSecure(self): Returns 'True' if the underlying omero.clients.BaseClient is connected using SSL """ - return self.secure + return hasattr(self.c, 'isSecure') and self.c.isSecure() or self.secure def _getSessionId(self): return self.c.getSessionId() From 01fc825c6baf57635275d1e619e7a9d63bf0a467 Mon Sep 17 00:00:00 2001 From: Jean-Marie Burel Date: Thu, 11 Apr 2024 14:15:28 +0100 Subject: [PATCH 17/18] revert to original implementation --- src/omero/gateway/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/omero/gateway/__init__.py b/src/omero/gateway/__init__.py index a8c139b9f..1ccbb7c99 100644 --- a/src/omero/gateway/__init__.py +++ b/src/omero/gateway/__init__.py @@ -2047,7 +2047,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 self.secure + return hasattr(self.c, 'isSecure') and self.c.isSecure() or False def _getSessionId(self): return self.c.getSessionId() From 64bf1f9dfd9553a639094f9a6b232218e92d690b Mon Sep 17 00:00:00 2001 From: Jean-Marie Burel Date: Thu, 11 Apr 2024 17:37:14 +0100 Subject: [PATCH 18/18] check compatibility of secure flag --- src/omero/gateway/__init__.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/omero/gateway/__init__.py b/src/omero/gateway/__init__.py index 1ccbb7c99..4583303ca 100644 --- a/src/omero/gateway/__init__.py +++ b/src/omero/gateway/__init__.py @@ -1477,7 +1477,7 @@ class _BlitzGateway (object): def __init__(self, username=None, passwd=None, client_obj=None, group=None, clone=False, try_super=False, host=None, port=None, - extra_config=None, secure=False, anonymous=True, + extra_config=None, secure=None, anonymous=True, useragent=None, userip=None): """ Create the connection wrapper. @@ -1538,6 +1538,18 @@ def __init__(self, username=None, passwd=None, client_obj=None, group=None, self.port = pc elif pc != self.port: raise Exception("ports %s and %s do not match" % (pc, self.port)) + if self.c is None: + if secure is None: + secure = False + else: + cs = self.c.isSecure() + if secure is None: + secure = cs + else: + # Check that the values match + if secure != cs: + raise Exception("Secure flag %s and %s do not match" % (secure, cs)) + self.secure = secure self.useragent = useragent self.userip = userip @@ -2047,7 +2059,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 + return self.secure def _getSessionId(self): return self.c.getSessionId()