Skip to content

Commit

Permalink
Merge pull request #264 from chStaiger/develop
Browse files Browse the repository at this point in the history
v1.1.1
  • Loading branch information
chStaiger authored Sep 16, 2024
2 parents 62833f1 + 342270e commit 3caa89a
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 46 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# iBridges <img src="ibridgesgui/icons/logo.png" width="150" align="right">
# iBridges GUI <img src="https://github.com/chStaiger/iBridges-Gui/blob/develop/ibridgesgui/icons/logo.png?raw=true" width="150" align="right">

<p align="center">
<p align="center">
Expand Down
2 changes: 1 addition & 1 deletion ibridgesgui/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ def update_permission(self):
elif acc_name == "":
self.error_label.setText("Please provide an access level from the menu.")
return
recursive = self.recurisive_box.currentText() == "True"
recursive = self.recursive_box.currentText() == "True"
try:
perm = Permissions(self.session, get_irods_item(irods_path))
perm.set(perm=perm_lables_to_acl.get(acc_name, acc_name),
Expand Down
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
6 changes: 4 additions & 2 deletions ibridgesgui/popup_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,8 @@ def _finish_upload(self):

def _upload_status(self, state):
up_size, transferred_size, obj_count, num_objs, obj_failed = state
self.progress_bar.setValue(int(transferred_size*100/up_size))
if up_size > 0:
self.progress_bar.setValue(int(transferred_size*100/up_size))
text = f"{obj_count} of {num_objs} files; failed: {obj_failed}."
self.error_label.setText(text)

Expand Down Expand Up @@ -559,7 +560,8 @@ def _finish_download(self):

def _download_status(self, state):
down_size, transferred_size, obj_count, num_objs, obj_failed = state
self.progress_bar.setValue(int(transferred_size*100/down_size))
if down_size > 0:
self.progress_bar.setValue(int(transferred_size*100/down_size))
text = f"{obj_count} of {num_objs} files; failed: {obj_failed}."
self.error_label.setText(text)

Expand Down
3 changes: 2 additions & 1 deletion ibridgesgui/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,8 @@ def _sync_data_end(self, thread_output: dict):

def _sync_data_status(self, state):
up_size, transferred_size, obj_count, num_objs, obj_failed = state
self.progress_bar.setValue(int(transferred_size*100/up_size))
if up_size > 0:
self.progress_bar.setValue(int(transferred_size*100/up_size))
text = f"{obj_count} of {num_objs} files; failed: {obj_failed}."
self.error_label.setText(text)

Expand Down

0 comments on commit 3caa89a

Please sign in to comment.