authentik.policies.event_matcher.api
Event Matcher Policy API
1"""Event Matcher Policy API""" 2 3from django.utils.translation import gettext as _ 4from rest_framework.exceptions import ValidationError 5from rest_framework.fields import ChoiceField 6from rest_framework.viewsets import ModelViewSet 7 8from authentik.core.api.used_by import UsedByMixin 9from authentik.lib.api import app_choices, model_choices 10from authentik.policies.api.policies import PolicySerializer 11from authentik.policies.event_matcher.models import EventMatcherPolicy 12 13 14class EventMatcherPolicySerializer(PolicySerializer): 15 """Event Matcher Policy Serializer""" 16 17 app = ChoiceField( 18 choices=app_choices(), 19 required=False, 20 allow_null=True, 21 help_text=_( 22 "Match events created by selected application. When left empty, " 23 "all applications are matched." 24 ), 25 ) 26 model = ChoiceField( 27 choices=model_choices(), 28 required=False, 29 allow_null=True, 30 help_text=_( 31 "Match events created by selected model. " 32 "When left empty, all models are matched. When an app is selected, " 33 "all the application's models are matched." 34 ), 35 ) 36 37 def validate(self, attrs: dict) -> dict: 38 if ( 39 attrs["action"] == "" 40 and attrs["client_ip"] == "" 41 and attrs["app"] == "" 42 and attrs["model"] == "" 43 and attrs["query"] == "" 44 ): 45 raise ValidationError(_("At least one criteria must be set.")) 46 return super().validate(attrs) 47 48 class Meta: 49 model = EventMatcherPolicy 50 fields = PolicySerializer.Meta.fields + ["action", "client_ip", "app", "model", "query"] 51 52 53class EventMatcherPolicyViewSet(UsedByMixin, ModelViewSet): 54 """Event Matcher Policy Viewset""" 55 56 queryset = EventMatcherPolicy.objects.all() 57 serializer_class = EventMatcherPolicySerializer 58 filterset_fields = "__all__" 59 ordering = ["name"] 60 search_fields = ["name"]
15class EventMatcherPolicySerializer(PolicySerializer): 16 """Event Matcher Policy Serializer""" 17 18 app = ChoiceField( 19 choices=app_choices(), 20 required=False, 21 allow_null=True, 22 help_text=_( 23 "Match events created by selected application. When left empty, " 24 "all applications are matched." 25 ), 26 ) 27 model = ChoiceField( 28 choices=model_choices(), 29 required=False, 30 allow_null=True, 31 help_text=_( 32 "Match events created by selected model. " 33 "When left empty, all models are matched. When an app is selected, " 34 "all the application's models are matched." 35 ), 36 ) 37 38 def validate(self, attrs: dict) -> dict: 39 if ( 40 attrs["action"] == "" 41 and attrs["client_ip"] == "" 42 and attrs["app"] == "" 43 and attrs["model"] == "" 44 and attrs["query"] == "" 45 ): 46 raise ValidationError(_("At least one criteria must be set.")) 47 return super().validate(attrs) 48 49 class Meta: 50 model = EventMatcherPolicy 51 fields = PolicySerializer.Meta.fields + ["action", "client_ip", "app", "model", "query"]
Event Matcher Policy Serializer
Inherited Members
class
EventMatcherPolicySerializer.Meta:
49 class Meta: 50 model = EventMatcherPolicy 51 fields = PolicySerializer.Meta.fields + ["action", "client_ip", "app", "model", "query"]
model =
<class 'authentik.policies.event_matcher.models.EventMatcherPolicy'>
class
EventMatcherPolicyViewSet(authentik.core.api.used_by.UsedByMixin, rest_framework.viewsets.ModelViewSet):
54class EventMatcherPolicyViewSet(UsedByMixin, ModelViewSet): 55 """Event Matcher Policy Viewset""" 56 57 queryset = EventMatcherPolicy.objects.all() 58 serializer_class = EventMatcherPolicySerializer 59 filterset_fields = "__all__" 60 ordering = ["name"] 61 search_fields = ["name"]
Event Matcher Policy Viewset
serializer_class =
<class 'EventMatcherPolicySerializer'>