clients.py 1.92 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
Lukas Burgey's avatar
Lukas Burgey committed
6
7
8
9
10

from .. import models
from ..users import User
from ..brokers import RabbitMQInstance
from .serializers import GroupSerializer, SSHPublicKeySerializer
11
12


Lukas Burgey's avatar
Lukas Burgey committed
13
14
15
class ServiceSerializer(serializers.ModelSerializer):
    class Meta:
        model = models.Service
Lukas Burgey's avatar
Lukas Burgey committed
16
17
18
        fields = [
            'name',
        ]
Lukas Burgey's avatar
Lukas Burgey committed
19
20


21
class UserSerializer(serializers.ModelSerializer):
Lukas Burgey's avatar
Lukas Burgey committed
22
    groups = GroupSerializer(many=True)
Lukas Burgey's avatar
Lukas Burgey committed
23
    userinfo = JSONField()
24
25

    class Meta:
Lukas Burgey's avatar
Lukas Burgey committed
26
        model = User
Lukas Burgey's avatar
Lukas Burgey committed
27
        fields = ['email', 'groups', 'userinfo']
28
29


30
class DeploymentSerializer(serializers.ModelSerializer):
31
    user = UserSerializer()
Lukas Burgey's avatar
Lukas Burgey committed
32
    service = ServiceSerializer()
Lukas Burgey's avatar
Lukas Burgey committed
33
    ssh_keys = SSHPublicKeySerializer(many=True)
34
    #ssh_keys_to_remove = backend_serializers.SSHPublicKeySerializer(many=True)
35
36
37

    class Meta:
        model = models.Deployment
38
39
40
41
42
43
        fields = [
            'user',
            'service',
            'ssh_keys',
            #'ssh_keys_to_remove',
        ]
44
45
46
47


class DeploymentsSerializer(serializers.Serializer):
    services = serializers.DictField(
48
49
50
51
        child=serializers.ListField(
            child=DeploymentSerializer()
        )
    )
52
53


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

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

71
72
73


class SiteSerializer(serializers.Serializer):
Lukas Burgey's avatar
Lukas Burgey committed
74
    states = DeploymentStateSerializer(many=True)
75
76
77
78


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