Adding the possibility to delete elements/IOCs from watchers

This commit is contained in:
Félix Aime
2021-02-16 16:51:36 +01:00
parent af499f3cda
commit 53620b6a0a
3 changed files with 56 additions and 4 deletions

View File

@ -70,7 +70,7 @@ class IOCs(object):
@staticmethod
def delete(ioc_id):
"""
Delete an IOC by its id to the database.
Delete an IOC by its id in the database.
:return: status of the operation in JSON
"""
if db.session.query(exists().where(Ioc.id == ioc_id)).scalar():
@ -82,6 +82,21 @@ class IOCs(object):
return {"status": False,
"message": "IOC not found"}
@staticmethod
def delete_by_value(ioc_value):
"""
Delete an IOC by its value in the database.
:return: status of the operation in JSON
"""
if db.session.query(exists().where(Ioc.value == ioc_value)).scalar():
db.session.query(Ioc).filter_by(value=ioc_value).delete()
db.session.commit()
return {"status": True,
"message": "IOC deleted"}
else:
return {"status": False,
"message": "IOC not found"}
@staticmethod
def search(term):
"""

View File

@ -55,7 +55,7 @@ class WhiteList(object):
@staticmethod
def delete(elem_id):
"""
Delete an element by its id to the database.
Delete an element by its id in the database.
:return: status of the operation in a dict
"""
if db.session.query(exists().where(Whitelist.id == elem_id)).scalar():
@ -67,6 +67,21 @@ class WhiteList(object):
return {"status": False,
"message": "Element not found"}
@staticmethod
def delete_by_value(elem_value):
"""
Delete an element by its value in the database.
:return: status of the operation in a dict
"""
if db.session.query(exists().where(Whitelist.element == elem_value)).scalar():
db.session.query(Whitelist).filter_by(element=elem_value).delete()
db.session.commit()
return {"status": True,
"message": "Element deleted"}
else:
return {"status": False,
"message": "Element not found"}
@staticmethod
def search(element):
"""