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 ): 44 raise ValidationError(_("At least one criteria must be set.")) 45 return super().validate(attrs) 46 47 class Meta: 48 model = EventMatcherPolicy 49 fields = PolicySerializer.Meta.fields + [ 50 "action", 51 "client_ip", 52 "app", 53 "model", 54 ] 55 56 57class EventMatcherPolicyViewSet(UsedByMixin, ModelViewSet): 58 """Event Matcher Policy Viewset""" 59 60 queryset = EventMatcherPolicy.objects.all() 61 serializer_class = EventMatcherPolicySerializer 62 filterset_fields = "__all__" 63 ordering = ["name"] 64 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 ): 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 + [ 51 "action", 52 "client_ip", 53 "app", 54 "model", 55 ]
Event Matcher Policy Serializer
Inherited Members
class
EventMatcherPolicySerializer.Meta:
48 class Meta: 49 model = EventMatcherPolicy 50 fields = PolicySerializer.Meta.fields + [ 51 "action", 52 "client_ip", 53 "app", 54 "model", 55 ]
model =
<class 'authentik.policies.event_matcher.models.EventMatcherPolicy'>
class
EventMatcherPolicyViewSet(authentik.core.api.used_by.UsedByMixin, rest_framework.viewsets.ModelViewSet):
58class EventMatcherPolicyViewSet(UsedByMixin, ModelViewSet): 59 """Event Matcher Policy Viewset""" 60 61 queryset = EventMatcherPolicy.objects.all() 62 serializer_class = EventMatcherPolicySerializer 63 filterset_fields = "__all__" 64 ordering = ["name"] 65 search_fields = ["name"]
Event Matcher Policy Viewset
serializer_class =
<class 'EventMatcherPolicySerializer'>