def _export_subject_object_action_assignments(self, type_element, json_content): export_method_data = getattr(PolicyManager, 'get_' + type_element + '_assignments') policies = PolicyManager.get_policies(self._user_id) element_assignments_array = [] for policy_key in policies: assignments = export_method_data(self._user_id, policy_key) # logger.info(assignments) for assignment_key in assignments: assignment_dict = dict() JsonUtils.convert_id_to_name( assignments[assignment_key][type_element + "_id"], assignment_dict, type_element, type_element, PolicyManager, self._user_id, policy_key) JsonUtils.convert_id_to_name( assignments[assignment_key]["category_id"], assignment_dict, "category", type_element + "_category", ModelManager, self._user_id, policy_key) JsonUtils.convert_ids_to_names( assignments[assignment_key]["assignments"], assignment_dict, "assignments", type_element + "_data", PolicyManager, self._user_id, policy_key) element_assignments_array.append(assignment_dict) logger.info("Exporting {} assignment {}".format( type_element, assignment_dict)) if len(element_assignments_array) > 0: json_content[type_element + '_assignments'] = element_assignments_array
def _export_rules(self, json_content): policies = PolicyManager.get_policies(self._user_id) rules_array = [] for policy_key in policies: rules = PolicyManager.get_rules(self._user_id, policy_key) rules = rules["rules"] # logger.info(rules) for rule in rules: rule_dict = dict() JsonUtils.copy_field_if_exists(rule, rule_dict, "instructions", dict) JsonUtils.copy_field_if_exists(rule, rule_dict, "enabled", True) JsonUtils.convert_id_to_name(rule["meta_rule_id"], rule_dict, "meta_rule", "meta_rule", ModelManager, self._user_id) JsonUtils.convert_id_to_name(policy_key, rule_dict, "policy", "policy", PolicyManager, self._user_id) ids = rule["rule"] rule_description = dict() meta_rule = ModelManager.get_meta_rules( self._user_id, rule["meta_rule_id"]) meta_rule = [v for v in meta_rule.values()] meta_rule = meta_rule[0] index_subject_data = len(meta_rule["subject_categories"]) - 1 index_object_data = len(meta_rule["subject_categories"]) + len( meta_rule["object_categories"]) - 1 index_action_data = len(meta_rule["subject_categories"]) + len( meta_rule["object_categories"]) + len( meta_rule["action_categories"]) - 1 ids_subject_data = [ids[0]] if len( meta_rule["subject_categories"] ) == 1 else ids[0:index_subject_data] ids_object_data = [ids[index_object_data]] if len( meta_rule["object_categories"] ) == 1 else ids[index_subject_data + 1:index_object_data] ids_action_date = [ids[index_action_data]] if len( meta_rule["action_categories"] ) == 1 else ids[index_object_data + 1:index_action_data] JsonUtils.convert_ids_to_names(ids_subject_data, rule_description, "subject_data", "subject_data", PolicyManager, self._user_id, policy_key) JsonUtils.convert_ids_to_names(ids_object_data, rule_description, "object_data", "object_data", PolicyManager, self._user_id, policy_key) JsonUtils.convert_ids_to_names(ids_action_date, rule_description, "action_data", "action_data", PolicyManager, self._user_id, policy_key) rule_dict["rule"] = rule_description rules_array.append(rule_dict) if len(rules_array) > 0: json_content['rules'] = rules_array
def _export_policies(self, json_content): policies = PolicyManager.get_policies(self._user_id) policies_array = [] for policy_key in policies: policy = dict() JsonUtils.copy_field_if_exists(policies[policy_key], policy, "name", str) JsonUtils.copy_field_if_exists(policies[policy_key], policy, "genre", str) JsonUtils.copy_field_if_exists(policies[policy_key], policy, "description", str) JsonUtils.convert_id_to_name(policies[policy_key]["model_id"], policy, "model", "model", ModelManager, self._user_id) logger.info("Exporting policy {}".format(policy)) policies_array.append(policy) if len(policies_array) > 0: json_content["policies"] = policies_array
def _export_subject_object_action_datas(self, type_element, json_content): export_method_data = getattr(PolicyManager, 'get_' + type_element + '_data') policies = PolicyManager.get_policies(self._user_id) element_datas_array = [] for policy_key in policies: datas = export_method_data(self._user_id, policy_key) # logger.info("data found : {}".format(datas)) for data_group in datas: policy_id = data_group["policy_id"] category_id = data_group["category_id"] # logger.info(data_group["data"]) for data_key in data_group["data"]: data_dict = dict() if type_element == 'subject': JsonUtils.copy_field_if_exists( data_group["data"][data_key], data_dict, "name", str) JsonUtils.copy_field_if_exists( data_group["data"][data_key], data_dict, "description", str) else: JsonUtils.copy_field_if_exists( data_group["data"][data_key], data_dict, "name", str) JsonUtils.copy_field_if_exists( data_group["data"][data_key], data_dict, "description", str) JsonUtils.convert_id_to_name(policy_id, data_dict, "policy", "policy", PolicyManager, self._user_id) JsonUtils.convert_id_to_name(category_id, data_dict, "category", type_element + "_category", ModelManager, self._user_id, policy_key) logger.info("Exporting {} data {}".format( type_element, data_dict)) element_datas_array.append(data_dict) if len(element_datas_array) > 0: json_content[type_element + '_data'] = element_datas_array