clients.py 1.94 KB
Newer Older
1
2
# we don't need to deserialize, so we do not implement the abstract methods
# pylint: disable=abstract-method
3

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


Lukas Burgey's avatar
Lukas Burgey committed
9
10
11
class ServiceSerializer(serializers.ModelSerializer):
    class Meta:
        model = models.Service
Lukas Burgey's avatar
Lukas Burgey committed
12
13
14
        fields = [
            'name',
        ]
Lukas Burgey's avatar
Lukas Burgey committed
15
16


17
class UserSerializer(serializers.ModelSerializer):
18
    groups = backend_serializers.GroupSerializer(many=True)
Lukas Burgey's avatar
Lukas Burgey committed
19
    userinfo = JSONField()
20
21
22

    class Meta:
        model = models.User
Lukas Burgey's avatar
Lukas Burgey committed
23
        fields = ['email', 'groups', 'userinfo']
24
25


26
class DeploymentSerializer(serializers.ModelSerializer):
27
    user = UserSerializer()
Lukas Burgey's avatar
Lukas Burgey committed
28
    service = ServiceSerializer()
29
    ssh_keys = backend_serializers.SSHPublicKeySerializer(many=True)
30
    #ssh_keys_to_remove = backend_serializers.SSHPublicKeySerializer(many=True)
31
32
33

    class Meta:
        model = models.Deployment
34
35
36
37
38
39
        fields = [
            'user',
            'service',
            'ssh_keys',
            #'ssh_keys_to_remove',
        ]
40
41
42
43


class DeploymentsSerializer(serializers.Serializer):
    services = serializers.DictField(
44
45
46
47
        child=serializers.ListField(
            child=DeploymentSerializer()
        )
    )
48
49


Lukas Burgey's avatar
Lukas Burgey committed
50
class DeploymentStateSerializer(serializers.ModelSerializer):
51
    user = UserSerializer()
52
    key = backend_serializers.SSHPublicKeySerializer()
Lukas Burgey's avatar
Lukas Burgey committed
53
54
55
56
57
58
59
60
61
62
63
64
65
66
    service = ServiceSerializer()
    group = backend_serializers.GroupSerializer()

    class Meta:
        model = models.DeploymentState
        fields = [
            'state_target',
            'id',
            'service',
            'group',
            'key',
            'user',
        ]

67
68
69


class SiteSerializer(serializers.Serializer):
Lukas Burgey's avatar
Lukas Burgey committed
70
    states = DeploymentStateSerializer(many=True)
71
72
73
74


class RabbitMQInstanceSerializer(serializers.ModelSerializer):
    class Meta:
75
        model = broker_models.RabbitMQInstance
Lukas Burgey's avatar
Lukas Burgey committed
76
        fields = ['vhost']