From 5ec0744e6e586d9348bc1282dc52a481316dfc73 Mon Sep 17 00:00:00 2001 From: "Staiger, Christine" Date: Wed, 28 Aug 2024 11:24:30 +0200 Subject: [PATCH 1/2] Catch eror when resource is not set. --- ibridgesgui/login.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/ibridgesgui/login.py b/ibridgesgui/login.py index fb47e44c..9d9dbca5 100644 --- a/ibridgesgui/login.py +++ b/ibridgesgui/login.py @@ -83,10 +83,13 @@ def _check_home(self, session): return True def _check_resource(self, session): - resc = Resources(session).get_resource(session.default_resc) - if resc.parent is not None: + try: + resc = Resources(session).get_resource(session.default_resc) + if resc.parent is not None: + return False + return True + except Exception: return False - return True def login_function(self): """Connect to iRODS server with gathered info.""" @@ -116,14 +119,19 @@ def login_function(self): self.close() elif not self._check_home(session): self.error_label.setText(f'"irods_home": "{session.home}" does not exist.') + return elif not self._check_resource(session): self.error_label.setText( f'"irods_default_resource": "{session.default_resc}" not writeable.' ) + return except LoginError: self.error_label.setText("irods_environment.json not setup correctly.") self.logger.error("irods_environment.json not setup correctly.") + except ValueError as err: + self.error_label.setText(repr(err)) + self.logger.error(repr(err)) except PasswordError: self.error_label.setText("Wrong password!") self.logger.error("Wrong password provided.") From 83ceabb28b7fef4cd5cabdfe5374123e8a50d549 Mon Sep 17 00:00:00 2001 From: "Staiger, Christine" Date: Wed, 28 Aug 2024 11:52:19 +0200 Subject: [PATCH 2/2] check in login function if all params in environment are resent --- ibridgesgui/config.py | 81 +++++++++++++++++++++++-------------------- ibridgesgui/login.py | 10 ++++-- 2 files changed, 50 insertions(+), 41 deletions(-) diff --git a/ibridgesgui/config.py b/ibridgesgui/config.py index 48eb8056..d429053a 100644 --- a/ibridgesgui/config.py +++ b/ibridgesgui/config.py @@ -177,7 +177,7 @@ def is_session_from_config(session: Session) -> Union[Session, None]: return False -def check_irods_config(ienv: Union[Path, dict]) -> str: +def check_irods_config(ienv: Union[Path, dict], include_network = True) -> str: """Check whether an iRODS configuration file is correct. Parameters @@ -185,6 +185,10 @@ def check_irods_config(ienv: Union[Path, dict]) -> str: ienv : Path or dict Path to the irods_environment.json or the dictionary conatining the json. + include_network : bool + If true connect to server and check more parameters. Otherwise only + existence of parameters in the environment.json will be checked. + Returns ------- str : @@ -213,43 +217,44 @@ def check_irods_config(ienv: Union[Path, dict]) -> str: return 'Please set an "irods_default_resource".' if not isinstance(env["irods_port"], int): return '"irods_port" needs to be an integer, remove quotes.' - if not Session.network_check(env["irods_host"], env["irods_port"]): - return f'No connection: Network might be down or\n \ - server name {env["irods_host"]} is incorrect or\n \ - port {env["irods_port"]} is incorrect.' - # check authentication scheme - try: - sess = iRODSSession(password="bogus", **env) - _ = sess.server_version - except TypeError as err: - return repr(err) - except NetworkException as err: - return repr(err) - except AttributeError as err: - return repr(err) - except PamLoginException as err: - # irods4.3+ specific - return f'Adjust "irods_authentication_scheme" {err.args}' - except ModuleNotFoundError as err: - # irods4.3+ uses string in authenticationscheme as class - return f'"irods_authentication_scheme": "{err.name}" does not exist' - - except PlainTextPAMPasswordError: - return ( - 'Value of "irods_client_server_negotiation" needs to be' - + ' "request_server_negotiation".' - ) - - except CAT_INVALID_AUTHENTICATION: - return 'Wrong "irods_authentication_scheme".' - except ValueError as err: - if "scheme" in err.args[0]: - return 'Value of "irods_authentication_scheme" not recognised.' - return f"{err.args}" - - # password incorrect but rest is fine - except (CAT_INVALID_USER, PAM_AUTH_PASSWORD_FAILED): - return "All checks passed successfully." + if include_network: + if not Session.network_check(env["irods_host"], env["irods_port"]): + return f'No connection: Network might be down or\n \ + server name {env["irods_host"]} is incorrect or\n \ + port {env["irods_port"]} is incorrect.' + # check authentication scheme + try: + sess = iRODSSession(password="bogus", **env) + _ = sess.server_version + except TypeError as err: + return repr(err) + except NetworkException as err: + return repr(err) + except AttributeError as err: + return repr(err) + except PamLoginException as err: + # irods4.3+ specific + return f'Adjust "irods_authentication_scheme" {err.args}' + except ModuleNotFoundError as err: + # irods4.3+ uses string in authenticationscheme as class + return f'"irods_authentication_scheme": "{err.name}" does not exist' + + except PlainTextPAMPasswordError: + return ( + 'Value of "irods_client_server_negotiation" needs to be' + + ' "request_server_negotiation".' + ) + + except CAT_INVALID_AUTHENTICATION: + return 'Wrong "irods_authentication_scheme".' + except ValueError as err: + if "scheme" in err.args[0]: + return 'Value of "irods_authentication_scheme" not recognised.' + return f"{err.args}" + + # password incorrect but rest is fine + except (CAT_INVALID_USER, PAM_AUTH_PASSWORD_FAILED): + return "All checks passed successfully." # all tests passed return "All checks passed successfully." diff --git a/ibridgesgui/login.py b/ibridgesgui/login.py index 9d9dbca5..68b2903e 100644 --- a/ibridgesgui/login.py +++ b/ibridgesgui/login.py @@ -13,6 +13,7 @@ from ibridgesgui.config import ( IRODSA, + check_irods_config, get_last_ienv_path, get_prev_settings, save_current_settings, @@ -95,6 +96,12 @@ def login_function(self): """Connect to iRODS server with gathered info.""" self.error_label.clear() env_file = self.irods_config_dir.joinpath(self.envbox.currentText()) + + msg = check_irods_config(env_file, include_network = False) + if not msg == "All checks passed successfully.": + self.error_label.setText("Go to menu Configure. "+msg) + return + try: if self.cached_pw is True and self.password_field.text() == "***********": self.logger.debug("Login with %s and cached password.", env_file) @@ -129,9 +136,6 @@ def login_function(self): except LoginError: self.error_label.setText("irods_environment.json not setup correctly.") self.logger.error("irods_environment.json not setup correctly.") - except ValueError as err: - self.error_label.setText(repr(err)) - self.logger.error(repr(err)) except PasswordError: self.error_label.setText("Wrong password!") self.logger.error("Wrong password provided.")