def to_model(cls, rule): kwargs = {} kwargs["name"] = getattr(rule, "name", None) kwargs["description"] = getattr(rule, "description", None) # Validate trigger parameters # Note: This must happen before we create a trigger, otherwise create trigger could fail # with a cryptic error trigger = getattr(rule, "trigger", {}) trigger_type_ref = trigger.get("type", None) parameters = trigger.get("parameters", {}) validator.validate_trigger_parameters( trigger_type_ref=trigger_type_ref, parameters=parameters ) # Create a trigger for the provided rule trigger_db = TriggerService.create_trigger_db_from_rule(rule) kwargs["trigger"] = reference.get_str_resource_ref_from_model(trigger_db) kwargs["pack"] = getattr(rule, "pack", DEFAULT_PACK_NAME) kwargs["ref"] = ResourceReference.to_string_reference( pack=kwargs["pack"], name=kwargs["name"] ) # Validate criteria kwargs["criteria"] = dict(getattr(rule, "criteria", {})) validator.validate_criteria(kwargs["criteria"]) kwargs["action"] = ActionExecutionSpecDB( ref=rule.action["ref"], parameters=rule.action.get("parameters", {}) ) rule_type = dict(getattr(rule, "type", {})) if rule_type: kwargs["type"] = RuleTypeSpecDB( ref=rule_type["ref"], parameters=rule_type.get("parameters", {}) ) kwargs["enabled"] = getattr(rule, "enabled", False) kwargs["context"] = getattr(rule, "context", dict()) kwargs["tags"] = TagsHelper.to_model(getattr(rule, "tags", [])) kwargs["metadata_file"] = getattr(rule, "metadata_file", None) model = cls.model(**kwargs) return model
def to_model(cls, rule): kwargs = {} kwargs['name'] = getattr(rule, 'name', None) kwargs['description'] = getattr(rule, 'description', None) # Validate trigger parameters # Note: This must happen before we create a trigger, otherwise create trigger could fail # with a cryptic error trigger = getattr(rule, 'trigger', {}) trigger_type_ref = trigger.get('type', None) parameters = trigger.get('parameters', {}) validator.validate_trigger_parameters( trigger_type_ref=trigger_type_ref, parameters=parameters) # Create a trigger for the provided rule trigger_db = TriggerService.create_trigger_db_from_rule(rule) kwargs['trigger'] = reference.get_str_resource_ref_from_model( trigger_db) kwargs['pack'] = getattr(rule, 'pack', DEFAULT_PACK_NAME) kwargs['ref'] = ResourceReference.to_string_reference( pack=kwargs['pack'], name=kwargs['name']) # Validate criteria kwargs['criteria'] = dict(getattr(rule, 'criteria', {})) validator.validate_criteria(kwargs['criteria']) kwargs['action'] = ActionExecutionSpecDB(ref=rule.action['ref'], parameters=rule.action.get( 'parameters', {})) rule_type = dict(getattr(rule, 'type', {})) if rule_type: kwargs['type'] = RuleTypeSpecDB(ref=rule_type['ref'], parameters=rule_type.get( 'parameters', {})) kwargs['enabled'] = getattr(rule, 'enabled', False) kwargs['context'] = getattr(rule, 'context', dict()) kwargs['tags'] = TagsHelper.to_model(getattr(rule, 'tags', [])) kwargs['metadata_file'] = getattr(rule, 'metadata_file', None) model = cls.model(**kwargs) return model
def to_model(cls, rule): kwargs = {} kwargs['name'] = getattr(rule, 'name', None) kwargs['description'] = getattr(rule, 'description', None) # Create a trigger for the provided rule trigger_db = TriggerService.create_trigger_db_from_rule(rule) kwargs['trigger'] = reference.get_str_resource_ref_from_model( trigger_db) # Validate trigger parameters validator.validate_trigger_parameters(trigger_db=trigger_db) kwargs['pack'] = getattr(rule, 'pack', DEFAULT_PACK_NAME) kwargs['ref'] = ResourceReference.to_string_reference( pack=kwargs['pack'], name=kwargs['name']) # Validate criteria kwargs['criteria'] = dict(getattr(rule, 'criteria', {})) validator.validate_criteria(kwargs['criteria']) kwargs['action'] = ActionExecutionSpecDB(ref=rule.action['ref'], parameters=rule.action.get( 'parameters', {})) rule_type = dict(getattr(rule, 'type', {})) if rule_type: kwargs['type'] = RuleTypeSpecDB(ref=rule_type['ref'], parameters=rule_type.get( 'parameters', {})) kwargs['enabled'] = getattr(rule, 'enabled', False) kwargs['tags'] = TagsHelper.to_model(getattr(rule, 'tags', [])) model = cls.model(**kwargs) return model