Skip to content

Commit 228bf86

Browse files
committed
[_505,sq] atomic ACLs endpoint
1 parent 7a81184 commit 228bf86

3 files changed

Lines changed: 70 additions & 2 deletions

File tree

irods/access.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def __eq__(self, other):
102102
def __hash__(self):
103103
return hash((self.access_name, iRODSPath(self.path), self.user_name, self.user_zone))
104104

105-
def copy(self, decanonicalize=False):
105+
def copy(self, decanonicalize=False, ref_zone=''):
106106
other = copy.deepcopy(self)
107107
if decanonicalize:
108108
replacement_string = {
@@ -112,6 +112,9 @@ def copy(self, decanonicalize=False):
112112
"modify_object": "write",
113113
}.get(self.access_name)
114114
other.access_name = replacement_string if replacement_string is not None else self.access_name
115+
if '' != ref_zone == other.user_zone:
116+
other.user_zone = ''
117+
115118
return other
116119

117120
def __repr__(self):

irods/manager/access_manager.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from irods.manager import Manager
44
from irods.api_number import api_number
5-
from irods.message import ModAclRequest, iRODSMessage
5+
from irods.message import ModAclRequest, iRODSMessage, JSON_Message
66
from irods.data_object import iRODSDataObject, irods_dirname, irods_basename
77
from irods.collection import iRODSCollection
88
from irods.models import (
@@ -14,6 +14,7 @@
1414
CollectionAccess,
1515
)
1616
from irods.access import iRODSAccess
17+
import irods.exception as ex
1718
from irods.column import In
1819
from irods.user import iRODSUser
1920

@@ -36,6 +37,33 @@ def users_by_ids(session, ids=()):
3637

3738

3839
class AccessManager(Manager):
40+
41+
def _ACL_operation(self, op_input: iRODSAccess):
42+
return {
43+
"acl": op_input.access_name,
44+
"entity_name": op_input.user_name,
45+
**(
46+
{} if not (z := op_input.user_zone)
47+
else {"zone": z}
48+
)
49+
}
50+
51+
def _call_atomic_acl_api(self, logical_path : str, *operations, admin=False):
52+
request_text = {"logical_path": logical_path}
53+
request_text["admin_mode"] = admin
54+
request_text["operations"] = [self._ACL_operation(op) for op in operations]
55+
56+
with self.sess.pool.get_connection() as conn:
57+
request_msg = iRODSMessage(
58+
"RODS_API_REQ",
59+
JSON_Message(request_text, conn.server_version),
60+
int_info=20005,
61+
)
62+
conn.send(request_msg)
63+
response = conn.recv()
64+
response_msg = response.get_json_encoded_struct()
65+
logger.debug("in atomic ACL api, server responded with: %r", response_msg)
66+
3967
def get(self, target, report_raw_acls=True, **kw):
4068

4169
if report_raw_acls:

irods/test/access_test.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,43 @@ def test_iRODSAccess_cannot_be_constructed_using_unsupported_type__issue_558(sel
497497
self.sess,
498498
)
499499

500+
def test_atomic_acls_505(self):
501+
#import pdb;pdb.set_trace()
502+
ses = self.sess
503+
zone = user1 = user2 = group = None
504+
try:
505+
zone = ses.zones.create("twilight","remote")
506+
user1 = ses.users.create("test_user_505", "rodsuser")
507+
user2 = ses.users.create("rod_serling_505#twilight", "rodsuser")
508+
group = ses.groups.create("test_group_505")
509+
ses.acls._call_atomic_acl_api(
510+
self.coll_path,
511+
a1:=iRODSAccess("write", "", user1.name, user1.zone),
512+
a2:=iRODSAccess("read", "", user2.name, user2.zone),
513+
a3:=iRODSAccess("read", "", group.name),
514+
)
515+
516+
accesses = ses.acls.get(self.coll)
517+
518+
# For purposes of equality tests, assign the path name of interest into each ACL.
519+
for p in (a1, a2, a3):
520+
p.path = self.coll_path
521+
522+
# Assert that the ACLs we added are among those listed for the object in the catalog.
523+
normalize = lambda access: access.copy(decanonicalize=True, ref_zone=ses.zone)
524+
self.assertLess(
525+
set(normalize(_) for _ in (a1,a2,a3)),
526+
set(normalize(_) for _ in accesses)
527+
)
528+
finally:
529+
if user1:
530+
user1.remove()
531+
if user2:
532+
user2.remove()
533+
if group:
534+
group.remove()
535+
if zone:
536+
zone.remove()
500537

501538
if __name__ == "__main__":
502539
# let the tests find the parent irods lib

0 commit comments

Comments
 (0)