This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
authentik/passbook/policies/webhook/models.py

43 lines
1.2 KiB
Python
Raw Normal View History

2019-10-07 14:33:48 +00:00
"""webhook models"""
from django.db import models
from django.utils.translation import gettext as _
from passbook.core.models import Policy
from passbook.policies.types import PolicyRequest, PolicyResult
2019-10-07 14:33:48 +00:00
class WebhookPolicy(Policy):
"""Policy that asks webhook"""
2019-12-31 11:51:16 +00:00
METHOD_GET = "GET"
METHOD_POST = "POST"
METHOD_PATCH = "PATCH"
METHOD_DELETE = "DELETE"
METHOD_PUT = "PUT"
2019-10-07 14:33:48 +00:00
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()
2019-12-31 11:51:16 +00:00
form = "passbook.policies.webhook.forms.WebhookPolicyForm"
2019-10-07 14:33:48 +00:00
def passes(self, request: PolicyRequest) -> PolicyResult:
"""Call webhook asynchronously and report back"""
raise NotImplementedError()
class Meta:
2019-12-31 11:51:16 +00:00
verbose_name = _("Webhook Policy")
verbose_name_plural = _("Webhook Policies")