def handle_rule_versions(self, filename, rule_type, rule): """ For each version of a rule found in the ruleset, append a new Rule object """ if 'versions' in rule: versions = rule.pop('versions') for version_key_suffix in versions: version = versions[version_key_suffix] version['key_suffix'] = version_key_suffix tmp_rule = dict(rule, **version) self.rules[filename].append(Rule(self.rules_data_path, filename, rule_type, tmp_rule)) else: self.rules[filename].append(Rule(self.rules_data_path, filename, rule_type, rule))
def prepare_rules(self, attributes=None, ip_ranges=None, params=None): """ Update the ruleset's rules by duplicating fields as required by the HTML ruleset generator :return: """ attributes = [] if attributes is None else attributes ip_ranges = [] if ip_ranges is None else ip_ranges params = {} if params is None else params for filename in self.rule_definitions: if filename in self.rules: for rule in self.rules[filename]: rule.set_definition(self.rule_definitions, attributes, ip_ranges, params) else: self.rules[filename] = [] new_rule = Rule(self.rules_data_path, filename, self.rule_type, {'enabled': False, 'level': 'danger'}) new_rule.set_definition(self.rule_definitions, attributes, ip_ranges, params) self.rules[filename].append(new_rule)