mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-09-15 14:58:42 +00:00
feat: 修改 DBPortMapper 异常处理问题; DBListenPort API 迁移至 terminal app 中
This commit is contained in:
@@ -1,19 +1,16 @@
|
||||
# coding: utf-8
|
||||
#
|
||||
from orgs.mixins.api import OrgBulkModelViewSet
|
||||
from rest_framework import status
|
||||
from rest_framework.decorators import action
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.viewsets import GenericViewSet
|
||||
|
||||
|
||||
from common.tree import TreeNodeSerializer
|
||||
from common.mixins.api import SuggestionMixin
|
||||
from ..utils import db_port_manager
|
||||
from .. import serializers
|
||||
from ..models import Application
|
||||
|
||||
__all__ = ['ApplicationViewSet', 'DBListenPortViewSet']
|
||||
__all__ = ['ApplicationViewSet']
|
||||
|
||||
|
||||
class ApplicationViewSet(SuggestionMixin, OrgBulkModelViewSet):
|
||||
@@ -41,30 +38,3 @@ class ApplicationViewSet(SuggestionMixin, OrgBulkModelViewSet):
|
||||
tree_nodes = Application.create_tree_nodes(queryset, show_count=show_count)
|
||||
serializer = self.get_serializer(tree_nodes, many=True)
|
||||
return Response(serializer.data)
|
||||
|
||||
|
||||
class DBListenPortViewSet(GenericViewSet):
|
||||
rbac_perms = {
|
||||
'GET': 'applications.view_application',
|
||||
'list': 'applications.view_application',
|
||||
'db_info': 'applications.view_application',
|
||||
}
|
||||
|
||||
http_method_names = ['get', 'post']
|
||||
|
||||
def list(self, request, *args, **kwargs):
|
||||
ports = db_port_manager.get_already_use_ports()
|
||||
return Response(data=ports, status=status.HTTP_200_OK)
|
||||
|
||||
@action(methods=['post'], detail=False, url_path='db-info')
|
||||
def db_info(self, request, *args, **kwargs):
|
||||
port = request.data.get("port")
|
||||
db, msg = db_port_manager.get_db_by_port(port)
|
||||
if db:
|
||||
serializer = serializers.AppSerializer(instance=db)
|
||||
data = serializer.data
|
||||
_status = status.HTTP_200_OK
|
||||
else:
|
||||
data = {'error': msg}
|
||||
_status = status.HTTP_404_NOT_FOUND
|
||||
return Response(data=data, status=_status)
|
||||
|
Reference in New Issue
Block a user