Skip to content
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

256 sync bug #259

Merged
merged 2 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 43 additions & 38 deletions ibridgesgui/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,18 @@ 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
----------
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 :
Expand Down Expand Up @@ -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."

Expand Down
18 changes: 15 additions & 3 deletions ibridgesgui/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

from ibridgesgui.config import (
IRODSA,
check_irods_config,
get_last_ienv_path,
get_prev_settings,
save_current_settings,
Expand Down Expand Up @@ -83,15 +84,24 @@ 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."""
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)
Expand All @@ -116,10 +126,12 @@ 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.")
Expand Down
Loading