Implemented support for "depth" query parameter

parent d799261c
......@@ -283,6 +283,35 @@ class BaseDatastore:
# Prun subtree data
n = nrpc.check_data_read_path(self._data, ii)
try:
max_depth = int(rpc.qs["depth"][0])
except KeyError:
max_depth = None
except IndexError:
max_depth = None
except ValueError:
raise ValueError("Invalid value of query param \"depth\"")
if max_depth is not None:
def _tree_limit_depth(node: InstanceNode, depth: int) -> InstanceNode:
if isinstance(node.value, ObjectValue):
if depth > max_depth:
node.value = ObjectValue({})
else:
for child_key in sorted(node.value.keys()):
m = node.member(child_key)
node = _tree_limit_depth(m, depth + 1).up()
elif isinstance(node.value, ArrayValue):
if depth > max_depth:
node.value = ArrayValue([])
else:
for i in range(len(node.value)):
e = node.entry(i)
node = _tree_limit_depth(e, depth + 1).up()
return node
n = _tree_limit_depth(n, 1)
return n
# Get staging data node, evaluate NACM if required
......
......@@ -391,7 +391,7 @@ class UserNacm:
debug("checking eii {}".format(eii))
if self.check_data_node_path(root, eii, Permission.NACM_ACCESS_READ) == Action.DENY:
debug("Pruning node {} {}".format(id(node.value[i]), node.value[i]))
node = node.remove_entry(i)
node = node.delete_entry(i)
arr_len -= 1
else:
i += 1
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment