webpage.py 3.24 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
8

from .. import models
from ..users import User
from . import serializers as backend_serializers
Lukas Burgey's avatar
Lukas Burgey committed
9
10
11
12
13


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


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

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


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

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


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

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


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

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


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

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


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

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