Skip to content

Commit 7f8b62e

Browse files
committed
[_81] add test and handling of PEP for atomic acl
1 parent 5d5375b commit 7f8b62e

5 files changed

+100
-2
lines changed

indexing.cmake

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ install(
6666
FILES
6767
${CMAKE_SOURCE_DIR}/packaging/test_plugin_indexing.py
6868
${CMAKE_SOURCE_DIR}/packaging/atomic_metadata_ops.py
69+
${CMAKE_SOURCE_DIR}/packaging/atomic_acl_ops.py
6970
DESTINATION ${IRODS_HOME_DIRECTORY}/scripts/irods/test
7071
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
7172
COMPONENT ${IRODS_PACKAGE_COMPONENT_POLICY_NAME}

libirods_rule_engine_plugin-indexing.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,21 @@ namespace {
518518
idx.schedule_metadata_purge_for_recursive_rm_object(obj_inp->collName, recurseInfo);
519519
}
520520
}
521+
else if("pep_api_atomic_apply_acl_operations_post" == _rn) {
522+
auto it = _args.begin();
523+
std::advance(it, 2);
524+
auto request = boost::any_cast<BytesBuf*>(*it);
525+
std::string requ_str {(const char*)request->buf,unsigned(request->len)};
526+
const auto requ_json = nlohmann::json::parse( requ_str );
527+
const auto obj_path = requ_json["logical_path"].get<std::string>();
528+
irods::indexing::indexer idx{_rei, config->instance_name_};
529+
idx.schedule_metadata_indexing_event(
530+
obj_path,
531+
_rei->rsComm->clientUser.userName,
532+
"attribute",
533+
"value",
534+
"units");
535+
}
521536
else if (_rn == "pep_api_atomic_apply_metadata_operations_pre"
522537
|| _rn == "pep_api_atomic_apply_metadata_operations_post")
523538
{
@@ -1022,6 +1037,7 @@ irods::error rule_exists(
10221037
"pep_api_data_obj_unlink_post",
10231038
"pep_api_mod_avu_metadata_pre",
10241039
"pep_api_mod_avu_metadata_post",
1040+
"pep_api_atomic_apply_acl_operations_post",
10251041
"pep_api_data_obj_close_post",
10261042
"pep_api_data_obj_put_post",
10271043
"pep_api_phy_path_reg_post",

packaging/atomic_acl_ops.py

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/usr/bin/env python3
2+
3+
from __future__ import print_function
4+
import sys
5+
import json
6+
import getopt
7+
from os.path import (join, abspath)
8+
9+
opt,args = getopt.getopt(sys.argv[1:],'v:')
10+
optD = dict(opt)
11+
activate_path = optD.get('-v')
12+
if activate_path is not None:
13+
if '/bin/activate' not in activate_path:
14+
activate_path = join(activate_path, 'bin/activate_this.py')
15+
activate_path = abspath( activate_path )
16+
exec(open(activate_path).read(), {'__file__': activate_path})
17+
18+
from irods.message import iRODSMessage, JSON_Message
19+
from irods.test.helpers import (home_collection, make_session)
20+
21+
def call_json_api(sess, request_text, api_number):
22+
with sess.pool.get_connection() as conn:
23+
request_msg = iRODSMessage("RODS_API_REQ", JSON_Message( request_text, conn.server_version ), int_info=api_number)
24+
conn.send( request_msg )
25+
response = conn.recv()
26+
response_msg = response.get_json_encoded_struct()
27+
if response_msg:
28+
print("in atomic apply ACL api, server responded with: %r"%response_msg, file = sys.stderr)
29+
30+
31+
def usage(program = sys.argv[0], stream = sys.stderr):
32+
print('{program} logical_path [user1 access1] [user2 access2] ... '.format(**locals()), file = stream)
33+
exit(1)
34+
35+
if __name__ == '__main__':
36+
37+
try:
38+
logical_path = args.pop(0)
39+
except IndexError:
40+
usage()
41+
42+
request = {"logical_path": logical_path,
43+
"operations": [ ]
44+
}
45+
46+
with make_session() as ses:
47+
while len(args) > 0:
48+
try:
49+
username,access = args[:2]
50+
except ValueError:
51+
usage()
52+
del args[:2]
53+
request["operations"].append({"entity_name": username,
54+
"acl": access })
55+
call_json_api(ses, request, api_number = 20005) # ATOMIC_APPLY_ACL_OPERATIONS_APN
56+

packaging/atomic_metadata_ops.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22

33
from __future__ import print_function
44
import re

packaging/test_plugin_indexing.py

+26-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
import zipfile
1313
import subprocess
14-
from time import sleep
14+
from time import sleep, time
1515
from textwrap import dedent
1616
from datetime import datetime as _datetime
1717

@@ -932,6 +932,31 @@ def logical_filesystem_for_indexing(self,objects,session):
932932
for p in collections_to_delete:
933933
session.assert_icommand(['irm', '-rf', p],'STDOUT','')
934934

935+
def test_indexing_with_atomic_acl_ops__81(self):
936+
with indexing_plugin__installed(indexing_config = {'minimum_delay_time':'1', 'maximum_delay_time':'9'}):
937+
test_coll = self.test_coll_name()
938+
INDEX = DEFAULT_METADATA_INDEX + "__81_{:%s.%f}".format(_datetime.now())
939+
create_metadata_index (INDEX)
940+
try:
941+
with session.make_session_for_existing_admin() as admin_session:
942+
admin_session.assert_icommand("imkdir {0}".format(test_coll))
943+
admin_session.assert_icommand("itouch {0}/testobj".format(test_coll))
944+
admin_session.assert_icommand("imeta set -C {0} irods::indexing::index {1}::metadata elasticsearch".format(test_coll, INDEX))
945+
sleep(5)
946+
# hit the apply_atomic_acl api
947+
self.assertIsNotNone (repeat_until (operator.eq, True) (self.delay_queue_is_empty) (admin_session))
948+
admin_session.assert_icommand("""cd ${{HOME}} ; python3 ~/scripts/irods/test/atomic_acl_ops.py -v {self.venv_dir} """
949+
""" '/{0.zone_name}/home/{0.username}'/{test_coll}/testobj {self.user0.username} write """
950+
""" {self.user1.username} read """.format(admin_session, **locals()), use_unsafe_shell=True)
951+
# Check new permissions are reflected in the index
952+
self.assertIsNotNone( repeat_until(operator.eq, 1, transform=number_of_hits,
953+
) (search_index_for_userPermissions_user_name) (INDEX, self.user0.username))
954+
self.assertEqual(1, number_of_hits(search_index_for_userPermissions_user_name (INDEX, self.user1.username)))
955+
finally:
956+
delete_metadata_index (INDEX)
957+
with session.make_session_for_existing_admin() as admin_session:
958+
admin_session.assert_icommand("irm -fr {0}".format(test_coll))
959+
935960
def test_indexing_with_atomic_metadata_ops_66(self):
936961
with indexing_plugin__installed():
937962
test_coll = 'testcoll_66'

0 commit comments

Comments
 (0)