1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

force webhooks to use the same JSONEncoder class as DRF - fixes #2137

This commit is contained in:
John Anderson
2018-07-31 16:17:24 -04:00
parent 5ea41fa7f9
commit 2f33e9724d

View File

@ -1,8 +1,10 @@
import hashlib
import hmac
import requests
import json
from django_rq import job
from rest_framework.utils.encoders import JSONEncoder
from extras.constants import WEBHOOK_CT_JSON, WEBHOOK_CT_X_WWW_FORM_ENCODED, OBJECTCHANGE_ACTION_CHOICES
@ -13,9 +15,9 @@ def process_webhook(webhook, data, model_class, event, timestamp):
Make a POST request to the defined Webhook
"""
payload = {
'event': dict(OBJECTCHANGE_ACTION_CHOICES)[event],
'event': dict(OBJECTCHANGE_ACTION_CHOICES)[event].lower(),
'timestamp': timestamp,
'model': model_class.__name__,
'model': model_class._meta.model_name,
'data': data
}
headers = {
@ -28,7 +30,7 @@ def process_webhook(webhook, data, model_class, event, timestamp):
}
if webhook.http_content_type == WEBHOOK_CT_JSON:
params.update({'json': payload})
params.update({'data': json.dumps(payload, cls=JSONEncoder)})
elif webhook.http_content_type == WEBHOOK_CT_X_WWW_FORM_ENCODED:
params.update({'data': payload})