diff --git a/netbox/extras/admin.py b/netbox/extras/admin.py index 98711e5de..0517918a5 100644 --- a/netbox/extras/admin.py +++ b/netbox/extras/admin.py @@ -4,6 +4,7 @@ from django import forms from django.contrib import admin from django.utils.safestring import mark_safe +from utilities.forms import LaxURLField from .models import ( CustomField, CustomFieldChoice, Graph, ExportTemplate, TopologyMap, UserAction, Webhook @@ -24,6 +25,8 @@ def order_content_types(field): class WebhookForm(forms.ModelForm): + payload_url = LaxURLField() + class Meta: model = Webhook exclude = [] diff --git a/netbox/extras/migrations/0009_webhooks.py b/netbox/extras/migrations/0012_auto_20180523_1635.py similarity index 89% rename from netbox/extras/migrations/0009_webhooks.py rename to netbox/extras/migrations/0012_auto_20180523_1635.py index a783b756d..ccdad0a0a 100644 --- a/netbox/extras/migrations/0009_webhooks.py +++ b/netbox/extras/migrations/0012_auto_20180523_1635.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Generated by Django 1.11.6 on 2017-10-23 18:29 +# Generated by Django 1.11.10 on 2018-05-23 16:35 from __future__ import unicode_literals from django.db import migrations, models @@ -9,7 +9,7 @@ class Migration(migrations.Migration): dependencies = [ ('contenttypes', '0002_remove_content_type_name'), - ('extras', '0008_reports'), + ('extras', '0011_django2'), ] operations = [ @@ -21,7 +21,7 @@ class Migration(migrations.Migration): ('type_create', models.BooleanField(default=False, help_text='A POST will be sent to the URL when the object type(s) is created.')), ('type_update', models.BooleanField(default=False, help_text='A POST will be sent to the URL when the object type(s) is updated.')), ('type_delete', models.BooleanField(default=False, help_text='A POST will be sent to the URL when the object type(s) is deleted.')), - ('payload_url', models.URLField(help_text='A POST will be sent to this URL based on the webhook criteria.')), + ('payload_url', models.CharField(max_length=500, verbose_name='A POST will be sent to this URL based on the webhook criteria.')), ('content_type', models.PositiveSmallIntegerField(choices=[(1, 'application/json'), (2, 'application/x-www-form-urlencoded')], default=1)), ('secret', models.CharField(blank=True, help_text="When provided the request will include a 'X-Hook-Signature' header which is a HMAC hex digest of the payload body using the secret as the key. The secret is not transmitted in the request.", max_length=255)), ('enabled', models.BooleanField(default=True)), diff --git a/netbox/extras/models.py b/netbox/extras/models.py index dcd26582c..3bd7b22d1 100644 --- a/netbox/extras/models.py +++ b/netbox/extras/models.py @@ -31,22 +31,53 @@ class Webhook(models.Model): that endpoint with the configured payload. """ - obj_type = models.ManyToManyField(ContentType, related_name='webhooks', verbose_name='Object(s)', - limit_choices_to={'model__in': WEBHOOK_MODELS}, - help_text="The object(s) to which this Webhook applies.") - name = models.CharField(max_length=50, unique=True) - type_create = models.BooleanField(default=False, help_text="A POST will be sent to the URL when the object type(s) is created.") - type_update = models.BooleanField(default=False, help_text="A POST will be sent to the URL when the object type(s) is updated.") - type_delete = models.BooleanField(default=False, help_text="A POST will be sent to the URL when the object type(s) is deleted.") - payload_url = models.URLField(help_text="A POST will be sent to this URL based on the webhook criteria.") - content_type = models.PositiveSmallIntegerField(choices=WEBHOOK_CT_CHOICES, default=WEBHOOK_CT_JSON) - secret = models.CharField(max_length=255, blank=True, help_text="When provided the request will include a 'X-Hook-Signature' " - "header which is a HMAC hex digest of the payload body using " - "the secret as the key. The secret is not transmitted in " - "the request.") - enabled = models.BooleanField(default=True) - insecure_ssl = models.BooleanField(default=False, help_text="When enabled, secure SSL verification will be ignored. Use with " - "caution!") + obj_type = models.ManyToManyField( + ContentType, + related_name='webhooks', + verbose_name='Object(s)', + limit_choices_to={'model__in': WEBHOOK_MODELS}, + help_text="The object(s) to which this Webhook applies." + ) + name = models.CharField( + max_length=50, + unique=True + ) + type_create = models.BooleanField( + default=False, + help_text="A POST will be sent to the URL when the object type(s) is created." + ) + type_update = models.BooleanField( + default=False, + help_text="A POST will be sent to the URL when the object type(s) is updated." + ) + type_delete = models.BooleanField( + default=False, + help_text="A POST will be sent to the URL when the object type(s) is deleted." + ) + payload_url = models.CharField( + max_length=500, + verbose_name="A POST will be sent to this URL based on the webhook criteria." + ) + content_type = models.PositiveSmallIntegerField( + choices=WEBHOOK_CT_CHOICES, + default=WEBHOOK_CT_JSON + ) + secret = models.CharField( + max_length=255, + blank=True, + help_text="When provided the request will include a 'X-Hook-Signature' " + "header which is a HMAC hex digest of the payload body using " + "the secret as the key. The secret is not transmitted in " + "the request." + ) + enabled = models.BooleanField( + default=True + ) + insecure_ssl = models.BooleanField( + default=False, + help_text="When enabled, secure SSL verification will be ignored. Use with " + "caution!" + ) class Meta: unique_together = ('payload_url', 'type_create', "type_update", "type_delete",) diff --git a/netbox/extras/webhooks_worker.py b/netbox/extras/webhooks_worker.py index ec06faaf1..298edbaf8 100644 --- a/netbox/extras/webhooks_worker.py +++ b/netbox/extras/webhooks_worker.py @@ -5,7 +5,7 @@ from rq.utils import import_attribute from django_rq import job -from extras.constants import * +from extras.constants import WEBHOOK_CT_JSON, WEBHOOK_CT_X_WWW_FORM_ENCODED @job('default')