serializers.py 1.01 KB
Newer Older
Lukas Burgey's avatar
Lukas Burgey committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from django.contrib.auth.models import Group
from rest_framework import serializers
from . import models


class GroupSerializer(serializers.ModelSerializer):
    class Meta:
        model = Group
        fields = ['name']


class SiteSerializer(serializers.ModelSerializer):
    class Meta:
        model = models.Site
        fields = ['name']


class ServiceSerializer(serializers.ModelSerializer):
    site = SiteSerializer()
    groups = GroupSerializer(many=True)

    class Meta:
        model = models.Site
        exclude = ['id']


class SSHPublicKeySerializer(serializers.ModelSerializer):
    class Meta:
        model = models.SSHPublicKey
        fields = ['name', 'key']


class UserSerializer(serializers.ModelSerializer):
    groups = GroupSerializer(many=True)
    ssh_keys = SSHPublicKeySerializer(many=True)

    class Meta:
        model = models.User
        fields = ['sub', 'email', 'username', 'ssh_keys', 'groups']


class StateSerializer(serializers.Serializer):
    services = ServiceSerializer(many=True)