updated webhooks for 2.4 and cleanup

This commit is contained in:
John Anderson 2018-05-23 09:41:05 -07:00
parent 201b27e52c
commit 97e71976ae
4 changed files with 54 additions and 20 deletions

View File

@ -4,6 +4,7 @@ from django import forms
from django.contrib import admin from django.contrib import admin
from django.utils.safestring import mark_safe from django.utils.safestring import mark_safe
from utilities.forms import LaxURLField
from .models import ( from .models import (
CustomField, CustomFieldChoice, Graph, ExportTemplate, TopologyMap, UserAction, CustomField, CustomFieldChoice, Graph, ExportTemplate, TopologyMap, UserAction,
Webhook Webhook
@ -24,6 +25,8 @@ def order_content_types(field):
class WebhookForm(forms.ModelForm): class WebhookForm(forms.ModelForm):
payload_url = LaxURLField()
class Meta: class Meta:
model = Webhook model = Webhook
exclude = [] exclude = []

View File

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*- # -*- 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 __future__ import unicode_literals
from django.db import migrations, models from django.db import migrations, models
@ -9,7 +9,7 @@ class Migration(migrations.Migration):
dependencies = [ dependencies = [
('contenttypes', '0002_remove_content_type_name'), ('contenttypes', '0002_remove_content_type_name'),
('extras', '0008_reports'), ('extras', '0011_django2'),
] ]
operations = [ 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_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_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.')), ('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)), ('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)), ('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)), ('enabled', models.BooleanField(default=True)),

View File

@ -31,22 +31,53 @@ class Webhook(models.Model):
that endpoint with the configured payload. that endpoint with the configured payload.
""" """
obj_type = models.ManyToManyField(ContentType, related_name='webhooks', verbose_name='Object(s)', obj_type = models.ManyToManyField(
limit_choices_to={'model__in': WEBHOOK_MODELS}, ContentType,
help_text="The object(s) to which this Webhook applies.") related_name='webhooks',
name = models.CharField(max_length=50, unique=True) verbose_name='Object(s)',
type_create = models.BooleanField(default=False, help_text="A POST will be sent to the URL when the object type(s) is created.") limit_choices_to={'model__in': WEBHOOK_MODELS},
type_update = models.BooleanField(default=False, help_text="A POST will be sent to the URL when the object type(s) is updated.") help_text="The object(s) to which this Webhook applies."
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.") name = models.CharField(
content_type = models.PositiveSmallIntegerField(choices=WEBHOOK_CT_CHOICES, default=WEBHOOK_CT_JSON) max_length=50,
secret = models.CharField(max_length=255, blank=True, help_text="When provided the request will include a 'X-Hook-Signature' " unique=True
"header which is a HMAC hex digest of the payload body using " )
"the secret as the key. The secret is not transmitted in " type_create = models.BooleanField(
"the request.") default=False,
enabled = models.BooleanField(default=True) help_text="A POST will be sent to the URL when the object type(s) is created."
insecure_ssl = models.BooleanField(default=False, help_text="When enabled, secure SSL verification will be ignored. Use with " )
"caution!") 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: class Meta:
unique_together = ('payload_url', 'type_create', "type_update", "type_delete",) unique_together = ('payload_url', 'type_create', "type_update", "type_delete",)

View File

@ -5,7 +5,7 @@ from rq.utils import import_attribute
from django_rq import job from django_rq import job
from extras.constants import * from extras.constants import WEBHOOK_CT_JSON, WEBHOOK_CT_X_WWW_FORM_ENCODED
@job('default') @job('default')