core: Add Webhook Rule
This commit is contained in:
parent
cde35515c7
commit
4b047802c0
|
@ -2,7 +2,7 @@
|
|||
|
||||
from django import forms
|
||||
|
||||
from passbook.core.models import FieldMatcherRule
|
||||
from passbook.core.models import FieldMatcherRule, WebhookRule
|
||||
|
||||
|
||||
class FieldMatcherRuleForm(forms.ModelForm):
|
||||
|
@ -18,3 +18,19 @@ class FieldMatcherRuleForm(forms.ModelForm):
|
|||
'user_field': forms.TextInput(),
|
||||
'value': forms.TextInput(),
|
||||
}
|
||||
|
||||
|
||||
class WebhookRuleForm(forms.ModelForm):
|
||||
"""WebhookRuleForm Form"""
|
||||
|
||||
class Meta:
|
||||
|
||||
model = WebhookRule
|
||||
fields = ['url', 'method', 'json_body', 'json_headers',
|
||||
'result_jsonpath', 'result_json_value', ]
|
||||
widgets = {
|
||||
'json_body': forms.TextInput(),
|
||||
'json_headers': forms.TextInput(),
|
||||
'result_jsonpath': forms.TextInput(),
|
||||
'result_json_value': forms.TextInput(),
|
||||
}
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
# Generated by Django 2.1.3 on 2018-11-27 13:41
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('passbook_core', '0003_rule_order'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='WebhookRule',
|
||||
fields=[
|
||||
('rule_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='passbook_core.Rule')),
|
||||
('url', models.URLField()),
|
||||
('method', models.CharField(choices=[('get', 'get'), ('post', 'post'), ('patch', 'patch'), ('delete', 'delete'), ('put', 'put')], max_length=10)),
|
||||
('json_body', models.TextField()),
|
||||
('json_headers', models.TextField()),
|
||||
('result_jsonpath', models.TextField()),
|
||||
('result_json_value', models.TextField()),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'Webhook Rule',
|
||||
'verbose_name_plural': 'Webhook Rules',
|
||||
},
|
||||
bases=('passbook_core.rule',),
|
||||
),
|
||||
migrations.AlterModelOptions(
|
||||
name='fieldmatcherrule',
|
||||
options={'verbose_name': 'Field matcher Rule', 'verbose_name_plural': 'Field matcher Rules'},
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='fieldmatcherrule',
|
||||
name='match_action',
|
||||
field=models.CharField(choices=[('startswith', 'Starts with'), ('endswith', 'Ends with'), ('endswith', 'Contains'), ('regexp', 'Regexp'), ('exact', 'Exact')], max_length=50),
|
||||
),
|
||||
]
|
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 2.1.3 on 2018-11-27 15:22
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('passbook_core', '0004_auto_20181127_1341'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='webhookrule',
|
||||
name='method',
|
||||
field=models.CharField(choices=[('GET', 'GET'), ('POST', 'POST'), ('PATCH', 'PATCH'), ('DELETE', 'DELETE'), ('PUT', 'PUT')], max_length=10),
|
||||
),
|
||||
]
|
|
@ -175,3 +175,40 @@ class FieldMatcherRule(Rule):
|
|||
|
||||
verbose_name = _('Field matcher Rule')
|
||||
verbose_name_plural = _('Field matcher Rules')
|
||||
@reversion.register()
|
||||
class WebhookRule(Rule):
|
||||
"""Rule that asks webhook"""
|
||||
|
||||
METHOD_GET = 'GET'
|
||||
METHOD_POST = 'POST'
|
||||
METHOD_PATCH = 'PATCH'
|
||||
METHOD_DELETE = 'DELETE'
|
||||
METHOD_PUT = 'PUT'
|
||||
|
||||
METHODS = (
|
||||
(METHOD_GET, METHOD_GET),
|
||||
(METHOD_POST, METHOD_POST),
|
||||
(METHOD_PATCH, METHOD_PATCH),
|
||||
(METHOD_DELETE, METHOD_DELETE),
|
||||
(METHOD_PUT, METHOD_PUT),
|
||||
)
|
||||
|
||||
url = models.URLField()
|
||||
method = models.CharField(max_length=10, choices=METHODS)
|
||||
json_body = models.TextField()
|
||||
json_headers = models.TextField()
|
||||
result_jsonpath = models.TextField()
|
||||
result_json_value = models.TextField()
|
||||
|
||||
name = 'passbook_core.WebhookRule'
|
||||
form = 'passbook.core.forms.rules.WebhookRuleForm'
|
||||
|
||||
def passes(self, user: User):
|
||||
"""Call webhook asynchronously and report back"""
|
||||
raise NotImplementedError()
|
||||
|
||||
class Meta:
|
||||
|
||||
verbose_name = _('Webhook Rule')
|
||||
verbose_name_plural = _('Webhook Rules')
|
||||
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 2.1.3 on 2018-11-27 13:41
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('passbook_ldap', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='ldapsource',
|
||||
name='type',
|
||||
field=models.CharField(choices=[('ad', 'Active Directory'), ('generic', 'Generic')], max_length=20),
|
||||
),
|
||||
]
|
Reference in New Issue