Skip to content

Commit

Permalink
move client hints call to ruleinterface to reduce repeated api calls
Browse files Browse the repository at this point in the history
  • Loading branch information
FuHsinyu committed Oct 7, 2024
1 parent d96a2c7 commit e64ec95
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions yclienttools/common_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'] = ""
Expand Down

0 comments on commit e64ec95

Please sign in to comment.