mirror of https://github.com/jumpserver/jumpserver
perf: 添加 mariadb port (#7989)
* perf: 添加 mariadb port * perf: 优化 mariadb 树上天津更多信息 * perf: remove mixin Co-authored-by: ibuler <ibuler@qq.com>pull/7991/head
parent
cddff9fd19
commit
b8e6bc932b
|
@ -1,4 +1,3 @@
|
|||
from .application import *
|
||||
from .account import *
|
||||
from .mixin import *
|
||||
from .remote_app import *
|
||||
|
|
|
@ -145,7 +145,6 @@ class ApplicationTreeNodeMixin:
|
|||
pid, counts, show_empty=show_empty,
|
||||
show_count=show_count
|
||||
)
|
||||
|
||||
return tree_nodes
|
||||
|
||||
@classmethod
|
||||
|
@ -183,7 +182,7 @@ class ApplicationTreeNodeMixin:
|
|||
|
||||
def _attrs_to_tree(self):
|
||||
if self.category == const.AppCategory.db:
|
||||
return {'database': self.attrs.get('database')}
|
||||
return self.attrs
|
||||
return {}
|
||||
|
||||
def _as_tree_node(self, pid):
|
||||
|
|
|
@ -317,6 +317,7 @@ class Config(dict):
|
|||
'TERMINAL_MAGNUS_ENABLED': True,
|
||||
'TERMINAL_MAGNUS_HOST': lambda: urlparse(settings.SITE_URL).hostname,
|
||||
'TERMINAL_MAGNUS_MYSQL_PORT': 33060,
|
||||
'TERMINAL_MAGNUS_MARIADB_PORT': 33061,
|
||||
'TERMINAL_MAGNUS_POSTGRE_PORT': 54320,
|
||||
|
||||
# 安全配置
|
||||
|
|
|
@ -176,4 +176,5 @@ MAGNUS_ENABLED = CONFIG.MAGNUS_ENABLED
|
|||
TERMINAL_MAGNUS_HOST = CONFIG.TERMINAL_MAGNUS_HOST
|
||||
TERMINAL_MAGNUS_ENABLED = CONFIG.TERMINAL_MAGNUS_ENABLED
|
||||
TERMINAL_MAGNUS_MYSQL_PORT = CONFIG.TERMINAL_MAGNUS_MYSQL_PORT
|
||||
TERMINAL_MAGNUS_MARIADB_PORT = CONFIG.TERMINAL_MAGNUS_MARIADB_PORT
|
||||
TERMINAL_MAGNUS_POSTGRE_PORT = CONFIG.TERMINAL_MAGNUS_POSTGRE_PORT
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
from typing import Callable
|
||||
|
||||
from rest_framework.generics import ListAPIView
|
||||
from rest_framework.response import Response
|
||||
|
||||
from common.mixins.api import CommonApiMixin
|
||||
from common.tree import TreeNodeSerializer
|
||||
from applications.api.mixin import (
|
||||
SerializeApplicationToTreeNodeMixin
|
||||
)
|
||||
from perms import serializers
|
||||
from .mixin import AppRoleAdminMixin, AppRoleUserMixin
|
||||
from perms.tree.app import GrantedAppTreeUtil
|
||||
from perms.utils.application.user_permission import (
|
||||
get_user_granted_all_applications
|
||||
)
|
||||
from .mixin import AppRoleAdminMixin, AppRoleUserMixin
|
||||
|
||||
|
||||
__all__ = [
|
||||
|
@ -23,7 +23,7 @@ __all__ = [
|
|||
]
|
||||
|
||||
|
||||
class AllGrantedApplicationsMixin(CommonApiMixin, ListAPIView):
|
||||
class AllGrantedApplicationsApi(CommonApiMixin, ListAPIView):
|
||||
only_fields = serializers.AppGrantedSerializer.Meta.only_fields
|
||||
serializer_class = serializers.AppGrantedSerializer
|
||||
filterset_fields = {
|
||||
|
@ -41,28 +41,34 @@ class AllGrantedApplicationsMixin(CommonApiMixin, ListAPIView):
|
|||
return queryset.only(*self.only_fields)
|
||||
|
||||
|
||||
class UserAllGrantedApplicationsApi(AppRoleAdminMixin, AllGrantedApplicationsMixin):
|
||||
class UserAllGrantedApplicationsApi(AppRoleAdminMixin, AllGrantedApplicationsApi):
|
||||
pass
|
||||
|
||||
|
||||
class MyAllGrantedApplicationsApi(AppRoleUserMixin, AllGrantedApplicationsMixin):
|
||||
class MyAllGrantedApplicationsApi(AppRoleUserMixin, AllGrantedApplicationsApi):
|
||||
pass
|
||||
|
||||
|
||||
class ApplicationsAsTreeMixin(SerializeApplicationToTreeNodeMixin):
|
||||
class ApplicationsAsTreeMixin:
|
||||
"""
|
||||
将应用序列化成树的结构返回
|
||||
"""
|
||||
serializer_class = TreeNodeSerializer
|
||||
user: None
|
||||
filter_queryset: Callable
|
||||
get_queryset: Callable
|
||||
get_serializer: Callable
|
||||
|
||||
def list(self, request, *args, **kwargs):
|
||||
tree_id = request.query_params.get('tree_id', None)
|
||||
parent_info = request.query_params.get('parentInfo', None)
|
||||
queryset = self.filter_queryset(self.get_queryset())
|
||||
tree_nodes = self.serialize_applications_with_org(
|
||||
queryset, tree_id, parent_info, self.user
|
||||
)
|
||||
util = GrantedAppTreeUtil()
|
||||
|
||||
if not tree_id:
|
||||
tree_nodes = util.create_tree_nodes(queryset)
|
||||
else:
|
||||
tree_nodes = util.get_children_nodes(tree_id, parent_info, self.user)
|
||||
serializer = self.get_serializer(tree_nodes, many=True)
|
||||
return Response(data=serializer.data)
|
||||
|
||||
|
|
|
@ -6,16 +6,12 @@ from rest_framework.generics import get_object_or_404
|
|||
from common.tree import TreeNode
|
||||
from orgs.models import Organization
|
||||
from assets.models import SystemUser
|
||||
from applications.utils import KubernetesClient, KubernetesTree
|
||||
from applications.utils import KubernetesTree
|
||||
from applications.models import Application
|
||||
from perms.utils.application.permission import get_application_system_user_ids
|
||||
|
||||
from ..models import Application
|
||||
|
||||
__all__ = ['SerializeApplicationToTreeNodeMixin']
|
||||
|
||||
|
||||
class SerializeApplicationToTreeNodeMixin:
|
||||
|
||||
class GrantedAppTreeUtil:
|
||||
@staticmethod
|
||||
def filter_organizations(applications):
|
||||
organization_ids = set(applications.values_list('org_id', flat=True))
|
||||
|
@ -39,41 +35,15 @@ class SerializeApplicationToTreeNodeMixin:
|
|||
})
|
||||
return node
|
||||
|
||||
def serialize_applications_with_org(self, applications, tree_id, parent_info, user):
|
||||
@staticmethod
|
||||
def get_children_nodes(tree_id, parent_info, user):
|
||||
tree_nodes = []
|
||||
if not applications:
|
||||
return tree_nodes
|
||||
|
||||
if not tree_id:
|
||||
root_node = self.create_root_node()
|
||||
tree_nodes.append(root_node)
|
||||
organizations = self.filter_organizations(applications)
|
||||
|
||||
for i, org in enumerate(organizations):
|
||||
tree_id = urlencode({'org_id': str(org.id)})
|
||||
apps = applications.filter(org_id=org.id)
|
||||
|
||||
# 组织节点
|
||||
org_node = org.as_tree_node(oid=tree_id, pid=root_node.id)
|
||||
org_node.name += '({})'.format(apps.count())
|
||||
tree_nodes.append(org_node)
|
||||
|
||||
# 类别节点
|
||||
category_type_nodes = Application.create_category_type_tree_nodes(
|
||||
apps, tree_id, show_empty=False
|
||||
)
|
||||
tree_nodes += category_type_nodes
|
||||
|
||||
for app in apps:
|
||||
app_node = app.as_tree_node(tree_id, k8s_as_tree=True)
|
||||
tree_nodes.append(app_node)
|
||||
return tree_nodes
|
||||
|
||||
parent_info = dict(parse_qsl(parent_info))
|
||||
pod_name = parent_info.get('pod')
|
||||
app_id = parent_info.get('app_id')
|
||||
namespace = parent_info.get('namespace')
|
||||
system_user_id = parent_info.get('system_user_id')
|
||||
|
||||
if app_id and not any([pod_name, namespace, system_user_id]):
|
||||
app = get_object_or_404(Application, id=app_id)
|
||||
system_user_ids = get_application_system_user_ids(user, app)
|
||||
|
@ -84,6 +54,34 @@ class SerializeApplicationToTreeNodeMixin:
|
|||
)
|
||||
tree_nodes.append(system_user_node)
|
||||
return tree_nodes
|
||||
|
||||
tree_nodes = KubernetesTree(tree_id).async_tree_node(parent_info)
|
||||
return tree_nodes
|
||||
|
||||
def create_tree_nodes(self, applications):
|
||||
tree_nodes = []
|
||||
if not applications:
|
||||
return tree_nodes
|
||||
|
||||
root_node = self.create_root_node()
|
||||
tree_nodes.append(root_node)
|
||||
organizations = self.filter_organizations(applications)
|
||||
|
||||
for i, org in enumerate(organizations):
|
||||
tree_id = urlencode({'org_id': str(org.id)})
|
||||
apps = applications.filter(org_id=org.id)
|
||||
|
||||
# 组织节点
|
||||
org_node = org.as_tree_node(oid=tree_id, pid=root_node.id)
|
||||
org_node.name += '({})'.format(apps.count())
|
||||
tree_nodes.append(org_node)
|
||||
|
||||
# 类别节点
|
||||
category_type_nodes = Application.create_category_type_tree_nodes(
|
||||
apps, tree_id, show_empty=False
|
||||
)
|
||||
tree_nodes += category_type_nodes
|
||||
|
||||
for app in apps:
|
||||
app_node = app.as_tree_node(tree_id, k8s_as_tree=True)
|
||||
tree_nodes.append(app_node)
|
||||
return tree_nodes
|
|
@ -69,6 +69,7 @@ class PublicSettingApi(generics.RetrieveAPIView):
|
|||
"TERMINAL_MAGNUS_ENABLED": settings.TERMINAL_MAGNUS_ENABLED,
|
||||
"TERMINAL_MAGNUS_HOST": settings.TERMINAL_MAGNUS_HOST,
|
||||
"TERMINAL_MAGNUS_MYSQL_PORT": settings.TERMINAL_MAGNUS_MYSQL_PORT,
|
||||
"TERMINAL_MAGNUS_MARIADB_PORT": settings.TERMINAL_MAGNUS_MARIADB_PORT,
|
||||
"TERMINAL_MAGNUS_POSTGRE_PORT": settings.TERMINAL_MAGNUS_POSTGRE_PORT,
|
||||
# Announcement
|
||||
"ANNOUNCEMENT_ENABLED": settings.ANNOUNCEMENT_ENABLED,
|
||||
|
|
|
@ -51,6 +51,10 @@ class TerminalSettingSerializer(serializers.Serializer):
|
|||
required=False, label=_("MySQL port"), default=33060,
|
||||
help_text=_('Database proxy MySQL protocol port')
|
||||
)
|
||||
TERMINAL_MAGNUS_MARIADB_PORT = serializers.IntegerField(
|
||||
required=False, label=_("MariaDB port"), default=33061,
|
||||
help_text=_('Database proxy MySQL protocol port')
|
||||
)
|
||||
TERMINAL_MAGNUS_POSTGRE_PORT = serializers.IntegerField(
|
||||
required=False, label=_("PostgreSQL port"), default=54320,
|
||||
help_text=_('Database proxy PostgreSQL port')
|
||||
|
|
Loading…
Reference in New Issue