2018-02-07 15:25:15 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
2019-05-21 08:24:01 +00:00
|
|
|
from django.utils.translation import ugettext_lazy as _
|
2018-02-07 15:25:15 +00:00
|
|
|
from rest_framework import serializers
|
2018-03-27 10:34:41 +00:00
|
|
|
|
2018-02-09 07:24:44 +00:00
|
|
|
from ..models import Node, AdminUser
|
2019-08-21 12:27:21 +00:00
|
|
|
from orgs.mixins.serializers import BulkOrgResourceModelSerializer
|
2018-02-07 15:25:15 +00:00
|
|
|
|
2019-07-08 07:35:20 +00:00
|
|
|
from .base import AuthSerializer, AuthSerializerMixin
|
2018-03-27 10:34:41 +00:00
|
|
|
|
2018-02-07 15:25:15 +00:00
|
|
|
|
2019-07-08 07:35:20 +00:00
|
|
|
class AdminUserSerializer(AuthSerializerMixin, BulkOrgResourceModelSerializer):
|
2018-02-07 15:25:15 +00:00
|
|
|
"""
|
|
|
|
管理用户
|
|
|
|
"""
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = AdminUser
|
2021-04-29 11:10:45 +00:00
|
|
|
fields_mini = ['id', 'name', 'username']
|
|
|
|
fields_write_only = ['password', 'private_key', 'public_key']
|
|
|
|
fields_small = fields_mini + fields_write_only + [
|
|
|
|
'date_created', 'date_updated',
|
|
|
|
'comment', 'created_by'
|
2019-05-21 08:24:01 +00:00
|
|
|
]
|
2021-04-29 11:10:45 +00:00
|
|
|
fields_fk = ['assets_amount']
|
|
|
|
fields = fields_small + fields_fk
|
2019-07-12 10:31:55 +00:00
|
|
|
read_only_fields = ['date_created', 'date_updated', 'created_by', 'assets_amount']
|
2019-05-21 08:24:01 +00:00
|
|
|
|
|
|
|
extra_kwargs = {
|
2021-03-15 10:51:21 +00:00
|
|
|
'username': {"required": True},
|
2019-06-25 06:32:25 +00:00
|
|
|
'password': {"write_only": True},
|
|
|
|
'private_key': {"write_only": True},
|
|
|
|
'public_key': {"write_only": True},
|
2019-06-24 06:23:29 +00:00
|
|
|
'assets_amount': {'label': _('Asset')},
|
2019-05-21 08:24:01 +00:00
|
|
|
}
|
2018-02-07 15:25:15 +00:00
|
|
|
|
|
|
|
|
2021-03-04 10:17:42 +00:00
|
|
|
class AdminUserDetailSerializer(AdminUserSerializer):
|
|
|
|
class Meta(AdminUserSerializer.Meta):
|
|
|
|
fields = AdminUserSerializer.Meta.fields + ['ssh_key_fingerprint']
|
|
|
|
|
|
|
|
|
2018-03-27 10:34:41 +00:00
|
|
|
class AdminUserAuthSerializer(AuthSerializer):
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = AdminUser
|
|
|
|
fields = ['password', 'private_key']
|
|
|
|
|
|
|
|
|
2018-02-09 07:24:44 +00:00
|
|
|
class ReplaceNodeAdminUserSerializer(serializers.ModelSerializer):
|
2018-02-07 15:25:15 +00:00
|
|
|
"""
|
|
|
|
管理用户更新关联到的集群
|
|
|
|
"""
|
2018-02-09 07:24:44 +00:00
|
|
|
nodes = serializers.PrimaryKeyRelatedField(
|
2019-10-18 07:05:45 +00:00
|
|
|
many=True, queryset=Node.objects
|
2018-02-07 15:25:15 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = AdminUser
|
2018-02-09 07:24:44 +00:00
|
|
|
fields = ['id', 'nodes']
|
2018-03-27 10:34:41 +00:00
|
|
|
|
|
|
|
|
2019-01-15 02:23:30 +00:00
|
|
|
class TaskIDSerializer(serializers.Serializer):
|
|
|
|
task = serializers.CharField(read_only=True)
|
2020-03-12 08:24:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
class AssetUserTaskSerializer(serializers.Serializer):
|
|
|
|
ACTION_CHOICES = (
|
|
|
|
('test', 'test'),
|
|
|
|
)
|
|
|
|
action = serializers.ChoiceField(choices=ACTION_CHOICES, write_only=True)
|
|
|
|
task = serializers.CharField(read_only=True)
|