serializers.py 2.97 KB
Newer Older
1
2
# we don't need to deserialize, so we do not implement the abstract methods
# pylint: disable=abstract-method
Lukas Burgey's avatar
Lukas Burgey committed
3

4
5
from rest_framework import serializers
from .. import models, serializers as backend_serializers
Lukas Burgey's avatar
Lukas Burgey committed
6
7
8
9
10


class SiteSerializer(serializers.ModelSerializer):
    class Meta:
        model = models.Site
11
        fields = ['id', 'name']
Lukas Burgey's avatar
Lukas Burgey committed
12
13
14


class ServiceSerializer(serializers.ModelSerializer):
15
    site = SiteSerializer(many=True)
16
    groups = backend_serializers.GroupSerializer(many=True)
Lukas Burgey's avatar
Lukas Burgey committed
17
18

    class Meta:
19
        model = models.Service
Lukas Burgey's avatar
Lukas Burgey committed
20
21
22
23
24
25
        fields = [
            'id',
            'name',
            'site',
            'groups',
        ]
Lukas Burgey's avatar
Lukas Burgey committed
26
27


Lukas Burgey's avatar
Lukas Burgey committed
28
class DeploymentStateItemSerializer(serializers.ModelSerializer):
Lukas Burgey's avatar
Lukas Burgey committed
29
    service = ServiceSerializer()
Lukas Burgey's avatar
Lukas Burgey committed
30
    key = backend_serializers.SSHPublicKeyRefSerializer()
Lukas Burgey's avatar
Lukas Burgey committed
31
    site = SiteSerializer()
32
    questionnaire = serializers.JSONField()
Lukas Burgey's avatar
Lukas Burgey committed
33
    credentials = serializers.JSONField()
Lukas Burgey's avatar
Lukas Burgey committed
34
35

    class Meta:
Lukas Burgey's avatar
Lukas Burgey committed
36
        model = models.DeploymentStateItem
Lukas Burgey's avatar
Lukas Burgey committed
37
        fields = [
Lukas Burgey's avatar
Lukas Burgey committed
38
            'id',
Lukas Burgey's avatar
Lukas Burgey committed
39
            'site',
40
            'state',
41
            'questionnaire',
Lukas Burgey's avatar
Lukas Burgey committed
42
43
44
            'credentials',
            'key',
            'service',
Lukas Burgey's avatar
Lukas Burgey committed
45
46
47
        ]


Lukas Burgey's avatar
Lukas Burgey committed
48
class DeploymentStateSerializer(serializers.ModelSerializer):
Lukas Burgey's avatar
Lukas Burgey committed
49
    key = backend_serializers.SSHPublicKeyRefSerializer()
Lukas Burgey's avatar
Lukas Burgey committed
50
    service = ServiceSerializer()
Lukas Burgey's avatar
Lukas Burgey committed
51
52
    state_items = DeploymentStateItemSerializer(many=True)

53
    class Meta:
Lukas Burgey's avatar
Lukas Burgey committed
54
        model = models.DeploymentState
Lukas Burgey's avatar
Lukas Burgey committed
55
        fields = [
56
            'state_target',
Lukas Burgey's avatar
Lukas Burgey committed
57
58
            'key',
            'service',
59
            'id',
Lukas Burgey's avatar
Lukas Burgey committed
60
            'state_items',
Lukas Burgey's avatar
Lukas Burgey committed
61
        ]
62
63


Lukas Burgey's avatar
Lukas Burgey committed
64
class DeploymentSerializer(serializers.ModelSerializer):
Lukas Burgey's avatar
Lukas Burgey committed
65
    service = ServiceSerializer()
66
    ssh_keys = backend_serializers.SSHPublicKeySerializer(many=True)
67
    ssh_keys_to_withdraw = backend_serializers.SSHPublicKeySerializer(many=True)
Lukas Burgey's avatar
Lukas Burgey committed
68
    states = DeploymentStateSerializer(many=True)
Lukas Burgey's avatar
Lukas Burgey committed
69
70
71

    class Meta:
        model = models.Deployment
Lukas Burgey's avatar
Lukas Burgey committed
72
73
74
75
76
77
78
        fields = [
            'service',
            'ssh_keys',
            'ssh_keys_to_withdraw',
            'states',
            'id',
        ]
Lukas Burgey's avatar
Lukas Burgey committed
79
80


Lukas Burgey's avatar
Lukas Burgey committed
81
# contains properties which change less often
Lukas Burgey's avatar
Lukas Burgey committed
82
class UserSerializer(serializers.ModelSerializer):
Lukas Burgey's avatar
Lukas Burgey committed
83
    auth_groups = backend_serializers.AuthGroupSerializer(many=True)
84
85
    groups = backend_serializers.GroupSerializer(many=True)
    ssh_keys = backend_serializers.SSHPublicKeySerializer(many=True)
Lukas Burgey's avatar
Lukas Burgey committed
86
87
88

    class Meta:
        model = models.User
Lukas Burgey's avatar
Lukas Burgey committed
89
        fields = [
Lukas Burgey's avatar
Lukas Burgey committed
90
            'auth_groups',
Lukas Burgey's avatar
Lukas Burgey committed
91
92
            'email',
            'groups',
Lukas Burgey's avatar
Lukas Burgey committed
93
94
95
            'id',
            'ssh_keys',
            'userinfo',
Lukas Burgey's avatar
Lukas Burgey committed
96
        ]
Lukas Burgey's avatar
Lukas Burgey committed
97
98


Lukas Burgey's avatar
Lukas Burgey committed
99
100
101
102
103
104
# contains properties which change a lot
class UserStateSerializer(serializers.ModelSerializer):
    deployment_state_items = DeploymentStateItemSerializer(many=True)
    deployment_states = DeploymentStateSerializer(many=True)
    deployments = DeploymentSerializer(many=True)

105
106
    class Meta:
        model = models.User
Lukas Burgey's avatar
Lukas Burgey committed
107
108
109
110
111
        fields = [
            'deployment_state_items',
            'deployment_states',
            'deployments',
        ]