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 .application import *
|
||||||
from .account import *
|
from .account import *
|
||||||
from .mixin import *
|
|
||||||
from .remote_app import *
|
from .remote_app import *
|
||||||
|
|
|
@ -145,7 +145,6 @@ class ApplicationTreeNodeMixin:
|
||||||
pid, counts, show_empty=show_empty,
|
pid, counts, show_empty=show_empty,
|
||||||
show_count=show_count
|
show_count=show_count
|
||||||
)
|
)
|
||||||
|
|
||||||
return tree_nodes
|
return tree_nodes
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -183,7 +182,7 @@ class ApplicationTreeNodeMixin:
|
||||||
|
|
||||||
def _attrs_to_tree(self):
|
def _attrs_to_tree(self):
|
||||||
if self.category == const.AppCategory.db:
|
if self.category == const.AppCategory.db:
|
||||||
return {'database': self.attrs.get('database')}
|
return self.attrs
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
def _as_tree_node(self, pid):
|
def _as_tree_node(self, pid):
|
||||||
|
|
|
@ -317,6 +317,7 @@ class Config(dict):
|
||||||
'TERMINAL_MAGNUS_ENABLED': True,
|
'TERMINAL_MAGNUS_ENABLED': True,
|
||||||
'TERMINAL_MAGNUS_HOST': lambda: urlparse(settings.SITE_URL).hostname,
|
'TERMINAL_MAGNUS_HOST': lambda: urlparse(settings.SITE_URL).hostname,
|
||||||
'TERMINAL_MAGNUS_MYSQL_PORT': 33060,
|
'TERMINAL_MAGNUS_MYSQL_PORT': 33060,
|
||||||
|
'TERMINAL_MAGNUS_MARIADB_PORT': 33061,
|
||||||
'TERMINAL_MAGNUS_POSTGRE_PORT': 54320,
|
'TERMINAL_MAGNUS_POSTGRE_PORT': 54320,
|
||||||
|
|
||||||
# 安全配置
|
# 安全配置
|
||||||
|
|
|
@ -176,4 +176,5 @@ MAGNUS_ENABLED = CONFIG.MAGNUS_ENABLED
|
||||||
TERMINAL_MAGNUS_HOST = CONFIG.TERMINAL_MAGNUS_HOST
|
TERMINAL_MAGNUS_HOST = CONFIG.TERMINAL_MAGNUS_HOST
|
||||||
TERMINAL_MAGNUS_ENABLED = CONFIG.TERMINAL_MAGNUS_ENABLED
|
TERMINAL_MAGNUS_ENABLED = CONFIG.TERMINAL_MAGNUS_ENABLED
|
||||||
TERMINAL_MAGNUS_MYSQL_PORT = CONFIG.TERMINAL_MAGNUS_MYSQL_PORT
|
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
|
TERMINAL_MAGNUS_POSTGRE_PORT = CONFIG.TERMINAL_MAGNUS_POSTGRE_PORT
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
#
|
#
|
||||||
|
from typing import Callable
|
||||||
|
|
||||||
from rest_framework.generics import ListAPIView
|
from rest_framework.generics import ListAPIView
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
|
|
||||||
from common.mixins.api import CommonApiMixin
|
from common.mixins.api import CommonApiMixin
|
||||||
from common.tree import TreeNodeSerializer
|
from common.tree import TreeNodeSerializer
|
||||||
from applications.api.mixin import (
|
|
||||||
SerializeApplicationToTreeNodeMixin
|
|
||||||
)
|
|
||||||
from perms import serializers
|
from perms import serializers
|
||||||
from .mixin import AppRoleAdminMixin, AppRoleUserMixin
|
from perms.tree.app import GrantedAppTreeUtil
|
||||||
from perms.utils.application.user_permission import (
|
from perms.utils.application.user_permission import (
|
||||||
get_user_granted_all_applications
|
get_user_granted_all_applications
|
||||||
)
|
)
|
||||||
|
from .mixin import AppRoleAdminMixin, AppRoleUserMixin
|
||||||
|
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
|
@ -23,7 +23,7 @@ __all__ = [
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class AllGrantedApplicationsMixin(CommonApiMixin, ListAPIView):
|
class AllGrantedApplicationsApi(CommonApiMixin, ListAPIView):
|
||||||
only_fields = serializers.AppGrantedSerializer.Meta.only_fields
|
only_fields = serializers.AppGrantedSerializer.Meta.only_fields
|
||||||
serializer_class = serializers.AppGrantedSerializer
|
serializer_class = serializers.AppGrantedSerializer
|
||||||
filterset_fields = {
|
filterset_fields = {
|
||||||
|
@ -41,28 +41,34 @@ class AllGrantedApplicationsMixin(CommonApiMixin, ListAPIView):
|
||||||
return queryset.only(*self.only_fields)
|
return queryset.only(*self.only_fields)
|
||||||
|
|
||||||
|
|
||||||
class UserAllGrantedApplicationsApi(AppRoleAdminMixin, AllGrantedApplicationsMixin):
|
class UserAllGrantedApplicationsApi(AppRoleAdminMixin, AllGrantedApplicationsApi):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class MyAllGrantedApplicationsApi(AppRoleUserMixin, AllGrantedApplicationsMixin):
|
class MyAllGrantedApplicationsApi(AppRoleUserMixin, AllGrantedApplicationsApi):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class ApplicationsAsTreeMixin(SerializeApplicationToTreeNodeMixin):
|
class ApplicationsAsTreeMixin:
|
||||||
"""
|
"""
|
||||||
将应用序列化成树的结构返回
|
将应用序列化成树的结构返回
|
||||||
"""
|
"""
|
||||||
serializer_class = TreeNodeSerializer
|
serializer_class = TreeNodeSerializer
|
||||||
user: None
|
user: None
|
||||||
|
filter_queryset: Callable
|
||||||
|
get_queryset: Callable
|
||||||
|
get_serializer: Callable
|
||||||
|
|
||||||
def list(self, request, *args, **kwargs):
|
def list(self, request, *args, **kwargs):
|
||||||
tree_id = request.query_params.get('tree_id', None)
|
tree_id = request.query_params.get('tree_id', None)
|
||||||
parent_info = request.query_params.get('parentInfo', None)
|
parent_info = request.query_params.get('parentInfo', None)
|
||||||
queryset = self.filter_queryset(self.get_queryset())
|
queryset = self.filter_queryset(self.get_queryset())
|
||||||
tree_nodes = self.serialize_applications_with_org(
|
util = GrantedAppTreeUtil()
|
||||||
queryset, tree_id, parent_info, self.user
|
|
||||||
)
|
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)
|
serializer = self.get_serializer(tree_nodes, many=True)
|
||||||
return Response(data=serializer.data)
|
return Response(data=serializer.data)
|
||||||
|
|
||||||
|
|
|
@ -6,16 +6,12 @@ from rest_framework.generics import get_object_or_404
|
||||||
from common.tree import TreeNode
|
from common.tree import TreeNode
|
||||||
from orgs.models import Organization
|
from orgs.models import Organization
|
||||||
from assets.models import SystemUser
|
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 perms.utils.application.permission import get_application_system_user_ids
|
||||||
|
|
||||||
from ..models import Application
|
|
||||||
|
|
||||||
__all__ = ['SerializeApplicationToTreeNodeMixin']
|
|
||||||
|
|
||||||
|
|
||||||
class SerializeApplicationToTreeNodeMixin:
|
|
||||||
|
|
||||||
|
class GrantedAppTreeUtil:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def filter_organizations(applications):
|
def filter_organizations(applications):
|
||||||
organization_ids = set(applications.values_list('org_id', flat=True))
|
organization_ids = set(applications.values_list('org_id', flat=True))
|
||||||
|
@ -39,12 +35,33 @@ class SerializeApplicationToTreeNodeMixin:
|
||||||
})
|
})
|
||||||
return node
|
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 = []
|
||||||
|
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)
|
||||||
|
system_users = SystemUser.objects.filter(id__in=system_user_ids).order_by('priority')
|
||||||
|
for system_user in system_users:
|
||||||
|
system_user_node = KubernetesTree(tree_id).as_system_user_tree_node(
|
||||||
|
system_user, parent_info
|
||||||
|
)
|
||||||
|
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 = []
|
tree_nodes = []
|
||||||
if not applications:
|
if not applications:
|
||||||
return tree_nodes
|
return tree_nodes
|
||||||
|
|
||||||
if not tree_id:
|
|
||||||
root_node = self.create_root_node()
|
root_node = self.create_root_node()
|
||||||
tree_nodes.append(root_node)
|
tree_nodes.append(root_node)
|
||||||
organizations = self.filter_organizations(applications)
|
organizations = self.filter_organizations(applications)
|
||||||
|
@ -68,22 +85,3 @@ class SerializeApplicationToTreeNodeMixin:
|
||||||
app_node = app.as_tree_node(tree_id, k8s_as_tree=True)
|
app_node = app.as_tree_node(tree_id, k8s_as_tree=True)
|
||||||
tree_nodes.append(app_node)
|
tree_nodes.append(app_node)
|
||||||
return tree_nodes
|
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)
|
|
||||||
system_users = SystemUser.objects.filter(id__in=system_user_ids).order_by('priority')
|
|
||||||
for system_user in system_users:
|
|
||||||
system_user_node = KubernetesTree(tree_id).as_system_user_tree_node(
|
|
||||||
system_user, parent_info
|
|
||||||
)
|
|
||||||
tree_nodes.append(system_user_node)
|
|
||||||
return tree_nodes
|
|
||||||
|
|
||||||
tree_nodes = KubernetesTree(tree_id).async_tree_node(parent_info)
|
|
||||||
return tree_nodes
|
|
|
@ -69,6 +69,7 @@ class PublicSettingApi(generics.RetrieveAPIView):
|
||||||
"TERMINAL_MAGNUS_ENABLED": settings.TERMINAL_MAGNUS_ENABLED,
|
"TERMINAL_MAGNUS_ENABLED": settings.TERMINAL_MAGNUS_ENABLED,
|
||||||
"TERMINAL_MAGNUS_HOST": settings.TERMINAL_MAGNUS_HOST,
|
"TERMINAL_MAGNUS_HOST": settings.TERMINAL_MAGNUS_HOST,
|
||||||
"TERMINAL_MAGNUS_MYSQL_PORT": settings.TERMINAL_MAGNUS_MYSQL_PORT,
|
"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,
|
"TERMINAL_MAGNUS_POSTGRE_PORT": settings.TERMINAL_MAGNUS_POSTGRE_PORT,
|
||||||
# Announcement
|
# Announcement
|
||||||
"ANNOUNCEMENT_ENABLED": settings.ANNOUNCEMENT_ENABLED,
|
"ANNOUNCEMENT_ENABLED": settings.ANNOUNCEMENT_ENABLED,
|
||||||
|
|
|
@ -51,6 +51,10 @@ class TerminalSettingSerializer(serializers.Serializer):
|
||||||
required=False, label=_("MySQL port"), default=33060,
|
required=False, label=_("MySQL port"), default=33060,
|
||||||
help_text=_('Database proxy MySQL protocol port')
|
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(
|
TERMINAL_MAGNUS_POSTGRE_PORT = serializers.IntegerField(
|
||||||
required=False, label=_("PostgreSQL port"), default=54320,
|
required=False, label=_("PostgreSQL port"), default=54320,
|
||||||
help_text=_('Database proxy PostgreSQL port')
|
help_text=_('Database proxy PostgreSQL port')
|
||||||
|
|
Loading…
Reference in New Issue