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

YDA-5953 uuUserExists with rule_user_exists #15

Merged
merged 5 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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'] = ""
stsnel marked this conversation as resolved.
Show resolved Hide resolved

# 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