webpage.py 3.23 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
from rest_framework import serializers
Lukas Burgey's avatar
Lukas Burgey committed
5

6
7
from ... import models
from .. import serializers as backend_serializers
Lukas Burgey's avatar
Lukas Burgey committed
8
9
10
11
12


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


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

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


Lukas Burgey's avatar
Lukas Burgey committed
31
class DeploymentStateItemSerializer(serializers.ModelSerializer):
Lukas Burgey's avatar
Lukas Burgey committed
32
    service = ServiceSerializer()
Lukas Burgey's avatar
Lukas Burgey committed
33
    #services = ServiceSerializer(many=True)
Lukas Burgey's avatar
Lukas Burgey committed
34
    key = backend_serializers.SSHPublicKeyRefSerializer()
Lukas Burgey's avatar
Lukas Burgey committed
35
    site = SiteSerializer()
36
    questionnaire = serializers.JSONField()
Lukas Burgey's avatar
Lukas Burgey committed
37
    credentials = serializers.JSONField()
Lukas Burgey's avatar
Lukas Burgey committed
38
    group = backend_serializers.GroupSerializer()
Lukas Burgey's avatar
Lukas Burgey committed
39
40

    class Meta:
Lukas Burgey's avatar
Lukas Burgey committed
41
        model = models.DeploymentStateItem
Lukas Burgey's avatar
Lukas Burgey committed
42
        fields = [
Lukas Burgey's avatar
Lukas Burgey committed
43
            'id',
Lukas Burgey's avatar
Lukas Burgey committed
44
            'site',
45
            'state',
46
            'questionnaire',
Lukas Burgey's avatar
Lukas Burgey committed
47
48
49
            'credentials',
            'key',
            'service',
Lukas Burgey's avatar
Lukas Burgey committed
50
            #'services',
Lukas Burgey's avatar
Lukas Burgey committed
51
            'group',
52
            'message',
Lukas Burgey's avatar
Lukas Burgey committed
53
54
55
        ]


Lukas Burgey's avatar
Lukas Burgey committed
56
class DeploymentStateSerializer(serializers.ModelSerializer):
Lukas Burgey's avatar
Lukas Burgey committed
57
    key = backend_serializers.SSHPublicKeyRefSerializer()
Lukas Burgey's avatar
Lukas Burgey committed
58
    service = ServiceSerializer()
Lukas Burgey's avatar
Lukas Burgey committed
59
60
    state_items = DeploymentStateItemSerializer(many=True)

61
    class Meta:
Lukas Burgey's avatar
Lukas Burgey committed
62
        model = models.DeploymentState
Lukas Burgey's avatar
Lukas Burgey committed
63
        fields = [
64
            'state_target',
Lukas Burgey's avatar
Lukas Burgey committed
65
66
            'key',
            'service',
67
            'id',
Lukas Burgey's avatar
Lukas Burgey committed
68
            'state_items',
Lukas Burgey's avatar
Lukas Burgey committed
69
        ]
70
71


Lukas Burgey's avatar
Lukas Burgey committed
72
class DeploymentSerializer(serializers.ModelSerializer):
Lukas Burgey's avatar
Lukas Burgey committed
73
    sites = SiteSerializer(many=True)
Lukas Burgey's avatar
Lukas Burgey committed
74
    service = ServiceSerializer()
75
76
    services = ServiceSerializer(many=True)
    ssh_keys = backend_serializers.SSHPublicKeyRefSerializer(many=True)
77
    #ssh_keys_to_remove = backend_serializers.SSHPublicKeySerializer(many=True)
Lukas Burgey's avatar
Lukas Burgey committed
78
    states = DeploymentStateSerializer(many=True)
Lukas Burgey's avatar
Lukas Burgey committed
79
80
81

    class Meta:
        model = models.Deployment
Lukas Burgey's avatar
Lukas Burgey committed
82
        fields = [
Lukas Burgey's avatar
Lukas Burgey committed
83
            'sites',
Lukas Burgey's avatar
Lukas Burgey committed
84
            'service',
85
86
            'services',
            'group',
Lukas Burgey's avatar
Lukas Burgey committed
87
            'ssh_keys',
88
            #'ssh_keys_to_remove',
Lukas Burgey's avatar
Lukas Burgey committed
89
90
91
            'states',
            'id',
        ]
Lukas Burgey's avatar
Lukas Burgey committed
92
93


Lukas Burgey's avatar
Lukas Burgey committed
94
# contains properties which change less often
Lukas Burgey's avatar
Lukas Burgey committed
95
class UserSerializer(serializers.ModelSerializer):
96
97
    groups = backend_serializers.GroupSerializer(many=True)
    ssh_keys = backend_serializers.SSHPublicKeySerializer(many=True)
Lukas Burgey's avatar
Lukas Burgey committed
98
99

    class Meta:
Lukas Burgey's avatar
Lukas Burgey committed
100
        model = models.User
Lukas Burgey's avatar
Lukas Burgey committed
101
        fields = [
Lukas Burgey's avatar
Lukas Burgey committed
102
            'profile_name',
Lukas Burgey's avatar
Lukas Burgey committed
103
            'groups',
Lukas Burgey's avatar
Lukas Burgey committed
104
105
106
            'id',
            'ssh_keys',
            'userinfo',
Lukas Burgey's avatar
Lukas Burgey committed
107
        ]
Lukas Burgey's avatar
Lukas Burgey committed
108
109


Lukas Burgey's avatar
Lukas Burgey committed
110
111
112
113
114
115
# 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)

116
    class Meta:
Lukas Burgey's avatar
Lukas Burgey committed
117
        model = models.User
Lukas Burgey's avatar
Lukas Burgey committed
118
119
120
121
122
        fields = [
            'deployment_state_items',
            'deployment_states',
            'deployments',
        ]