From c7ce53563054b71af3358b7cbe9cbaae575ae47c Mon Sep 17 00:00:00 2001 From: fit2bot <68588906+fit2bot@users.noreply.github.com> Date: Mon, 6 Feb 2023 18:30:17 +0800 Subject: [PATCH] perf: account seri type category (#9445) Co-authored-by: feng <1304903146@qq.com> --- apps/accounts/automations/gather_accounts/manager.py | 2 +- apps/accounts/serializers/account/account.py | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/apps/accounts/automations/gather_accounts/manager.py b/apps/accounts/automations/gather_accounts/manager.py index efbe1a965..de6db61af 100644 --- a/apps/accounts/automations/gather_accounts/manager.py +++ b/apps/accounts/automations/gather_accounts/manager.py @@ -53,7 +53,7 @@ class GatherAccountsManager(AccountBasePlaybookManager): info = result.get('debug', {}).get('res', {}).get('info', {}) asset = self.host_asset_mapper.get(host) if asset and info: - result = self.filter_success_result(host, info) + result = self.filter_success_result(asset.type, info) self.bulk_create_accounts(asset, result) else: logger.error("Not found info".format(host)) diff --git a/apps/accounts/serializers/account/account.py b/apps/accounts/serializers/account/account.py index afcf5af37..454708265 100644 --- a/apps/accounts/serializers/account/account.py +++ b/apps/accounts/serializers/account/account.py @@ -5,6 +5,7 @@ from assets.models import Asset from accounts.const import SecretType, Source from accounts.models import Account, AccountTemplate from accounts.tasks import push_accounts_to_assets +from assets.const import Category, AllTypes from common.serializers.fields import ObjectRelatedField, LabeledChoiceField from common.serializers import SecretReadableMixin, BulkModelSerializer from .base import BaseAccountSerializer @@ -60,11 +61,12 @@ class AccountSerializerCreateMixin( class AccountAssetSerializer(serializers.ModelSerializer): platform = ObjectRelatedField(read_only=True) - category = serializers.CharField(source='platform.category', read_only=True) + category = LabeledChoiceField(choices=Category.choices, read_only=True, label=_('Category')) + type = LabeledChoiceField(choices=AllTypes.choices(), read_only=True, label=_('Type')) class Meta: model = Asset - fields = ['id', 'name', 'address', 'category', 'platform'] + fields = ['id', 'name', 'address', 'type', 'category', 'platform'] def to_internal_value(self, data): if isinstance(data, dict):