authentik.enterprise.endpoints.connectors.agent.api.secure_enclave

 1from rest_framework.viewsets import ModelViewSet
 2
 3from authentik.core.api.used_by import UsedByMixin
 4from authentik.core.api.utils import ModelSerializer
 5from authentik.endpoints.connectors.agent.models import AppleIndependentSecureEnclave
 6
 7
 8class AppleIndependentSecureEnclaveSerializer(ModelSerializer):
 9    class Meta:
10        model = AppleIndependentSecureEnclave
11        fields = [
12            "uuid",
13            "user",
14            "apple_secure_enclave_key",
15            "apple_enclave_key_id",
16            "device_type",
17        ]
18
19
20class AppleIndependentSecureEnclaveViewSet(UsedByMixin, ModelViewSet):
21    queryset = AppleIndependentSecureEnclave.objects.all()
22    serializer_class = AppleIndependentSecureEnclaveSerializer
23    search_fields = [
24        "name",
25        "user__name",
26    ]
27    ordering = ["uuid"]
28    filterset_fields = ["user", "apple_enclave_key_id"]
class AppleIndependentSecureEnclaveSerializer(authentik.core.api.utils.ModelSerializer):
 9class AppleIndependentSecureEnclaveSerializer(ModelSerializer):
10    class Meta:
11        model = AppleIndependentSecureEnclave
12        fields = [
13            "uuid",
14            "user",
15            "apple_secure_enclave_key",
16            "apple_enclave_key_id",
17            "device_type",
18        ]

A ModelSerializer is just a regular Serializer, except that:

  • A set of default fields are automatically populated.
  • A set of default validators are automatically populated.
  • Default .create() and .update() implementations are provided.

The process of automatically determining a set of serializer fields based on the model fields is reasonably complex, but you almost certainly don't need to dig into the implementation.

If the ModelSerializer class doesn't generate the set of fields that you need you should either declare the extra/differing fields explicitly on the serializer class, or simply use a Serializer class.

class AppleIndependentSecureEnclaveSerializer.Meta:
10    class Meta:
11        model = AppleIndependentSecureEnclave
12        fields = [
13            "uuid",
14            "user",
15            "apple_secure_enclave_key",
16            "apple_enclave_key_id",
17            "device_type",
18        ]
fields = ['uuid', 'user', 'apple_secure_enclave_key', 'apple_enclave_key_id', 'device_type']
class AppleIndependentSecureEnclaveViewSet(authentik.core.api.used_by.UsedByMixin, rest_framework.viewsets.ModelViewSet):
21class AppleIndependentSecureEnclaveViewSet(UsedByMixin, ModelViewSet):
22    queryset = AppleIndependentSecureEnclave.objects.all()
23    serializer_class = AppleIndependentSecureEnclaveSerializer
24    search_fields = [
25        "name",
26        "user__name",
27    ]
28    ordering = ["uuid"]
29    filterset_fields = ["user", "apple_enclave_key_id"]

Mixin to add a used_by endpoint to return a list of all objects using this object

queryset = <QuerySet []>
serializer_class = <class 'AppleIndependentSecureEnclaveSerializer'>
search_fields = ['name', 'user__name']
ordering = ['uuid']
filterset_fields = ['user', 'apple_enclave_key_id']
name = None
description = None
suffix = None
detail = None
basename = None