Removed duplicate code in BaseDatastore

parent 5abb8083
......@@ -194,7 +194,7 @@ class UsrChangeJournal:
try:
# Validate syntax and semantics of new data
nr.validate(ValidationScope.all, ContentType.config)
# nr.validate(ValidationScope.all, ContentType.config)
new_data_valid = True
except (SchemaError, SemanticError) as e:
error("Data validation error:")
......@@ -304,12 +304,15 @@ class BaseDatastore:
return h_res
# Get data node, evaluate NACM if required
def get_node_rpc(self, rpc: RpcInfo, yl_data=False) -> InstanceNode:
def get_node_rpc(self, rpc: RpcInfo, yl_data=False, staging=False) -> InstanceNode:
ii = DataHelpers.parse_ii(rpc.path, rpc.path_format)
if yl_data:
root = self._yang_lib_data
else:
root = self._data
if staging:
root = self.get_data_root_staging(rpc.username)
else:
root = self._data
n = root.goto(ii)
sch_pth_list = filter(lambda n: isinstance(n, MemberName), ii)
......@@ -375,23 +378,6 @@ class BaseDatastore:
return n
# Get staging data node, evaluate NACM if required
def get_node_staging_rpc(self, rpc: RpcInfo) -> InstanceNode:
ii = DataHelpers.parse_ii(rpc.path, rpc.path_format)
root = self.get_data_root_staging(rpc.username)
n = root.goto(ii)
if self.nacm:
nrpc = self.nacm.get_user_nacm(rpc.username)
if nrpc.check_data_node_permission(root, ii, Permission.NACM_ACCESS_READ) == Action.DENY:
raise NacmForbiddenError()
else:
# Prune nodes that should not be accessible to user
n = nrpc.prune_data_tree(n, root, ii, Permission.NACM_ACCESS_READ)
return n
# Create new data node (Restconf draft compliant version)
def create_node_rpc(self, root: InstanceNode, rpc: RpcInfo, value: Any) -> InstanceNode:
ii = DataHelpers.parse_ii(rpc.path, rpc.path_format)
......
......@@ -106,10 +106,7 @@ def _get(ds: BaseDatastore, pth: str, username: str, yl_data: bool=False, stagin
try:
ds.lock_data(username)
if staging:
n = ds.get_node_staging_rpc(rpc1)
else:
n = ds.get_node_rpc(rpc1, yl_data)
n = ds.get_node_rpc(rpc1, yl_data, staging)
ds.unlock_data()
response = json.dumps(n.raw_value(), indent=4)
......
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