mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-09 00:58:16 -06:00
updated webhooks for 2.4 and cleanup
This commit is contained in:
parent
201b27e52c
commit
97e71976ae
@ -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 = []
|
||||||
|
@ -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)),
|
@ -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(
|
||||||
|
ContentType,
|
||||||
|
related_name='webhooks',
|
||||||
|
verbose_name='Object(s)',
|
||||||
limit_choices_to={'model__in': WEBHOOK_MODELS},
|
limit_choices_to={'model__in': WEBHOOK_MODELS},
|
||||||
help_text="The object(s) to which this Webhook applies.")
|
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.")
|
name = models.CharField(
|
||||||
type_update = models.BooleanField(default=False, help_text="A POST will be sent to the URL when the object type(s) is updated.")
|
max_length=50,
|
||||||
type_delete = models.BooleanField(default=False, help_text="A POST will be sent to the URL when the object type(s) is deleted.")
|
unique=True
|
||||||
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)
|
type_create = models.BooleanField(
|
||||||
secret = models.CharField(max_length=255, blank=True, help_text="When provided the request will include a 'X-Hook-Signature' "
|
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 "
|
"header which is a HMAC hex digest of the payload body using "
|
||||||
"the secret as the key. The secret is not transmitted in "
|
"the secret as the key. The secret is not transmitted in "
|
||||||
"the request.")
|
"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 "
|
enabled = models.BooleanField(
|
||||||
"caution!")
|
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",)
|
||||||
|
@ -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')
|
||||||
|
Loading…
Reference in New Issue
Block a user