mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-09-08 10:49:08 +00:00
pref: 修改 applet host deploy
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import os.path
|
||||
import shutil
|
||||
import zipfile
|
||||
import yaml
|
||||
import os.path
|
||||
|
||||
from django.core.files.storage import default_storage
|
||||
from rest_framework import viewsets
|
||||
@@ -9,12 +9,16 @@ from rest_framework.decorators import action
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.serializers import ValidationError
|
||||
|
||||
from terminal import serializers, models
|
||||
from terminal import serializers
|
||||
from terminal.models import AppletPublication, Applet
|
||||
from terminal.serializers import AppletUploadSerializer
|
||||
|
||||
|
||||
__all__ = ['AppletViewSet', 'AppletPublicationViewSet']
|
||||
|
||||
|
||||
class AppletViewSet(viewsets.ModelViewSet):
|
||||
queryset = models.Applet.objects.all()
|
||||
queryset = Applet.objects.all()
|
||||
serializer_class = serializers.AppletSerializer
|
||||
rbac_perms = {
|
||||
'upload': 'terminal.add_applet',
|
||||
@@ -67,7 +71,7 @@ class AppletViewSet(viewsets.ModelViewSet):
|
||||
name = manifest['name']
|
||||
update = request.query_params.get('update')
|
||||
|
||||
instance = models.Applet.objects.filter(name=name).first()
|
||||
instance = Applet.objects.filter(name=name).first()
|
||||
if instance and not update:
|
||||
return Response({'error': 'Applet already exists: {}'.format(name)}, status=400)
|
||||
|
||||
@@ -82,5 +86,5 @@ class AppletViewSet(viewsets.ModelViewSet):
|
||||
|
||||
|
||||
class AppletPublicationViewSet(viewsets.ModelViewSet):
|
||||
queryset = models.AppletPublication.objects.all()
|
||||
queryset = AppletPublication.objects.all()
|
||||
serializer_class = serializers.AppletPublicationSerializer
|
||||
|
@@ -1,23 +1,35 @@
|
||||
from rest_framework import viewsets
|
||||
from rest_framework.decorators import action
|
||||
from rest_framework.response import Response
|
||||
|
||||
from orgs.utils import tmp_to_builtin_org
|
||||
from terminal import serializers, models
|
||||
from terminal import serializers
|
||||
from terminal.models import AppletHost, Applet
|
||||
from terminal.tasks import run_applet_host_deployment
|
||||
|
||||
__all__ = ['AppletHostViewSet', 'AppletHostDeploymentViewSet']
|
||||
__all__ = ['AppletHostViewSet']
|
||||
|
||||
|
||||
class AppletHostViewSet(viewsets.ModelViewSet):
|
||||
serializer_class = serializers.AppletHostSerializer
|
||||
|
||||
def get_queryset(self):
|
||||
return models.AppletHost.objects.all()
|
||||
return AppletHost.objects.all()
|
||||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
with tmp_to_builtin_org(system=1):
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
|
||||
@action(methods=['post'], detail=True)
|
||||
def deploy(self, request):
|
||||
from terminal.automations.deploy_applet_host.manager import DeployAppletHostManager
|
||||
manager = DeployAppletHostManager(self)
|
||||
manager.run()
|
||||
|
||||
class AppletHostDeploymentViewSet(viewsets.ModelViewSet):
|
||||
queryset = models.AppletHostDeployment.objects.all()
|
||||
serializer_class = serializers.AppletHostDeploymentSerializer
|
||||
@action(methods=['get'], detail=True, url_path='')
|
||||
def not_published_applets(self, request, *args, **kwargs):
|
||||
instance = self.get_object()
|
||||
applets = Applet.objects.exclude(id__in=instance.applets.all())
|
||||
serializer = serializers.AppletSerializer(applets, many=True)
|
||||
return Response(serializer.data)
|
||||
|
||||
|
Reference in New Issue
Block a user