Used dpath module instead of custom code to traverse object.

This commit is contained in:
VakarisZ 2021-01-29 13:01:22 +02:00
parent ba9e8c22b4
commit c45ff1dc1f
3 changed files with 3 additions and 20 deletions

View File

@ -1,10 +1,5 @@
# abstract, static method decorator
# noinspection PyPep8Naming
import operator
from functools import reduce
from typing import List, Union, Any
class abstractstatic(staticmethod):
__slots__ = ()
@ -13,7 +8,3 @@ class abstractstatic(staticmethod):
function.__isabstractmethod__ = True
__isabstractmethod__ = True
def get_dict_value_by_path(data: dict, path: List[str]) -> Any:
return reduce(operator.getitem, path, data)

View File

@ -1,9 +0,0 @@
import unittest
from common.utils.code_utils import get_dict_value_by_path
class TestCodeUtils(unittest.TestCase):
def test_get_dict_value_by_path(self):
dict_for_test = {'a': {'b': {'c': 'result'}}}
self.assertEqual(get_dict_value_by_path(dict_for_test, ['a', 'b', 'c']), 'result')

View File

@ -1,4 +1,5 @@
from common.utils.code_utils import get_dict_value_by_path
import dpath.util
from common.utils.exceptions import RulePathCreatorNotFound
from monkey_island.cc.services.zero_trust.scoutsuite.data_parsing.rule_path_building.rule_path_creators_list import \
RULE_PATH_CREATORS_LIST
@ -9,7 +10,7 @@ class RuleParser:
@staticmethod
def get_rule_data(scoutsuite_data, rule_name):
rule_path = RuleParser.get_rule_path(rule_name)
return get_dict_value_by_path(data=scoutsuite_data, path=rule_path)
return dpath.util.get(scoutsuite_data, rule_path)
@staticmethod
def get_rule_path(rule_name):