serializers.py 1.65 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, serializers as backend_serializers
7
8


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


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

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


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

    class Meta:
        model = models.Deployment
Lukas Burgey's avatar
Lukas Burgey committed
32
        fields = ['user', 'service', 'ssh_keys', 'ssh_keys_to_withdraw']
33
34
35
36


class DeploymentsSerializer(serializers.Serializer):
    services = serializers.DictField(
37
38
39
40
        child=serializers.ListField(
            child=DeploymentSerializer()
        )
    )
41
42
43
44
45
46
47


class DeploymentTaskSerializer(serializers.Serializer):
    id = serializers.IntegerField()
    action = serializers.CharField()
    user = UserSerializer()
    service = ServiceSerializer()
48
    key = backend_serializers.SSHPublicKeySerializer()
49
50
51
52


class SiteSerializer(serializers.Serializer):
    tasks = DeploymentTaskSerializer(many=True)
53
54
55
56
57


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