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 5480 expiration date schema options #6

Merged
merged 2 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
21 changes: 15 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,16 +205,20 @@ optional arguments:
Zone of the user who creates user (only available in Yoda 1.9 and higher)

The CSV file is expected to include the following labels in its header (the first row):
'category' = category for the group
'subcategory' = subcategory for the group
'groupname' = name of the group (without the "research-" prefix)
'category' = category for the group
'subcategory' = subcategory for the group
'groupname' = name of the group (without the "research-" prefix)

For Yoda versions 1.9 and higher, these labels can optionally be included:
'expiration_date' = expiration date for the group.
'schema_id' = schema id for the group. Can only be set when the group is first created.

The remainder of the columns should have a label that starts with a prefix which
indicates the role of each group member:

'manager:' = user that will be given the role of manager
'member:' = user that will be given the role of member with read/write
'viewer:' = user that will be given the role of viewer with read
'manager:' = user that will be given the role of manager
'member:' = user that will be given the role of member with read/write
'viewer:' = user that will be given the role of viewer with read

Notes:
- Columns may appear in any order
Expand All @@ -224,6 +228,11 @@ optional arguments:
category,subcategory,groupname,manager:manager,member:member1,member:member2
departmentx,teama,groupteama,[email protected],[email protected],[email protected]
departmentx,teamb,groupteamb,[email protected],[email protected],

Example Yoda 1.9 and higher:
category,subcategory,groupname,manager:manager,member:member1,expiration_date,schema_id
departmentx,teama,groupteama,[email protected],[email protected],2025-01-01,default-2
departmentx,teamb,groupteamb,[email protected],[email protected],,
```

### yreport\_collectionsize
Expand Down
258 changes: 136 additions & 122 deletions yclienttools/common_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from yclienttools import common_queries
from yclienttools.exceptions import SizeNotSupportedException


class RuleInterface:

def __init__(self, session, yoda_version):
Expand All @@ -22,12 +23,12 @@ def __init__(self, session, yoda_version):
"""
self.session = session
self.set_re = False if yoda_version == "1.7" else True
self.uuGroupAdd_version = "1.7" if yoda_version in ["1.7", "1.8"] else "1.9"
self.uuGroupAdd_version = "1.7" if yoda_version in [
"1.7", "1.8"] else "1.9"
self.default_rule_engine = 'irods_rule_engine_plugin-irods_rule_language-instance'


def call_rule(self, rulename, params, number_outputs,
rule_engine = None):
rule_engine=None):
"""Run a rule

:param rulename: name of the rule
Expand All @@ -40,23 +41,25 @@ def call_rule(self, rulename, params, number_outputs,
for input_var in params.keys():
body += "*{},".format(input_var)

outparams = list(map(lambda n : '*outparam{}'.format(str(n+1)), range(number_outputs)))
outparams = list(
map(lambda n: '*outparam{}'.format(str(n + 1)), range(number_outputs)))
body += '{}); writeLine("stdout","{}")}}'.format(
",".join(outparams),
"\n".join(outparams))

input_params = { "*{}".format(k) : '"{}"'.format(v) for (k,v) in params.items() }
input_params = {"*{}".format(k): '"{}"'.format(v)
for (k, v) in params.items()}
output_params = 'ruleExecOut'

if self.set_re:
re_config = { 'instance_name': self.default_rule_engine if rule_engine is None
else rule_engine }
re_config = {'instance_name': self.default_rule_engine if rule_engine is None
else rule_engine}
else:
re_config = {}

myrule = Rule(
self.session,
rule_file = StringIO(body),
rule_file=StringIO(body),
params=input_params,
output=output_params,
**re_config)
Expand All @@ -67,145 +70,156 @@ def call_rule(self, rulename, params, number_outputs,

return buf[:number_outputs]


def _string_list_to_list(self, s):
if s.startswith("[") and s.endswith("]"):
return s[1:-1].split(",")
else:
raise ValueError("Unable to convert string representation of list to list")

raise ValueError(
"Unable to convert string representation of list to list")

def call_uuGroupGetMembers(self, groupname):
"""Returns list of group members"""
parms = OrderedDict([
( 'groupname', groupname)] )
[out] = self.call_rule('uuGroupGetMembers', parms, 1)
if len(out) >= 1023 and not out.endswith("]"):
raise SizeNotSupportedException("Group member list exceeds 1023 bytes")
return self._string_list_to_list(out)

"""Returns list of group members"""
parms = OrderedDict([
('groupname', groupname)])
[out] = self.call_rule('uuGroupGetMembers', parms, 1)
if len(out) >= 1023 and not out.endswith("]"):
raise SizeNotSupportedException(
"Group member list exceeds 1023 bytes")
return self._string_list_to_list(out)

def call_uuGroupUserRemove(self, groupname, user):
"""Removes a user from a group"""
parms = OrderedDict([
( 'groupname', groupname),
( 'user', user) ])
return self.call_rule('uuGroupUserRemove', parms, 2)

"""Removes a user from a group"""
parms = OrderedDict([
('groupname', groupname),
('user', user)])
return self.call_rule('uuGroupUserRemove', parms, 2)

def call_uuGroupGetMemberType(self, groupname, user):
""":returns: member type of a group member"""
parms = OrderedDict([
( 'groupname', groupname),
( 'user', user) ])
return self.call_rule('uuGroupGetMemberType', parms, 1)[0]

def call_uuGroupUserAddByOtherCreator(self, groupname, username, creator_user, creator_zone):
"""Adds user to group on the behalf of a creator user.

:param: groupname
:param: username
:param: creator_user
:param: creator_zone
:returns: (status, message) ; status !=0 is error
"""
parms = OrderedDict([
('groupname', groupname),
('username', username),
('creatorUser', creator_user),
('creatorZone', creator_zone)])
return self.call_rule('uuGroupUserAdd', parms, 2)
""":returns: member type of a group member"""
parms = OrderedDict([
('groupname', groupname),
('user', user)])
return self.call_rule('uuGroupGetMemberType', parms, 1)[0]

def call_uuGroupUserAddByOtherCreator(
self, groupname, username, creator_user, creator_zone):
"""Adds user to group on the behalf of a creator user.

:param: groupname
:param: username
:param: creator_user
:param: creator_zone
:returns: (status, message) ; status !=0 is error
"""
parms = OrderedDict([
('groupname', groupname),
('username', username),
('creatorUser', creator_user),
('creatorZone', creator_zone)])
return self.call_rule('uuGroupUserAdd', parms, 2)

def call_uuGroupUserAdd(self, groupname, username):
"""Adds user to group.

:param: groupname
:param: username
:returns: (status, message) ; status !=0 is error
"""
parms = OrderedDict([
('groupname', groupname),
('username', username)])
return self.call_rule('uuGroupUserAdd', parms, 2)
"""Adds user to group.

:param: groupname
:param: username
:returns: (status, message) ; status !=0 is error
"""
parms = OrderedDict([
('groupname', groupname),
('username', username)])
return self.call_rule('uuGroupUserAdd', parms, 2)

def call_uuGroupUserChangeRole(self, groupname, username, newrole):
"""Change role of user in group

:param groupname: name of group
:param username: name of user
:param newrole: new role (can be "manager", "reader", "normal")
:returns: (status, message) ; status != 0 is error
"""
parms = OrderedDict([
('groupname', groupname),
('username', username),
('newrole', newrole)])
return self.call_rule('uuGroupUserChangeRole', parms, 2)
"""Change role of user in group

:param groupname: name of group
:param username: name of user
:param newrole: new role (can be "manager", "reader", "normal")
:returns: (status, message) ; status != 0 is error
"""
parms = OrderedDict([
('groupname', groupname),
('username', username),
('newrole', newrole)])
return self.call_rule('uuGroupUserChangeRole', parms, 2)

def call_uuGroupExists(self, groupname):
"""Check whether group name exists on Yoda

:param groupname: name of group
:returns: false/true
"""
parms = OrderedDict([('groupname', groupname)])
[out] = self.call_rule('uuGroupExists', parms, 1)
return out == 'true'
"""Check whether group name exists on Yoda

:param groupname: name of group
:returns: false/true
"""
parms = OrderedDict([('groupname', groupname)])
[out] = self.call_rule('uuGroupExists', parms, 1)
return out == 'true'

def call_uuUserExists(self, username):
"""Check whether user name exists on Yoda

:param username: name of user
:returns: false/true
"""
parms = OrderedDict([('username', username)])
[out] = self.call_rule('uuUserExists', parms, 1)
return out == 'true'
"""Check whether user name exists on Yoda

:param username: name of user
:returns: false/true
"""
parms = OrderedDict([('username', username)])
[out] = self.call_rule('uuUserExists', parms, 1)
return out == 'true'

def call_uuGroupAdd(self, groupname, category,
subcategory, description, classification):
"""Adds a group

:param groupname: name of group
:param category: category / community
:param subcategory: subcategory
:param description: description
:param classification: security classification

:returns: (status, message). Status not 0 means error,
-1089000 means group name already exists
"""
if self.uuGroupAdd_version == "1.7":
parms = OrderedDict([
('groupname', groupname),
('category', category),
('subcategory', subcategory),
('description', description),
('classification', classification)])
elif self.uuGroupAdd_version == "1.9":
parms = OrderedDict([
('groupname', groupname),
('category', category),
('subcategory', subcategory),
('schema_id', 'default-2'),
('expiration_date', ''),
('description', description),
('dataClassification', classification),
('co_identifier', '')
])

return self.call_rule('uuGroupAdd', parms, 2)
subcategory, description, classification, schema_id='default-2', expiration_date=''):
"""Adds a group

:param groupname: name of group
:param category: category / community
:param subcategory: subcategory
:param description: description
:param classification: security classification
:param schema_id: schema id
:param expiration_date: expiration date

:returns: (status, message). Status not 0 means error,
-1089000 means group name already exists
"""
if self.uuGroupAdd_version == "1.7":
parms = OrderedDict([
('groupname', groupname),
('category', category),
('subcategory', subcategory),
('description', description),
('classification', classification)])
elif self.uuGroupAdd_version == "1.9":
parms = OrderedDict([
('groupname', groupname),
('category', category),
('subcategory', subcategory),
('schema_id', schema_id if schema_id not in ("", ".") else "default-2"),
('expiration_date', expiration_date),
('description', description),
('dataClassification', classification),
('co_identifier', '')
])

return self.call_rule('uuGroupAdd', parms, 2)

def call_uuGroupModify(self, groupname, property, value):
"""Modifies one property of a group

:param groupname: name of group
:param property: property to change
:param value: value to change the property to

:returns: (status, message). Status not 0 means error.
"""
parms = OrderedDict([('groupname', groupname),
('property', property),
('value', value)])
return self.call_rule('uuGroupModify', parms, 2)

def call_uuGroupRemove(self, groupname):
"""Removes an empty group
"""Removes an empty group

:param groupname: name of group
:param groupname: name of group

:returns: (status, message). Status not 0 means error.
"""
parms = OrderedDict([('groupname', groupname)])
return self.call_rule('uuGroupRemove', parms, 2)
:returns: (status, message). Status not 0 means error.
"""
parms = OrderedDict([('groupname', groupname)])
return self.call_rule('uuGroupRemove', parms, 2)
Loading