feat: 修改 DBPortMapper 异常处理问题; DBListenPort API 迁移至 terminal app 中

This commit is contained in:
Jiangjie.Bai
2022-09-22 18:47:16 +08:00
parent 7a6ed91f62
commit c1c70849e9
14 changed files with 249 additions and 224 deletions

View File

@@ -8,3 +8,4 @@ from .storage import *
from .status import *
from .sharing import *
from .endpoint import *
from .db_listen_port import *

View 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)