Commit 257f40f6 authored by Alexandre Moevi's avatar Alexandre Moevi

doc(webhooks): add doc

parent 2ee468a6
Pipeline #4498 passed with stage
in 2 minutes and 1 second
......@@ -36,6 +36,12 @@ def exports(ws):
'/api/v2/webhook'
)
def get_webhook_list():
"""
Return the list of all webhooks.
:returns: <Webhook>
:rtype: list
"""
try:
document = webhook_manager.get_webhook_list()
except PyMongoError:
......@@ -50,6 +56,14 @@ def exports(ws):
'/api/v2/webhook/<webhook_id>'
)
def get_webhook_by_id(webhook_id):
"""
Return a webhook given the id.
:param webhook_id: ID of the webhook
:type webhook_id: str
:returns: <Webhook>
:rtype: dict
"""
try:
document = webhook_manager.get_webhook_by_id(webhook_id)
except PyMongoError:
......@@ -64,6 +78,12 @@ def exports(ws):
'/api/v2/webhook'
)
def create_webhook():
"""
Create a new webhook.
:returns: ID of the webhook
:rtype: string
"""
try:
webhook = request.json
except ValueError:
......@@ -89,6 +109,13 @@ def exports(ws):
'/api/v2/webhook/<webhook_id>'
)
def update_webhook_by_id(webhook_id):
"""
Update an existing webhook.
:param webhook_id: ID of the webhook
:type webhook_id: str
:rtype: dict
"""
try:
webhook = request.json
except ValueError:
......@@ -122,6 +149,13 @@ def exports(ws):
'/api/v2/webhook/<webhook_id>'
)
def delete_webhook_by_id(webhook_id):
"""
Delte an existing webhook, given its id.
:param webhook_id: ID of the webhook
:type webhook_id: str
:rtype: dict
"""
try:
ok = webhook_manager.delete_webhook_by_id(webhook_id)
except PyMongoError:
......
......@@ -23,6 +23,9 @@ from canopsis.common.collection import MongoCollection
class WebhookManager(object):
"""
Manager for the webhooks
"""
COLLECTION = "webhooks"
......@@ -47,18 +50,53 @@ class WebhookManager(object):
return MongoCollection(collection)
def get_webhook_list(self):
"""
Return a list of all the webhooks.
:rtype: List[Dict[str, Any]]
"""
return list(self.__collection.find({}))
def get_webhook_by_id(self, wid):
"""
Get a webhook given its id.
:param str rule_id: the id of the webhook.
:rtype: Dict[str, Any]
"""
return self.__collection.find_one({'_id': wid})
def create_webhook(self, webhook):
"""
Create a webhook and return its id.
:param Dict[str, Any] webhook:
:rtype: str
:raises: CollectionError if the creation fails.
"""
return self.__collection.insert(webhook)
def update_webhook_by_id(self, webhook, wid):
"""
Update a webhook given its id.
Return a boolean if the operation is successful.
:param str wid: the id of the webhook.
:param Dict[str, Any] webhook:
:rtype: bool
:raises: CollectionError if the update fails.
"""
resp = self.__collection.update(query={'_id': wid}, document=webhook)
return self.__collection.is_successfull(resp)
def delete_webhook_by_id(self, wid):
"""
Remove a webhook given its id.
Return a boolean if the operation is successful.
:param str wid: the id of the rule.
:rtype: bool
:raises: CollectionError if the deletion fails.
"""
resp = self.__collection.remove({'_id': wid})
return self.__collection.is_successfull(resp)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment