From 9b2acfe4a4524f5d9192d1cdfb5a21d69f8f9ca4 Mon Sep 17 00:00:00 2001 From: ibuler Date: Thu, 15 Sep 2022 21:20:56 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E5=B9=B3=E5=8F=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/assets/api/asset/network.py | 8 ++++---- apps/assets/const.py | 20 +++++++++---------- .../migrations/0096_auto_20220426_1550.py | 2 +- .../migrations/0099_auto_20220711_1409.py | 4 ++-- .../migrations/0106_auto_20220819_1523.py | 2 +- apps/assets/models/asset/__init__.py | 2 +- .../models/asset/{networking.py => device.py} | 3 +-- apps/assets/models/base.py | 2 +- apps/assets/serializers/account/__init__.py | 4 ++-- .../{account_history.py => history.py} | 0 .../{account_template.py => template.py} | 3 ++- apps/assets/serializers/asset/__init__.py | 2 +- apps/assets/serializers/asset/category.py | 4 ++-- .../asset/{networking.py => device.py} | 4 ++-- apps/assets/serializers/platform.py | 3 +++ apps/assets/urls/api_urls.py | 4 ++-- 16 files changed, 35 insertions(+), 32 deletions(-) rename apps/assets/models/asset/{networking.py => device.py} (59%) rename apps/assets/serializers/account/{account_history.py => history.py} (100%) rename apps/assets/serializers/account/{account_template.py => template.py} (92%) rename apps/assets/serializers/asset/{networking.py => device.py} (71%) diff --git a/apps/assets/api/asset/network.py b/apps/assets/api/asset/network.py index 608a70d1a..e64f69e1f 100644 --- a/apps/assets/api/asset/network.py +++ b/apps/assets/api/asset/network.py @@ -1,13 +1,13 @@ from assets.serializers import HostSerializer -from assets.models import Networking +from assets.models import Device from .asset import AssetViewSet -__all__ = ['NetworkViewSet'] +__all__ = ['DeviceViewSet'] -class NetworkViewSet(AssetViewSet): - model = Networking +class DeviceViewSet(AssetViewSet): + model = Device def get_serializer_classes(self): serializer_classes = super().get_serializer_classes() diff --git a/apps/assets/const.py b/apps/assets/const.py index 5a46d8d31..9c5603052 100644 --- a/apps/assets/const.py +++ b/apps/assets/const.py @@ -6,7 +6,7 @@ from common.tree import TreeNode __all__ = [ - 'Category', 'HostTypes', 'NetworkingTypes', 'DatabaseTypes', + 'Category', 'HostTypes', 'DeviceTypes', 'DatabaseTypes', 'WebTypes', 'CloudTypes', 'Protocol', 'AllTypes', ] @@ -17,7 +17,7 @@ class PlatformMixin: return { 'domain_enabled': False, 'su_enabled': False, - 'vendor_enabled': False, + 'brand_enabled': False, 'ping_enabled': False, 'gather_facts_enabled': False, 'change_password_enabled': False, @@ -30,9 +30,9 @@ class PlatformMixin: class Category(PlatformMixin, ChoicesMixin, models.TextChoices): HOST = 'host', _('Host') - NETWORKING = 'networking', _("NetworkDevice") + DEVICE = 'device', _("Device") DATABASE = 'database', _("Database") - CLOUD = 'cloud', _("Clouding") + CLOUD = 'cloud', _("Cloud service") WEB = 'web', _("Web") @classmethod @@ -49,7 +49,7 @@ class Category(PlatformMixin, ChoicesMixin, models.TextChoices): 'gather_accounts_enabled': True, 'gather_accounts_method': 'gather_accounts_posix', '_protocols': ['ssh', 'telnet'], }, - cls.NETWORKING: { + cls.DEVICE: { 'domain_enabled': True, 'brand_enabled': True, 'brands': [ @@ -108,7 +108,7 @@ class HostTypes(PlatformMixin, ChoicesMixin, models.TextChoices): LINUX = 'linux', 'Linux' WINDOWS = 'windows', 'Windows' UNIX = 'unix', 'Unix' - OTHER_HOST = 'other_host', _("Other host") + OTHER_HOST = 'other', _("Other") @classmethod def platform_constraints(cls): @@ -131,7 +131,7 @@ class HostTypes(PlatformMixin, ChoicesMixin, models.TextChoices): } -class NetworkingTypes(PlatformMixin, ChoicesMixin, models.TextChoices): +class DeviceTypes(PlatformMixin, ChoicesMixin, models.TextChoices): GENERAL = 'general', _("General device") SWITCH = 'switch', _("Switch") ROUTER = 'router', _("Router") @@ -163,7 +163,7 @@ class DatabaseTypes(PlatformMixin, ChoicesMixin, models.TextChoices): class WebTypes(PlatformMixin, ChoicesMixin, models.TextChoices): - WEBSITE = 'website', _('General Website') + WEBSITE = 'website', _('General website') class CloudTypes(PlatformMixin, ChoicesMixin, models.TextChoices): @@ -181,7 +181,7 @@ class CloudTypes(PlatformMixin, ChoicesMixin, models.TextChoices): class AllTypes(ChoicesMixin, metaclass=IncludesTextChoicesMeta): choices: list includes = [ - HostTypes, NetworkingTypes, DatabaseTypes, + HostTypes, DeviceTypes, DatabaseTypes, WebTypes, CloudTypes ] @@ -210,7 +210,7 @@ class AllTypes(ChoicesMixin, metaclass=IncludesTextChoicesMeta): def category_types(cls): return ( (Category.HOST, HostTypes), - (Category.NETWORKING, NetworkingTypes), + (Category.DEVICE, DeviceTypes), (Category.DATABASE, DatabaseTypes), (Category.WEB, WebTypes), (Category.CLOUD, CloudTypes) diff --git a/apps/assets/migrations/0096_auto_20220426_1550.py b/apps/assets/migrations/0096_auto_20220426_1550.py index bf7a93ac3..a0b1035d0 100644 --- a/apps/assets/migrations/0096_auto_20220426_1550.py +++ b/apps/assets/migrations/0096_auto_20220426_1550.py @@ -23,7 +23,7 @@ class Migration(migrations.Migration): bases=('assets.asset',), ), migrations.CreateModel( - name='Networking', + name='Device', fields=[ ('asset_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='assets.asset')), ], diff --git a/apps/assets/migrations/0099_auto_20220711_1409.py b/apps/assets/migrations/0099_auto_20220711_1409.py index af767c864..78495549c 100644 --- a/apps/assets/migrations/0099_auto_20220711_1409.py +++ b/apps/assets/migrations/0099_auto_20220711_1409.py @@ -31,7 +31,7 @@ class Migration(migrations.Migration): ('date_created', models.DateTimeField(blank=True, editable=False, verbose_name='Date created')), ('date_updated', models.DateTimeField(blank=True, editable=False, verbose_name='Date updated')), ('created_by', models.CharField(max_length=128, null=True, verbose_name='Created by')), - ('privileged', models.BooleanField(default=False, verbose_name='Privileged account')), + ('privileged', models.BooleanField(default=False, verbose_name='Privileged')), ('version', models.IntegerField(default=0, verbose_name='Version')), ('history_id', models.AutoField(primary_key=True, serialize=False)), ('history_date', models.DateTimeField(db_index=True)), @@ -64,7 +64,7 @@ class Migration(migrations.Migration): ('date_created', models.DateTimeField(auto_now_add=True, verbose_name='Date created')), ('date_updated', models.DateTimeField(auto_now=True, verbose_name='Date updated')), ('created_by', models.CharField(max_length=128, null=True, verbose_name='Created by')), - ('privileged', models.BooleanField(default=False, verbose_name='Privileged account')), + ('privileged', models.BooleanField(default=False, verbose_name='Privileged')), ('version', models.IntegerField(default=0, verbose_name='Version')), ('asset', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='accounts', to='assets.asset', verbose_name='Asset')), ('su_from', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='su_to', to='assets.account', verbose_name='Su from')), diff --git a/apps/assets/migrations/0106_auto_20220819_1523.py b/apps/assets/migrations/0106_auto_20220819_1523.py index c77fdb09b..81c4e29a9 100644 --- a/apps/assets/migrations/0106_auto_20220819_1523.py +++ b/apps/assets/migrations/0106_auto_20220819_1523.py @@ -28,7 +28,7 @@ class Migration(migrations.Migration): ('date_updated', models.DateTimeField(auto_now=True, verbose_name='Date updated')), ('created_by', models.CharField(max_length=128, null=True, verbose_name='Created by')), ('token', common.db.fields.EncryptTextField(blank=True, null=True, verbose_name='Token')), - ('privileged', models.BooleanField(default=False, verbose_name='Privileged account')), + ('privileged', models.BooleanField(default=False, verbose_name='Privileged')), ], options={ 'verbose_name': 'Account template', diff --git a/apps/assets/models/asset/__init__.py b/apps/assets/models/asset/__init__.py index 914a440ba..793df7455 100644 --- a/apps/assets/models/asset/__init__.py +++ b/apps/assets/models/asset/__init__.py @@ -1,6 +1,6 @@ from .common import * from .host import * from .database import * -from .networking import * +from .device import * from .web import * from .cloud import * diff --git a/apps/assets/models/asset/networking.py b/apps/assets/models/asset/device.py similarity index 59% rename from apps/assets/models/asset/networking.py rename to apps/assets/models/asset/device.py index 48d73a4d9..24c1d2bd4 100644 --- a/apps/assets/models/asset/networking.py +++ b/apps/assets/models/asset/device.py @@ -2,6 +2,5 @@ from .common import Asset -class Networking(Asset): - +class Device(Asset): pass diff --git a/apps/assets/models/base.py b/apps/assets/models/base.py index ce7b99da3..a18c7ae5e 100644 --- a/apps/assets/models/base.py +++ b/apps/assets/models/base.py @@ -62,7 +62,7 @@ class BaseAccount(OrgModelMixin): private_key = fields.EncryptTextField(blank=True, null=True, verbose_name=_('SSH private key')) public_key = fields.EncryptTextField(blank=True, null=True, verbose_name=_('SSH public key')) token = fields.EncryptTextField(blank=True, null=True, verbose_name=_('Token')) - privileged = models.BooleanField(verbose_name=_("Privileged account"), default=False) + privileged = models.BooleanField(verbose_name=_("Privileged"), default=False) comment = models.TextField(blank=True, verbose_name=_('Comment')) date_created = models.DateTimeField(auto_now_add=True, verbose_name=_("Date created")) date_updated = models.DateTimeField(auto_now=True, verbose_name=_("Date updated")) diff --git a/apps/assets/serializers/account/__init__.py b/apps/assets/serializers/account/__init__.py index 7ef87134a..70c013231 100644 --- a/apps/assets/serializers/account/__init__.py +++ b/apps/assets/serializers/account/__init__.py @@ -1,3 +1,3 @@ from .account import * -from .account_history import * -from .account_template import * +from .history import * +from .template import * diff --git a/apps/assets/serializers/account/account_history.py b/apps/assets/serializers/account/history.py similarity index 100% rename from apps/assets/serializers/account/account_history.py rename to apps/assets/serializers/account/history.py diff --git a/apps/assets/serializers/account/account_template.py b/apps/assets/serializers/account/template.py similarity index 92% rename from apps/assets/serializers/account/account_template.py rename to apps/assets/serializers/account/template.py index 5fe53c26c..1df7ea65a 100644 --- a/apps/assets/serializers/account/account_template.py +++ b/apps/assets/serializers/account/template.py @@ -10,12 +10,13 @@ from .common import AccountFieldsSerializerMixin class AccountTemplateSerializer(AuthValidateMixin, BulkOrgResourceModelSerializer): class Meta: model = AccountTemplate - fields_mini = ['id', 'privileged', 'username'] + fields_mini = ['id', 'name', 'username', 'privileged'] fields_write_only = AccountFieldsSerializerMixin.Meta.fields_write_only fields_other = AccountFieldsSerializerMixin.Meta.fields_other fields = fields_mini + fields_write_only + fields_other extra_kwargs = { 'username': {'required': True}, + 'name': {'required': True}, 'private_key': {'write_only': True}, 'public_key': {'write_only': True}, } diff --git a/apps/assets/serializers/asset/__init__.py b/apps/assets/serializers/asset/__init__.py index 93d35b736..12f1eb66c 100644 --- a/apps/assets/serializers/asset/__init__.py +++ b/apps/assets/serializers/asset/__init__.py @@ -1,6 +1,6 @@ from .common import * from .host import * from .database import * -from .networking import * +from .device import * from .cloud import * from .web import * diff --git a/apps/assets/serializers/asset/category.py b/apps/assets/serializers/asset/category.py index 1b69dc79d..8cf62d99d 100644 --- a/apps/assets/serializers/asset/category.py +++ b/apps/assets/serializers/asset/category.py @@ -1,4 +1,4 @@ -from assets.models import Networking +from assets.models import Device from .common import AssetSerializer __all__ = ['NetworkingSerializer'] @@ -6,4 +6,4 @@ __all__ = ['NetworkingSerializer'] class NetworkingSerializer(AssetSerializer): class Meta(AssetSerializer.Meta): - model = Networking + model = Device diff --git a/apps/assets/serializers/asset/networking.py b/apps/assets/serializers/asset/device.py similarity index 71% rename from apps/assets/serializers/asset/networking.py rename to apps/assets/serializers/asset/device.py index aff838bd5..1c6e59f9f 100644 --- a/apps/assets/serializers/asset/networking.py +++ b/apps/assets/serializers/asset/device.py @@ -1,5 +1,5 @@ -from assets.models import Networking +from assets.models import Device from .common import AssetSerializer __all__ = ['NetworkingSerializer'] @@ -7,4 +7,4 @@ __all__ = ['NetworkingSerializer'] class NetworkingSerializer(AssetSerializer): class Meta(AssetSerializer.Meta): - model = Networking + model = Device diff --git a/apps/assets/serializers/platform.py b/apps/assets/serializers/platform.py index 9c94a45f2..785cf6c39 100644 --- a/apps/assets/serializers/platform.py +++ b/apps/assets/serializers/platform.py @@ -38,6 +38,8 @@ class PlatformAutomationSerializer(serializers.ModelSerializer): 'gather_accounts_enabled', 'gather_accounts_method', ] extra_kwargs = { + 'ping_enabled': {'label': '启用资产探测'}, + 'ping_method': {'label': '探测方式'}, 'gather_facts_enabled': {'label': '启用收集信息'}, 'gather_facts_method': {'label': '收集信息方式'}, 'verify_account_enabled': {'label': '启用校验账号'}, @@ -82,6 +84,7 @@ class PlatformSerializer(JMSWritableNestedModelSerializer): ] extra_kwargs = { 'su_enabled': {'label': '启用切换账号'}, + 'protocols_enabled': {'label': '启用协议'}, 'domain_enabled': {'label': "启用网域"}, 'domain_default': {'label': "默认网域"}, } diff --git a/apps/assets/urls/api_urls.py b/apps/assets/urls/api_urls.py index 6a233cf07..04df314f9 100644 --- a/apps/assets/urls/api_urls.py +++ b/apps/assets/urls/api_urls.py @@ -9,10 +9,10 @@ app_name = 'assets' router = BulkRouter() router.register(r'assets', api.AssetViewSet, 'asset') router.register(r'hosts', api.HostViewSet, 'host') +router.register(r'devices', api.DeviceViewSet, 'device') router.register(r'databases', api.DatabaseViewSet, 'database') -router.register(r'web', api.WebViewSet, 'web') +router.register(r'webs', api.WebViewSet, 'web') router.register(r'clouds', api.CloudViewSet, 'cloud') -router.register(r'networks', api.NetworkViewSet, 'network') router.register(r'accounts', api.AccountViewSet, 'account') router.register(r'account-templates', api.AccountTemplateViewSet, 'account-template') router.register(r'account-secrets', api.AccountSecretsViewSet, 'account-secret')