mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-17 04:32:51 -06:00
force webhooks to use the same JSONEncoder class as DRF - fixes #2137
This commit is contained in:
parent
5ea41fa7f9
commit
2f33e9724d
@ -1,8 +1,10 @@
|
|||||||
import hashlib
|
import hashlib
|
||||||
import hmac
|
import hmac
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
import json
|
||||||
|
|
||||||
from django_rq import job
|
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
|
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
|
Make a POST request to the defined Webhook
|
||||||
"""
|
"""
|
||||||
payload = {
|
payload = {
|
||||||
'event': dict(OBJECTCHANGE_ACTION_CHOICES)[event],
|
'event': dict(OBJECTCHANGE_ACTION_CHOICES)[event].lower(),
|
||||||
'timestamp': timestamp,
|
'timestamp': timestamp,
|
||||||
'model': model_class.__name__,
|
'model': model_class._meta.model_name,
|
||||||
'data': data
|
'data': data
|
||||||
}
|
}
|
||||||
headers = {
|
headers = {
|
||||||
@ -28,7 +30,7 @@ def process_webhook(webhook, data, model_class, event, timestamp):
|
|||||||
}
|
}
|
||||||
|
|
||||||
if webhook.http_content_type == WEBHOOK_CT_JSON:
|
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:
|
elif webhook.http_content_type == WEBHOOK_CT_X_WWW_FORM_ENCODED:
|
||||||
params.update({'data': payload})
|
params.update({'data': payload})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user