mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-09-08 18:59:47 +00:00
feat: 修改 DBPortMapper 异常处理问题; DBListenPort API 迁移至 terminal app 中
This commit is contained in:
@@ -8,3 +8,4 @@ from .storage import *
|
||||
from .status import *
|
||||
from .sharing import *
|
||||
from .endpoint import *
|
||||
from .db_listen_port import *
|
||||
|
36
apps/terminal/api/db_listen_port.py
Normal file
36
apps/terminal/api/db_listen_port.py
Normal file
@@ -0,0 +1,36 @@
|
||||
# coding: utf-8
|
||||
#
|
||||
from rest_framework import status
|
||||
from rest_framework.decorators import action
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.viewsets import GenericViewSet
|
||||
|
||||
from ..utils import db_port_manager, DBPortManager
|
||||
from applications import serializers
|
||||
|
||||
|
||||
db_port_manager: DBPortManager
|
||||
|
||||
|
||||
__all__ = ['DBListenPortViewSet']
|
||||
|
||||
|
||||
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=['get'], detail=False, url_path='db-info')
|
||||
def db_info(self, request, *args, **kwargs):
|
||||
port = request.query_params.get("port")
|
||||
db = db_port_manager.get_db_by_port(port)
|
||||
serializer = serializers.AppSerializer(instance=db)
|
||||
return Response(data=serializer.data, status=status.HTTP_200_OK)
|
Reference in New Issue
Block a user