Commit 4568bf16 authored by Lukas Burgey's avatar Lukas Burgey

Rework webpage serializer structure

parent 1ac44034
......@@ -177,7 +177,7 @@ class NewDeployment(models.Model):
# credentials provided by the backend to the clients
@property
def user_credentials(self):
def credentials(self):
return self.user.credentials
@property
......@@ -316,10 +316,9 @@ class NewDeployment(models.Model):
item.user_deploy()
def publish_to_client(self):
# mitigating circular dependencies here
# avoiding circular dependencies here
from .serializers.clients import NewDeploymentSerializer
data = NewDeploymentSerializer(self).data
data['credentials'] = self.user_credentials
msg = dumps(data)
if self.service is not None:
......@@ -333,7 +332,6 @@ class NewDeployment(models.Model):
msg,
)
else:
LOGGER.error('Deployment has neither a group or a service')
raise ValueError('Deployment has neither a group or a service')
# sends a state update via RabbitMQ / STOMP to the users webpage instance
......
......@@ -7,19 +7,16 @@ from rest_framework import serializers
from ... import models
class GroupDescriptionSerializer(serializers.ModelSerializer):
# group = backend_serializers.GroupSerializer()
class GroupDescriptionSerializer(serializers.ModelSerializer):
class Meta:
model = models.GroupDescription
fields = [
# 'group',
'description',
]
class GroupSerializer(serializers.ModelSerializer):
description = GroupDescriptionSerializer()
class Meta:
......@@ -50,8 +47,17 @@ class SSHPublicKeyRefSerializer(serializers.ModelSerializer):
]
class CredentialStateSerializer(serializers.ModelSerializer):
class CredentialSerializer(serializers.ModelSerializer):
class Meta:
model = models.SSHPublicKey
fields = [
'id',
'name',
'value',
]
class CredentialStateSerializer(serializers.ModelSerializer):
credential = SSHPublicKeyRefSerializer()
class Meta:
......@@ -62,6 +68,7 @@ class CredentialStateSerializer(serializers.ModelSerializer):
'credential',
]
# "exports"
from .webpage import NewDeploymentSerializer
from .clients import RabbitMQInstanceSerializer
......@@ -5,9 +5,17 @@ from django_mysql.models import JSONField
from rest_framework import serializers
from ... import models
from .. import serializers as backend_serializers
from . import GroupSerializer
CredentialSerializer = serializers.DictField(
child=serializers.ListField(
child=backend_serializers.CredentialSerializer()
)
)
class ServiceSerializer(serializers.ModelSerializer):
class Meta:
model = models.Service
......@@ -19,6 +27,7 @@ class ServiceSerializer(serializers.ModelSerializer):
class UserSerializer(serializers.ModelSerializer):
groups = GroupSerializer(many=True)
userinfo = JSONField()
# credentials = CredentialSerializer
class Meta:
model = models.User
......@@ -26,6 +35,7 @@ class UserSerializer(serializers.ModelSerializer):
'email',
'groups',
'userinfo',
# 'credentials',
]
......@@ -33,6 +43,7 @@ class NewDeploymentSerializer(serializers.ModelSerializer):
user = UserSerializer()
service = ServiceSerializer()
group = GroupSerializer()
credentials = CredentialSerializer
class Meta:
model = models.NewDeployment
......@@ -42,17 +53,10 @@ class NewDeploymentSerializer(serializers.ModelSerializer):
'service',
'group',
'user',
'credentials',
]
class NewDeploymentsSerializer(serializers.Serializer):
services = serializers.DictField(
child=serializers.ListField(
child=NewDeploymentSerializer()
)
)
class RabbitMQInstanceSerializer(serializers.ModelSerializer):
class Meta:
model = models.RabbitMQInstance
......
......@@ -94,13 +94,7 @@ class User(AbstractUser):
@property
def credentials(self):
return {
'ssh_key': [
{
'name': key.name,
'value': key.key
}
for key in self.ssh_keys.all()
]
'ssh_key': self.ssh_keys.all(),
}
@property
......@@ -409,6 +403,10 @@ class SSHPublicKey(models.Model):
editable=False,
)
@property
def value(self):
return self.key
# does not really delete the key
def delete_key(self):
LOGGER.debug('delete_key: %s', self.name)
......
......@@ -7,8 +7,7 @@ from rest_framework import generics, views
from rest_framework.authentication import BasicAuthentication
from rest_framework.response import Response
from ..models.serializers.webpage import NewDeploymentSerializer
from ..models.serializers.clients import RabbitMQInstanceSerializer
from ..models.serializers.clients import RabbitMQInstanceSerializer, NewDeploymentSerializer
from .. import models
LOGGER = logging.getLogger(__name__)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment