Skip to content

Commit

Permalink
replace uuUserExists with rule_user_exists
Browse files Browse the repository at this point in the history
  • Loading branch information
FuHsinyu committed Oct 2, 2024
1 parent 39a4f97 commit d96a2c7
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
18 changes: 16 additions & 2 deletions yclienttools/common_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion yclienttools/ensuremembers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion yclienttools/importgroups.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
2 changes: 1 addition & 1 deletion yclienttools/rmusers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit d96a2c7

Please sign in to comment.