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
def to_model(cls, rule): name = getattr(rule, 'name', None) description = getattr(rule, 'description', None) # Create a trigger for the provided rule trigger_db = TriggerService.create_trigger_db_from_rule(rule) trigger = reference.get_str_resource_ref_from_model(trigger_db) criteria = dict(getattr(rule, 'criteria', {})) pack = getattr(rule, 'pack', DEFAULT_PACK_NAME) ref = ResourceReference.to_string_reference(pack=pack, name=name) # Validate criteria validator.validate_criteria(criteria) # Validate trigger parameters validator.validate_trigger_parameters(trigger_db=trigger_db) action = ActionExecutionSpecDB(ref=rule.action['ref'], parameters=rule.action['parameters']) enabled = rule.enabled tags = TagsHelper.to_model(getattr(rule, 'tags', [])) model = cls.model(name=name, description=description, pack=pack, ref=ref, trigger=trigger, criteria=criteria, action=action, enabled=enabled, tags=tags) 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) # 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): model = super(cls, cls).to_model(rule) trigger_db = TriggerService.create_trigger_db_from_rule(rule) model.trigger = reference.get_str_resource_ref_from_model(trigger_db) model.criteria = dict(getattr(rule, 'criteria', {})) model.pack = str(rule.pack) model.ref = ResourceReference.to_string_reference(pack=model.pack, name=model.name) # Validate criteria validator.validate_criteria(model.criteria) # Validate trigger parameters validator.validate_trigger_parameters(trigger_db=trigger_db) model.action = ActionExecutionSpecDB() model.action.ref = rule.action['ref'] model.action.parameters = rule.action['parameters'] model.enabled = rule.enabled model.tags = TagsHelper.to_model(getattr(rule, 'tags', [])) 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