mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-09-21 19:38:07 +00:00
perf: 优化支持 choices (#10151)
* perf: 支持自定义类型资产 * perf: 改名前 * perf: 优化支持 choices * perf: 优化自定义资产 * perf: 优化资产的详情 * perf: 修改完成自定义平台和资产 --------- Co-authored-by: ibuler <ibuler@qq.com> Co-authored-by: Jiangjie.Bai <bugatti_it@163.com>
This commit is contained in:
@@ -64,13 +64,7 @@ class DownloadUploadMixin:
|
||||
if instance and not update:
|
||||
return Response({'error': 'Applet already exists: {}'.format(name)}, status=400)
|
||||
|
||||
serializer = serializers.AppletSerializer(data=manifest, instance=instance)
|
||||
serializer.is_valid(raise_exception=True)
|
||||
save_to = default_storage.path('applets/{}'.format(name))
|
||||
if os.path.exists(save_to):
|
||||
shutil.rmtree(save_to)
|
||||
shutil.move(tmp_dir, save_to)
|
||||
serializer.save()
|
||||
applet, serializer = Applet.install_from_dir(tmp_dir)
|
||||
return Response(serializer.data, status=201)
|
||||
|
||||
@action(detail=True, methods=['get'])
|
||||
|
@@ -12,7 +12,6 @@ from rest_framework.serializers import ValidationError
|
||||
|
||||
from common.db.models import JMSBaseModel
|
||||
from common.utils import lazyproperty, get_logger
|
||||
from jumpserver.utils import has_valid_xpack_license
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
||||
@@ -91,24 +90,48 @@ class Applet(JMSBaseModel):
|
||||
return manifest
|
||||
|
||||
@classmethod
|
||||
def install_from_dir(cls, path):
|
||||
def load_platform_if_need(cls, d):
|
||||
from assets.serializers import PlatformSerializer
|
||||
|
||||
if not os.path.exists(os.path.join(d, 'platform.yml')):
|
||||
return
|
||||
try:
|
||||
with open(os.path.join(d, 'platform.yml')) as f:
|
||||
data = yaml.safe_load(f)
|
||||
except Exception as e:
|
||||
raise ValidationError({'error': _('Load platform.yml failed: {}').format(e)})
|
||||
|
||||
if data['category'] != 'custom':
|
||||
raise ValidationError({'error': _('Only support custom platform')})
|
||||
|
||||
try:
|
||||
tp = data['type']
|
||||
except KeyError:
|
||||
raise ValidationError({'error': _('Missing type in platform.yml')})
|
||||
|
||||
s = PlatformSerializer(data=data)
|
||||
s.add_type_choices(tp, tp)
|
||||
s.is_valid(raise_exception=True)
|
||||
s.save()
|
||||
|
||||
@classmethod
|
||||
def install_from_dir(cls, path, builtin=True):
|
||||
from terminal.serializers import AppletSerializer
|
||||
|
||||
manifest = cls.validate_pkg(path)
|
||||
name = manifest['name']
|
||||
if not has_valid_xpack_license() and name.lower() in ('navicat',):
|
||||
return
|
||||
|
||||
instance = cls.objects.filter(name=name).first()
|
||||
serializer = AppletSerializer(instance=instance, data=manifest)
|
||||
serializer.is_valid()
|
||||
serializer.save(builtin=True)
|
||||
pkg_path = default_storage.path('applets/{}'.format(name))
|
||||
serializer.save(builtin=builtin)
|
||||
|
||||
cls.load_platform_if_need(path)
|
||||
|
||||
pkg_path = default_storage.path('applets/{}'.format(name))
|
||||
if os.path.exists(pkg_path):
|
||||
shutil.rmtree(pkg_path)
|
||||
shutil.copytree(path, pkg_path)
|
||||
return instance
|
||||
return instance, serializer
|
||||
|
||||
def select_host_account(self):
|
||||
# 选择激活的发布机
|
||||
|
@@ -1,3 +1,5 @@
|
||||
import time
|
||||
import uuid
|
||||
from django.conf import settings
|
||||
from django.core.cache import cache
|
||||
from django.db import models
|
||||
@@ -139,6 +141,7 @@ class Terminal(StorageMixin, TerminalStatusMixin, JMSBaseModel):
|
||||
if self.user:
|
||||
setattr(self.user, SKIP_SIGNAL, True)
|
||||
self.user.delete()
|
||||
self.name = self.name + '_' + uuid.uuid4().hex[:8]
|
||||
self.user = None
|
||||
self.is_deleted = True
|
||||
self.save()
|
||||
|
Reference in New Issue
Block a user