perf: stash it

pull/8873/head
ibuler 2022-08-22 13:25:57 +08:00
parent 05f913ab18
commit dd0b8e988c
6 changed files with 30 additions and 11 deletions

View File

@ -17,11 +17,11 @@ class AssetPlatformViewSet(JMSModelViewSet):
'default': PlatformSerializer,
'categories': GroupedChoiceSerailizer
}
filterset_fields = ['name']
filterset_fields = ['name', 'category', 'type']
search_fields = ['name']
rbac_perms = {
'categories': 'assets.view_platform',
'type_constraints': 'assets-view_platform'
'type_constraints': 'assets.view_platform'
}
@action(methods=['GET'], detail=False)

View File

@ -13,4 +13,4 @@ class AssetsConfig(AppConfig):
def ready(self):
super().ready()
from . import signal_handlers
# from . import signal_handlers

View File

@ -6,7 +6,7 @@ from django.utils.translation import ugettext_lazy as _
from common.drf.serializers import JMSWritableNestedModelSerializer
from common.drf.fields import ChoiceDisplayField
from ..account import AccountSerializer
from ...models import Asset, Node, Platform, Protocol, Label, Domain, Account
from ...models import Asset, Node, Platform, Protocol, Label, Domain
from ...const import Category, AllTypes
__all__ = [

View File

@ -12,7 +12,7 @@ sys.path.insert(0, APPS_DIR)
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "jumpserver.settings")
django.setup()
from resources.assets import AssetsGenerator, NodesGenerator, SystemUsersGenerator, AdminUsersGenerator
from resources.assets import AssetsGenerator, NodesGenerator
from resources.users import UserGroupGenerator, UserGenerator
from resources.perms import AssetPermissionGenerator
from resources.terminal import CommandGenerator, SessionGenerator
@ -21,8 +21,6 @@ from resources.terminal import CommandGenerator, SessionGenerator
resource_generator_mapper = {
'asset': AssetsGenerator,
'node': NodesGenerator,
'system_user': SystemUsersGenerator,
'admin_user': AdminUsersGenerator,
'user': UserGenerator,
'user_group': UserGroupGenerator,
'asset_permission': AssetPermissionGenerator,

View File

@ -5,6 +5,7 @@ import forgery_py
from .base import FakeDataGenerator
from assets.models import *
from assets.const import AllTypes
class NodesGenerator(FakeDataGenerator):
@ -17,13 +18,34 @@ class NodesGenerator(FakeDataGenerator):
parent.create_child()
class PlatformGenerator(FakeDataGenerator):
resource = 'platform'
category_type: dict
categories: list
def pre_generate(self):
self.category_type = dict(AllTypes.category_types())
self.categories = list(self.category_type.keys())
def do_generate(self, batch, batch_size):
platforms = []
for i in batch:
data = {
'name': forgery_py.name.company_name(),
'category': ''
}
platforms.append(Platform(**data))
Platform.objects.bulk_create(platforms, ignore_conflicts=True)
class AssetsGenerator(FakeDataGenerator):
resource = 'asset'
admin_user_ids: list
node_ids: list
platform_ids: list
def pre_generate(self):
self.node_ids = list(Node.objects.all().values_list('id', flat=True))
self.platform_ids = list(Platform.objects.all().values_list('id', flat=True))
def set_assets_nodes(self, assets):
for asset in assets:
@ -39,8 +61,8 @@ class AssetsGenerator(FakeDataGenerator):
hostname = f'{hostname}-{ip}'
data = dict(
ip=ip,
hostname=hostname,
admin_user_id=choice(self.admin_user_ids),
name=hostname,
platform_id=choice(self.platform_ids),
created_by='Fake',
org_id=self.org.id
)

View File

@ -4,7 +4,6 @@ import forgery_py
from .base import FakeDataGenerator
from users.models import *
from orgs.models import OrganizationMember
class UserGroupGenerator(FakeDataGenerator):