jumpserver/apps/terminal/api/applet/host.py

36 lines
1.2 KiB
Python
Raw Normal View History

2022-10-25 04:57:34 +00:00
from rest_framework import viewsets
2022-10-28 10:19:44 +00:00
from rest_framework.decorators import action
from rest_framework.response import Response
2022-10-25 04:57:34 +00:00
2022-10-27 08:26:15 +00:00
from orgs.utils import tmp_to_builtin_org
2022-10-28 10:19:44 +00:00
from terminal import serializers
from terminal.models import AppletHost, Applet
from terminal.tasks import run_applet_host_deployment
2022-10-25 04:57:34 +00:00
2022-10-28 10:19:44 +00:00
__all__ = ['AppletHostViewSet']
2022-10-25 04:57:34 +00:00
class AppletHostViewSet(viewsets.ModelViewSet):
serializer_class = serializers.AppletHostSerializer
2022-10-27 08:26:15 +00:00
def get_queryset(self):
2022-10-28 10:19:44 +00:00
return AppletHost.objects.all()
2022-10-27 08:26:15 +00:00
def dispatch(self, request, *args, **kwargs):
with tmp_to_builtin_org(system=1):
return super().dispatch(request, *args, **kwargs)
2022-10-25 11:31:13 +00:00
2022-10-28 10:19:44 +00:00
@action(methods=['post'], detail=True)
def deploy(self, request):
from terminal.automations.deploy_applet_host.manager import DeployAppletHostManager
manager = DeployAppletHostManager(self)
manager.run()
@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)
2022-10-25 04:57:34 +00:00