From f863ed0f4f8fb2114c2579d57f8944c90d57c29b Mon Sep 17 00:00:00 2001 From: ibuler Date: Wed, 22 May 2019 10:25:53 +0800 Subject: [PATCH] =?UTF-8?q?[Update]=20=E4=BF=AE=E6=94=B9=E8=8E=B7=E5=8F=96?= =?UTF-8?q?common=20store?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/jumpserver/conf.py | 1 + apps/jumpserver/settings.py | 7 +------ apps/terminal/api/session.py | 4 ++-- apps/terminal/templatetags/terminal_tags.py | 2 +- apps/terminal/views/session.py | 2 +- 5 files changed, 6 insertions(+), 10 deletions(-) diff --git a/apps/jumpserver/conf.py b/apps/jumpserver/conf.py index 35254d1ca..753ffb3d2 100644 --- a/apps/jumpserver/conf.py +++ b/apps/jumpserver/conf.py @@ -343,6 +343,7 @@ defaults = { 'TERMINAL_SESSION_KEEP_DURATION': 9999, 'TERMINAL_HOST_KEY': '', 'TERMINAL_TELNET_REGEX': '', + 'TERMINAL_COMMAND_STORAGE': {}, 'SECURITY_MFA_AUTH': False, 'SECURITY_LOGIN_LIMIT_COUNT': 7, 'SECURITY_LOGIN_LIMIT_TIME': 30, diff --git a/apps/jumpserver/settings.py b/apps/jumpserver/settings.py index bdc71ae3c..57a3c0148 100644 --- a/apps/jumpserver/settings.py +++ b/apps/jumpserver/settings.py @@ -519,12 +519,7 @@ DEFAULT_TERMINAL_COMMAND_STORAGE = { }, } -TERMINAL_COMMAND_STORAGE = { - # 'ali-es': { - # 'TYPE': 'elasticsearch', - # 'HOSTS': ['http://elastic:changeme@localhost:9200'], - # }, -} +TERMINAL_COMMAND_STORAGE = CONFIG.TERMINAL_COMMAND_STORAGE DEFAULT_TERMINAL_REPLAY_STORAGE = { "default": { diff --git a/apps/terminal/api/session.py b/apps/terminal/api/session.py index 39d18b159..f52d7b2b7 100644 --- a/apps/terminal/api/session.py +++ b/apps/terminal/api/session.py @@ -67,7 +67,6 @@ class CommandViewSet(viewsets.ViewSet): """ command_store = get_command_storage() - multi_command_storage = get_multi_command_storage() serializer_class = SessionCommandSerializer permission_classes = (IsOrgAdminOrAppUser,) @@ -88,7 +87,8 @@ class CommandViewSet(viewsets.ViewSet): return Response({"msg": msg}, status=401) def list(self, request, *args, **kwargs): - queryset = self.multi_command_storage.filter() + multi_command_storage = get_multi_command_storage() + queryset = multi_command_storage.filter() serializer = self.serializer_class(queryset, many=True) return Response(serializer.data) diff --git a/apps/terminal/templatetags/terminal_tags.py b/apps/terminal/templatetags/terminal_tags.py index e8ba23186..c0844eb31 100644 --- a/apps/terminal/templatetags/terminal_tags.py +++ b/apps/terminal/templatetags/terminal_tags.py @@ -5,10 +5,10 @@ from django import template from ..backends import get_multi_command_storage register = template.Library() -command_store = get_multi_command_storage() @register.filter def get_session_command_amount(session_id): + command_store = get_multi_command_storage() return command_store.count(session=session_id) diff --git a/apps/terminal/views/session.py b/apps/terminal/views/session.py index bc49e1b65..706d6ee8a 100644 --- a/apps/terminal/views/session.py +++ b/apps/terminal/views/session.py @@ -19,7 +19,6 @@ __all__ = [ 'SessionDetailView', ] -command_store = get_multi_command_storage() class SessionListView(AdminUserRequiredMixin, DatetimeSearchMixin, ListView): @@ -108,6 +107,7 @@ class SessionDetailView(SingleObjectMixin, AdminUserRequiredMixin, ListView): return super().get(request, *args, **kwargs) def get_queryset(self): + command_store = get_multi_command_storage() return command_store.filter(session=self.object.id) def get_context_data(self, **kwargs):