mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Merge pull request #3605 from netbox-community/3445-webhooks-additional-headers
implemented #3445 - Add support for additional user defined headers t…
This commit is contained in:
@ -2,12 +2,11 @@
|
|||||||
|
|
||||||
## Enhancements
|
## Enhancements
|
||||||
|
|
||||||
|
* [#3445](https://github.com/netbox-community/netbox/issues/3445) - Add support for additional user defined headers to be added to webhook requests
|
||||||
* [#3499](https://github.com/netbox-community/netbox/issues/3499) - Add `ca_file_path` to Webhook model to support user supplied CA certificate verification of webhook requests
|
* [#3499](https://github.com/netbox-community/netbox/issues/3499) - Add `ca_file_path` to Webhook model to support user supplied CA certificate verification of webhook requests
|
||||||
|
|
||||||
## Bug Fixes
|
## Bug Fixes
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
# v2.6.6 (2019-10-10)
|
# v2.6.6 (2019-10-10)
|
||||||
|
19
netbox/extras/migrations/0027_webhook_additional_headers.py
Normal file
19
netbox/extras/migrations/0027_webhook_additional_headers.py
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
# Generated by Django 2.2 on 2019-10-13 07:06
|
||||||
|
|
||||||
|
import django.contrib.postgres.fields.jsonb
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('extras', '0026_webhook_ca_file_path'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='webhook',
|
||||||
|
name='additional_headers',
|
||||||
|
field=django.contrib.postgres.fields.jsonb.JSONField(blank=True, null=True),
|
||||||
|
),
|
||||||
|
]
|
@ -70,6 +70,12 @@ class Webhook(models.Model):
|
|||||||
default=WEBHOOK_CT_JSON,
|
default=WEBHOOK_CT_JSON,
|
||||||
verbose_name='HTTP content type'
|
verbose_name='HTTP content type'
|
||||||
)
|
)
|
||||||
|
additional_headers = JSONField(
|
||||||
|
null=True,
|
||||||
|
blank=True,
|
||||||
|
help_text="User supplied headers which should be added to the request in addition to the HTTP content type. "
|
||||||
|
"Headers are supplied as key/value pairs in a JSON object."
|
||||||
|
)
|
||||||
secret = models.CharField(
|
secret = models.CharField(
|
||||||
max_length=255,
|
max_length=255,
|
||||||
blank=True,
|
blank=True,
|
||||||
@ -115,6 +121,12 @@ class Webhook(models.Model):
|
|||||||
'ca_file_path': 'Do not specify a CA certificate file if SSL verification is dissabled.'
|
'ca_file_path': 'Do not specify a CA certificate file if SSL verification is dissabled.'
|
||||||
})
|
})
|
||||||
|
|
||||||
|
# Verify that JSON data is provided as an object
|
||||||
|
if self.additional_headers and type(self.additional_headers) is not dict:
|
||||||
|
raise ValidationError({
|
||||||
|
'additional_headers': 'Header JSON data must be in object form. Example: {"X-API-KEY": "abc123"}'
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Custom fields
|
# Custom fields
|
||||||
|
@ -25,6 +25,9 @@ def process_webhook(webhook, data, model_name, event, timestamp, username, reque
|
|||||||
headers = {
|
headers = {
|
||||||
'Content-Type': webhook.get_http_content_type_display(),
|
'Content-Type': webhook.get_http_content_type_display(),
|
||||||
}
|
}
|
||||||
|
if webhook.additional_headers:
|
||||||
|
headers.update(webhook.additional_headers)
|
||||||
|
|
||||||
params = {
|
params = {
|
||||||
'method': 'POST',
|
'method': 'POST',
|
||||||
'url': webhook.payload_url,
|
'url': webhook.payload_url,
|
||||||
|
Reference in New Issue
Block a user