2019-07-01 11:30:18 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
|
|
|
|
2019-07-11 10:12:14 +00:00
|
|
|
from django.utils.translation import ugettext_lazy as _
|
2022-11-15 02:43:21 +00:00
|
|
|
from rest_framework import serializers
|
2019-07-01 11:30:18 +00:00
|
|
|
|
2022-11-09 12:58:45 +00:00
|
|
|
from assets.const import Category, AllTypes
|
2023-01-16 11:02:09 +00:00
|
|
|
from assets.models import Node, Asset, Platform
|
|
|
|
from accounts.models import Account
|
2022-11-30 09:52:00 +00:00
|
|
|
from assets.serializers.asset.common import AssetProtocolsSerializer
|
2023-01-16 11:02:09 +00:00
|
|
|
from common.serializers.fields import ObjectRelatedField, LabeledChoiceField
|
2022-11-11 07:04:31 +00:00
|
|
|
from perms.serializers.permission import ActionChoicesField
|
2023-01-16 11:02:09 +00:00
|
|
|
from orgs.mixins.serializers import OrgResourceModelSerializerMixin
|
2019-07-01 11:30:18 +00:00
|
|
|
|
|
|
|
__all__ = [
|
2022-12-15 08:02:34 +00:00
|
|
|
'NodePermedSerializer', 'AssetPermedSerializer',
|
2022-11-24 09:04:27 +00:00
|
|
|
'AccountsPermedSerializer'
|
2019-07-01 11:30:18 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
|
2023-01-16 11:02:09 +00:00
|
|
|
class AssetPermedSerializer(OrgResourceModelSerializerMixin):
|
2022-09-15 02:46:57 +00:00
|
|
|
""" 被授权资产的数据结构 """
|
2022-11-16 07:07:35 +00:00
|
|
|
platform = ObjectRelatedField(required=False, queryset=Platform.objects, label=_('Platform'))
|
|
|
|
protocols = AssetProtocolsSerializer(many=True, required=False, label=_('Protocols'))
|
2022-11-09 12:58:45 +00:00
|
|
|
category = LabeledChoiceField(choices=Category.choices, read_only=True, label=_('Category'))
|
|
|
|
type = LabeledChoiceField(choices=AllTypes.choices(), read_only=True, label=_('Type'))
|
2023-01-16 11:02:09 +00:00
|
|
|
domain = ObjectRelatedField(required=False, queryset=Node.objects, label=_('Domain'))
|
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-12-15 08:02:34 +00:00
|
|
|
"id", "name", "address", 'domain', 'platform',
|
2022-11-09 12:58:45 +00:00
|
|
|
"comment", "org_id", "is_active",
|
2020-10-22 10:13:14 +00:00
|
|
|
]
|
2022-11-30 16:36:02 +00:00
|
|
|
fields = only_fields + ['protocols', 'category', 'type', 'specific'] + ['org_name']
|
2020-10-22 09:05:47 +00:00
|
|
|
read_only_fields = fields
|
|
|
|
|
|
|
|
|
2022-12-15 08:02:34 +00:00
|
|
|
class NodePermedSerializer(serializers.ModelSerializer):
|
2020-10-22 10:13:14 +00:00
|
|
|
class Meta:
|
|
|
|
model = Node
|
|
|
|
fields = [
|
|
|
|
'id', 'name', 'key', 'value', 'org_id', "assets_amount"
|
|
|
|
]
|
|
|
|
read_only_fields = fields
|
|
|
|
|
|
|
|
|
2022-11-16 03:29:02 +00:00
|
|
|
class AccountsPermedSerializer(serializers.ModelSerializer):
|
2022-11-11 07:04:31 +00:00
|
|
|
actions = ActionChoicesField(read_only=True)
|
2022-09-15 02:46:57 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Account
|
2022-12-15 08:02:34 +00:00
|
|
|
fields = [
|
|
|
|
'alias', 'name', 'username', 'has_username',
|
|
|
|
'has_secret', 'secret_type', 'actions'
|
|
|
|
]
|
2022-09-15 02:46:57 +00:00
|
|
|
read_only_fields = fields
|