2019-07-01 11:30:18 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
|
|
|
|
|
|
|
from rest_framework import serializers
|
2019-07-11 10:12:14 +00:00
|
|
|
from django.utils.translation import ugettext_lazy as _
|
2019-07-01 11:30:18 +00:00
|
|
|
|
2022-09-15 02:46:57 +00:00
|
|
|
from assets.models import Node, Asset, Platform, Account
|
2022-09-07 09:35:23 +00:00
|
|
|
from perms.serializers.permission import ActionsField
|
2019-07-01 11:30:18 +00:00
|
|
|
|
|
|
|
__all__ = [
|
2019-08-28 03:43:55 +00:00
|
|
|
'NodeGrantedSerializer',
|
|
|
|
'AssetGrantedSerializer',
|
2022-08-17 03:54:18 +00:00
|
|
|
'ActionsSerializer',
|
2022-09-15 02:46:57 +00:00
|
|
|
'AccountsGrantedSerializer'
|
2019-07-01 11:30:18 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
|
2020-10-22 10:13:14 +00:00
|
|
|
class AssetGrantedSerializer(serializers.ModelSerializer):
|
2022-09-15 02:46:57 +00:00
|
|
|
""" 被授权资产的数据结构 """
|
2021-04-07 10:20:54 +00:00
|
|
|
platform = serializers.SlugRelatedField(
|
|
|
|
slug_field='name', queryset=Platform.objects.all(), label=_("Platform")
|
|
|
|
)
|
2020-10-22 10:13:14 +00:00
|
|
|
|
2020-10-22 09:05:47 +00:00
|
|
|
class Meta:
|
2020-10-22 10:13:14 +00:00
|
|
|
model = Asset
|
|
|
|
only_fields = [
|
2022-09-21 03:17:14 +00:00
|
|
|
"id", "name", "address", "protocols", 'domain',
|
2020-10-22 10:13:14 +00:00
|
|
|
"platform", "comment", "org_id", "is_active"
|
|
|
|
]
|
|
|
|
fields = only_fields + ['org_name']
|
2020-10-22 09:05:47 +00:00
|
|
|
read_only_fields = fields
|
|
|
|
|
|
|
|
|
2020-10-22 10:13:14 +00:00
|
|
|
class NodeGrantedSerializer(serializers.ModelSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = Node
|
|
|
|
fields = [
|
|
|
|
'id', 'name', 'key', 'value', 'org_id', "assets_amount"
|
|
|
|
]
|
|
|
|
read_only_fields = fields
|
|
|
|
|
|
|
|
|
|
|
|
class ActionsSerializer(serializers.Serializer):
|
|
|
|
actions = ActionsField(read_only=True)
|
|
|
|
|
2022-09-15 02:46:57 +00:00
|
|
|
|
|
|
|
class AccountsGrantedSerializer(serializers.ModelSerializer):
|
|
|
|
""" 授权的账号序列类 """
|
|
|
|
|
|
|
|
# Todo: 添加前端登录逻辑中需要的一些字段,比如:是否需要手动输入密码
|
|
|
|
# need_manual = serializers.BooleanField(label=_('Need manual input'))
|
2022-09-28 10:40:33 +00:00
|
|
|
actions = ActionsField(read_only=True)
|
2022-09-15 02:46:57 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Account
|
2022-09-28 10:40:33 +00:00
|
|
|
fields = ['id', 'name', 'username', 'actions']
|
2022-09-15 02:46:57 +00:00
|
|
|
read_only_fields = fields
|