def to_model(cls, triggertype): model = super(cls, cls).to_model(triggertype) model.pack = getattr(triggertype, 'pack', None) model.payload_schema = getattr(triggertype, 'payload_schema', {}) model.parameters_schema = getattr(triggertype, 'parameters_schema', {}) model.tags = TagsHelper.to_model(getattr(triggertype, 'tags', [])) return model
def to_model(cls, action): name = getattr(action, 'name', None) description = getattr(action, 'description', None) enabled = bool(getattr(action, 'enabled', True)) entry_point = str(action.entry_point) pack = str(action.pack) runner_type = {'name': str(action.runner_type)} parameters = getattr(action, 'parameters', dict()) tags = TagsHelper.to_model(getattr(action, 'tags', [])) ref = ResourceReference.to_string_reference(pack=pack, name=name) if getattr(action, 'notify', None): notify = NotificationsHelper.to_model(action.notify) else: notify = None model = cls.model(name=name, description=description, enable=enabled, enabled=enabled, entry_point=entry_point, pack=pack, runner_type=runner_type, tags=tags, parameters=parameters, notify=notify, ref=ref) 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) # 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, action): name = getattr(action, 'name', None) description = getattr(action, 'description', None) enabled = bool(getattr(action, 'enabled', True)) entry_point = str(action.entry_point) pack = str(action.pack) runner_type = {'name': str(action.runner_type)} parameters = getattr(action, 'parameters', dict()) tags = TagsHelper.to_model(getattr(action, 'tags', [])) ref = ResourceReference.to_string_reference(pack=pack, name=name) if getattr(action, 'notify', None): notify = NotificationsHelper.to_model(action.notify) else: # We use embedded document model for ``notify`` in action model. If notify is # set notify to None, Mongoengine interprets ``None`` as unmodified # field therefore doesn't delete the embedded document. Therefore, we need # to use an empty document. notify = NotificationsHelper.to_model({}) model = cls.model(name=name, description=description, enabled=enabled, entry_point=entry_point, pack=pack, runner_type=runner_type, tags=tags, parameters=parameters, notify=notify, ref=ref) return model
def to_model(cls, triggertype): model = super(cls, cls).to_model(triggertype) model.pack = getattr(triggertype, 'pack', None) model.payload_schema = getattr(triggertype, 'payload_schema', {}) model.parameters_schema = getattr(triggertype, 'parameters_schema', {}) model.tags = TagsHelper.to_model(getattr(triggertype, 'tags', [])) 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, action): name = getattr(action, 'name', None) description = getattr(action, 'description', None) enabled = bool(getattr(action, 'enabled', True)) entry_point = str(action.entry_point) pack = str(action.pack) runner_type = {'name': str(action.runner_type)} parameters = getattr(action, 'parameters', dict()) tags = TagsHelper.to_model(getattr(action, 'tags', [])) ref = ResourceReference.to_string_reference(pack=pack, name=name) if getattr(action, 'notify', None): notify = NotificationsHelper.to_model(action.notify) else: # We use embedded document model for ``notify`` in action model. If notify is # set notify to None, Mongoengine interprets ``None`` as unmodified # field therefore doesn't delete the embedded document. Therefore, we need # to use an empty document. notify = NotificationsHelper.to_model({}) model = cls.model(name=name, description=description, enabled=enabled, entry_point=entry_point, pack=pack, runner_type=runner_type, tags=tags, parameters=parameters, notify=notify, ref=ref) return model
def to_model(cls, action): name = getattr(action, "name", None) description = getattr(action, "description", None) enabled = bool(getattr(action, "enabled", True)) entry_point = str(action.entry_point) pack = str(action.pack) runner_type = {"name": str(action.runner_type)} parameters = getattr(action, "parameters", dict()) tags = TagsHelper.to_model(getattr(action, "tags", [])) ref = ResourceReference.to_string_reference(pack=pack, name=name) if getattr(action, "notify", None): notify = NotificationsHelper.to_model(action.notify) else: notify = None model = cls.model( name=name, description=description, enable=enabled, enabled=enabled, entry_point=entry_point, pack=pack, runner_type=runner_type, tags=tags, parameters=parameters, notify=notify, ref=ref, ) return model
def to_model(cls, action): model = super(cls, cls).to_model(action) model.enabled = bool(action.enabled) model.entry_point = str(action.entry_point) model.pack = str(action.pack) model.runner_type = {'name': str(action.runner_type)} model.parameters = getattr(action, 'parameters', dict()) model.tags = TagsHelper.to_model(getattr(action, 'tags', [])) return model
def to_model(cls, action): model = super(cls, cls).to_model(action) model.enabled = bool(action.enabled) model.entry_point = str(action.entry_point) model.pack = str(action.pack) model.runner_type = {'name': str(action.runner_type)} model.parameters = getattr(action, 'parameters', dict()) model.tags = TagsHelper.to_model(getattr(action, 'tags', [])) model.ref = ResourceReference.to_string_reference(pack=model.pack, name=model.name) return model
def to_model(cls, trigger_type): name = getattr(trigger_type, 'name', None) description = getattr(trigger_type, 'description', None) pack = getattr(trigger_type, 'pack', None) payload_schema = getattr(trigger_type, 'payload_schema', {}) parameters_schema = getattr(trigger_type, 'parameters_schema', {}) tags = TagsHelper.to_model(getattr(trigger_type, 'tags', [])) model = cls.model(name=name, description=description, pack=pack, payload_schema=payload_schema, parameters_schema=parameters_schema, tags=tags) return model
def to_model(cls, trigger_type): name = getattr(trigger_type, 'name', None) description = getattr(trigger_type, 'description', None) pack = getattr(trigger_type, 'pack', None) payload_schema = getattr(trigger_type, 'payload_schema', {}) parameters_schema = getattr(trigger_type, 'parameters_schema', {}) tags = TagsHelper.to_model(getattr(trigger_type, 'tags', [])) model = cls.model(name=name, description=description, pack=pack, payload_schema=payload_schema, parameters_schema=parameters_schema, tags=tags) 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', {})) validator.validate_criteria(model.criteria) 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, action): model = super(cls, cls).to_model(action) model.enabled = bool(action.enabled) model.entry_point = str(action.entry_point) model.pack = str(action.pack) model.runner_type = {'name': str(action.runner_type)} model.parameters = getattr(action, 'parameters', dict()) model.tags = TagsHelper.to_model(getattr(action, 'tags', [])) model.ref = ResourceReference.to_string_reference(pack=model.pack, name=model.name) if getattr(action, 'notify', None): model.notify = NotificationsHelper.to_model(action.notify) 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, trigger_type): name = getattr(trigger_type, "name", None) description = getattr(trigger_type, "description", None) pack = getattr(trigger_type, "pack", None) payload_schema = getattr(trigger_type, "payload_schema", {}) parameters_schema = getattr(trigger_type, "parameters_schema", {}) tags = TagsHelper.to_model(getattr(trigger_type, "tags", [])) metadata_file = getattr(trigger_type, "metadata_file", None) model = cls.model( name=name, description=description, pack=pack, payload_schema=payload_schema, parameters_schema=parameters_schema, tags=tags, metadata_file=metadata_file, ) 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, action): name = getattr(action, "name", None) description = getattr(action, "description", None) enabled = bool(getattr(action, "enabled", True)) entry_point = str(action.entry_point) pack = str(action.pack) runner_type = {"name": str(action.runner_type)} parameters = getattr(action, "parameters", dict()) output_schema = getattr(action, "output_schema", dict()) tags = TagsHelper.to_model(getattr(action, "tags", [])) ref = ResourceReference.to_string_reference(pack=pack, name=name) if getattr(action, "notify", None): notify = NotificationsHelper.to_model(action.notify) else: # We use embedded document model for ``notify`` in action model. If notify is # set notify to None, Mongoengine interprets ``None`` as unmodified # field therefore doesn't delete the embedded document. Therefore, we need # to use an empty document. notify = NotificationsHelper.to_model({}) metadata_file = getattr(action, "metadata_file", None) model = cls.model( name=name, description=description, enabled=enabled, entry_point=entry_point, pack=pack, runner_type=runner_type, tags=tags, parameters=parameters, output_schema=output_schema, notify=notify, ref=ref, metadata_file=metadata_file, ) 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