|
| 1 | +from __future__ import absolute_import |
| 2 | + |
| 3 | +import json |
| 4 | +import os |
| 5 | +from ._constants import RULE_CONFIG_FILE, RULE_GROUPS_CONFIG_FILE, COLLECTION_CONFIG_FILE |
| 6 | + |
| 7 | + |
| 8 | +def _get_rule_config(rule_name): |
| 9 | + rule_config = None |
| 10 | + print(rule_name) |
| 11 | + config_file_path = os.path.dirname(os.path.abspath(__file__)) + "/" + RULE_CONFIG_FILE |
| 12 | + print(config_file_path) |
| 13 | + |
| 14 | + if os.path.exists(config_file_path): |
| 15 | + with open(config_file_path) as json_data: |
| 16 | + configs = json.load(json_data) |
| 17 | + if rule_name in configs: |
| 18 | + rule_config = configs[rule_name] |
| 19 | + return rule_config |
| 20 | + |
| 21 | + |
| 22 | +def _get_rule_list(framework, type): |
| 23 | + rules_list = [] |
| 24 | + |
| 25 | + config_file_path = os.path.dirname(os.path.abspath(__file__)) + "/" + RULE_GROUPS_CONFIG_FILE |
| 26 | + |
| 27 | + if os.path.exists(config_file_path): |
| 28 | + with open(config_file_path) as json_data: |
| 29 | + configs = json.load(json_data) |
| 30 | + if framework in configs: |
| 31 | + if type in configs[framework]: |
| 32 | + rules_list = configs[framework][type] |
| 33 | + return rules_list |
| 34 | + |
| 35 | + |
| 36 | +def _get_config_for_group(rules): |
| 37 | + rules_config = [] |
| 38 | + |
| 39 | + config_file_path = os.path.dirname(os.path.abspath(__file__)) + "/" + RULE_CONFIG_FILE |
| 40 | + |
| 41 | + if os.path.exists(config_file_path): |
| 42 | + with open(config_file_path) as json_data: |
| 43 | + configs = json.load(json_data) |
| 44 | + for rule_name in rules: |
| 45 | + if rule_name in configs: |
| 46 | + rules_config.append(configs[rule_name]) |
| 47 | + return rules_config |
| 48 | + |
| 49 | + |
| 50 | +def _get_collection_config(collection_name): |
| 51 | + coll_config = None |
| 52 | + |
| 53 | + config_file_path = os.path.dirname(os.path.abspath(__file__)) + "/" + COLLECTION_CONFIG_FILE |
| 54 | + |
| 55 | + if os.path.exists(config_file_path): |
| 56 | + with open(config_file_path) as json_data: |
| 57 | + configs = json.load(json_data) |
| 58 | + if collection_name in configs: |
| 59 | + coll_config = configs[collection_name] |
| 60 | + return coll_config |
0 commit comments