From d96a2c79101a4ab92d4921e536268c12023c2de9 Mon Sep 17 00:00:00 2001 From: FuHsinyu Date: Wed, 2 Oct 2024 08:22:24 +0200 Subject: [PATCH 1/5] replace uuUserExists with rule_user_exists --- yclienttools/common_rules.py | 18 ++++++++++++++++-- yclienttools/ensuremembers.py | 2 +- yclienttools/importgroups.py | 2 +- yclienttools/rmusers.py | 2 +- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/yclienttools/common_rules.py b/yclienttools/common_rules.py index cdfb106..028fcfc 100644 --- a/yclienttools/common_rules.py +++ b/yclienttools/common_rules.py @@ -153,14 +153,28 @@ def call_uuGroupExists(self, groupname: str) -> bool: [out] = self.call_rule('uuGroupExists', parms, 1) return out == 'true' - def call_uuUserExists(self, username: str) -> bool: + def call_rule_user_exists(self, username: str) -> bool: """Check whether user name exists on Yoda :param username: name of user :returns: false/true """ + + # Attempt to retrieve client hints rules + try: + client_hints_rules = self.session.client_hints.get("rules", {}) + except Exception as e: + print("Error: {}. Hint: python-irodsclient needs to be version 2.1 or later to support client_hints.".format(e)) + + # Select python rule if avaliable, otherwise select legacy rule + rule_to_call = 'rule_user_exists' if 'rule_user_exists' in client_hints_rules else 'uuUserExists' parms = OrderedDict([('username', username)]) - [out] = self.call_rule('uuUserExists', parms, 1) + if rule_to_call == 'rule_user_exists': + parms['outparam1'] = "" + + # Call the rule + [out] = self.call_rule(rule_to_call, parms, 1) + return out == 'true' def call_uuGroupAdd(self, groupname: str, category: str, diff --git a/yclienttools/ensuremembers.py b/yclienttools/ensuremembers.py index 15ed0b6..ec09b7a 100644 --- a/yclienttools/ensuremembers.py +++ b/yclienttools/ensuremembers.py @@ -60,7 +60,7 @@ def validate_data(rule_interface, args, userdata, groupdata): for user in userdata: if not is_internal_user(user, args.internal_domains.split(",")): - if not rule_interface.call_uuUserExists(user): + if not rule_interface.call_rule_user_exists(user): errors.append("External user {} does not exist.".format(user)) for group in groupdata: diff --git a/yclienttools/importgroups.py b/yclienttools/importgroups.py index 90e4905..5e61bc0 100644 --- a/yclienttools/importgroups.py +++ b/yclienttools/importgroups.py @@ -213,7 +213,7 @@ def validate_data(rule_interface: RuleInterface, args: argparse.Namespace, data: # ensure that external users already have an iRODS account # we do not want to be the actor that creates them (unless # we are creating them in the name of a creator user) - if not rule_interface.call_uuUserExists(user) and not args.creator_user: + if not rule_interface.call_rule_user_exists(user) and not args.creator_user: errors.append( 'Group {} has nonexisting external user {}'.format(groupname, user)) diff --git a/yclienttools/rmusers.py b/yclienttools/rmusers.py index 19cb011..e3d0dfd 100644 --- a/yclienttools/rmusers.py +++ b/yclienttools/rmusers.py @@ -39,7 +39,7 @@ def validate_data(session, rule_interface, args, userdata): errors = [] for user in userdata: - if not rule_interface.call_uuUserExists(user): + if not rule_interface.call_rule_user_exists(user): errors.append(f"User {user} does not exist.") if home_exists(session, user) and not home_is_empty(session, user): errors.append(f"Home directory of user {user} is not empty") From e64ec95fac727fb88ad1cb80254f99b565adc744 Mon Sep 17 00:00:00 2001 From: FuHsinyu Date: Mon, 7 Oct 2024 17:10:30 +0200 Subject: [PATCH 2/5] move client hints call to ruleinterface to reduce repeated api calls --- yclienttools/common_rules.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/yclienttools/common_rules.py b/yclienttools/common_rules.py index 028fcfc..70b03d4 100644 --- a/yclienttools/common_rules.py +++ b/yclienttools/common_rules.py @@ -26,6 +26,11 @@ def __init__(self, session, yoda_version): "1.7", "1.8"] else "1.9" self.default_rule_engine = 'irods_rule_engine_plugin-irods_rule_language-instance' + try: + self.client_hints_rules = self.session.client_hints.get("rules", {}) + except Exception as e: + print("Error: {}. Hint: python-irodsclient needs to be version 2.1 or later to support client_hints.".format(e)) + def call_rule(self, rulename, params, number_outputs, rule_engine=None) -> List[str]: """Run a rule @@ -159,15 +164,14 @@ def call_rule_user_exists(self, username: str) -> bool: :param username: name of user :returns: false/true """ + # Ensure client_hints_rules initialized + if not hasattr(self, 'client_hints_rules') or not isinstance(self.client_hints_rules, list): + self.client_hints_rules = self.session.client_hints.get("rules", {}) - # Attempt to retrieve client hints rules - try: - client_hints_rules = self.session.client_hints.get("rules", {}) - except Exception as e: - print("Error: {}. Hint: python-irodsclient needs to be version 2.1 or later to support client_hints.".format(e)) + # Determinie which rule to call + rule_to_call = 'rule_user_exists' if 'rule_user_exists' in self.client_hints_rules else 'uuUserExists' - # Select python rule if avaliable, otherwise select legacy rule - rule_to_call = 'rule_user_exists' if 'rule_user_exists' in client_hints_rules else 'uuUserExists' + # Prepare rule parameters parms = OrderedDict([('username', username)]) if rule_to_call == 'rule_user_exists': parms['outparam1'] = "" From 83db5dde71b293a2faff97bec81009a929d31472 Mon Sep 17 00:00:00 2001 From: FuHsinyu Date: Tue, 8 Oct 2024 13:26:46 +0200 Subject: [PATCH 3/5] remove retry code of client hint verification --- yclienttools/common_rules.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/yclienttools/common_rules.py b/yclienttools/common_rules.py index 70b03d4..05887eb 100644 --- a/yclienttools/common_rules.py +++ b/yclienttools/common_rules.py @@ -17,7 +17,7 @@ def __init__(self, session, yoda_version): :param session: IrodsSession object to call :param yoda_version: which Yoda version to assume (e.g. 1.7, 1.8, 1.9) -Whether to specify the rule engine on rule calls + Whether to specify the rule engine on rule calls (enable for Yoda 1.8 and higher, disable for Yoda 1.7) """ self.session = session @@ -164,11 +164,7 @@ def call_rule_user_exists(self, username: str) -> bool: :param username: name of user :returns: false/true """ - # Ensure client_hints_rules initialized - if not hasattr(self, 'client_hints_rules') or not isinstance(self.client_hints_rules, list): - self.client_hints_rules = self.session.client_hints.get("rules", {}) - - # Determinie which rule to call + # Determine which rule to call rule_to_call = 'rule_user_exists' if 'rule_user_exists' in self.client_hints_rules else 'uuUserExists' # Prepare rule parameters From aeec3d0c841f8317f881eafdce2eccb0580061ba Mon Sep 17 00:00:00 2001 From: FuHsinyu Date: Fri, 11 Oct 2024 13:59:46 +0200 Subject: [PATCH 4/5] remove white space --- yclienttools/common_rules.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/yclienttools/common_rules.py b/yclienttools/common_rules.py index 05887eb..5ef1ecc 100644 --- a/yclienttools/common_rules.py +++ b/yclienttools/common_rules.py @@ -16,8 +16,7 @@ def __init__(self, session, yoda_version): :param session: IrodsSession object to call :param yoda_version: which Yoda version to assume (e.g. 1.7, 1.8, 1.9) - - Whether to specify the rule engine on rule calls +Whether to specify the rule engine on rule calls (enable for Yoda 1.8 and higher, disable for Yoda 1.7) """ self.session = session From 9f4f140458a59e2fb8239082644e812889994635 Mon Sep 17 00:00:00 2001 From: FuHsinyu Date: Fri, 11 Oct 2024 14:00:41 +0200 Subject: [PATCH 5/5] format a bit --- yclienttools/common_rules.py | 1 + 1 file changed, 1 insertion(+) diff --git a/yclienttools/common_rules.py b/yclienttools/common_rules.py index 5ef1ecc..5af3341 100644 --- a/yclienttools/common_rules.py +++ b/yclienttools/common_rules.py @@ -16,6 +16,7 @@ def __init__(self, session, yoda_version): :param session: IrodsSession object to call :param yoda_version: which Yoda version to assume (e.g. 1.7, 1.8, 1.9) + Whether to specify the rule engine on rule calls (enable for Yoda 1.8 and higher, disable for Yoda 1.7) """