mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-09-20 19:09:02 +00:00
pref: 修改 applet host
This commit is contained in:
@@ -13,9 +13,9 @@ from rest_framework.response import Response
|
||||
from rest_framework.serializers import ValidationError
|
||||
|
||||
from common.utils import is_uuid
|
||||
from common.drf.serializers import FileSerializer
|
||||
from terminal import serializers
|
||||
from terminal.models import AppletPublication, Applet
|
||||
from terminal.serializers import AppletUploadSerializer
|
||||
|
||||
|
||||
__all__ = ['AppletViewSet', 'AppletPublicationViewSet']
|
||||
@@ -59,7 +59,7 @@ class DownloadUploadMixin:
|
||||
raise ValidationError({'error': 'Missing name in manifest.yml'})
|
||||
return manifest, tmp_dir
|
||||
|
||||
@action(detail=False, methods=['post'], serializer_class=AppletUploadSerializer)
|
||||
@action(detail=False, methods=['post'], serializer_class=FileSerializer)
|
||||
def upload(self, request, *args, **kwargs):
|
||||
manifest, tmp_dir = self.extract_and_check_file(request)
|
||||
name = manifest['name']
|
||||
|
@@ -2,6 +2,8 @@ from rest_framework import viewsets
|
||||
from rest_framework.decorators import action
|
||||
from rest_framework.response import Response
|
||||
|
||||
from common.drf.api import JMSModelViewSet
|
||||
from orgs.utils import tmp_to_builtin_org
|
||||
from terminal import serializers
|
||||
from terminal.models import AppletHost, Applet, AppletHostDeployment
|
||||
from terminal.tasks import run_applet_host_deployment
|
||||
@@ -10,26 +12,34 @@ from terminal.tasks import run_applet_host_deployment
|
||||
__all__ = ['AppletHostViewSet', 'AppletHostDeploymentViewSet']
|
||||
|
||||
|
||||
class AppletHostViewSet(viewsets.ModelViewSet):
|
||||
class AppletHostViewSet(JMSModelViewSet):
|
||||
serializer_class = serializers.AppletHostSerializer
|
||||
queryset = AppletHost.objects.all()
|
||||
rbac_perms = {
|
||||
'accounts': 'terminal.view_applethost',
|
||||
'reports': '*'
|
||||
}
|
||||
|
||||
@action(methods=['post'], detail=True)
|
||||
def report(self, request, *args, **kwargs):
|
||||
# TODO:
|
||||
# 1. 上报 安装的 Applets 每小时
|
||||
# 2. Host 和 Terminal 关联
|
||||
@action(methods=['post'], detail=True, serializer_class=serializers.AppletHostReportSerializer)
|
||||
def reports(self, request, *args, **kwargs):
|
||||
# 1. Host 和 Terminal 关联
|
||||
# 2. 上报 安装的 Applets 每小时
|
||||
instance = self.get_object()
|
||||
instance.sync()
|
||||
serializer = self.get_serializer(data=request.data)
|
||||
serializer.is_valid(raise_exception=True)
|
||||
|
||||
data = serializer.validated_data
|
||||
instance.check_terminal_binding(request)
|
||||
instance.check_applets_state(data['applets'])
|
||||
return Response({'msg': 'ok'})
|
||||
|
||||
@action(methods=['get'], detail=True)
|
||||
@action(methods=['get'], detail=True, serializer_class=serializers.AppletHostAccountSerializer)
|
||||
def accounts(self, request, *args, **kwargs):
|
||||
# TODO:
|
||||
# 1. 返回 host 上的所有用户, host 可以去创建和更新 每小时
|
||||
# 2. 密码长度最少 8 位,包含大小写字母和数字和特殊字符
|
||||
instance = self.get_object()
|
||||
return Response(instance.get_accounts())
|
||||
host = self.get_object()
|
||||
with tmp_to_builtin_org(system=1):
|
||||
accounts = host.accounts.all().filter(privileged=False)
|
||||
response = self.get_paginated_response_from_queryset(accounts)
|
||||
return response
|
||||
|
||||
|
||||
class AppletHostDeploymentViewSet(viewsets.ModelViewSet):
|
||||
|
Reference in New Issue
Block a user