From df52240227ece56c33624f7567176a2081eb4980 Mon Sep 17 00:00:00 2001 From: BaiJiangJie <32935519+BaiJiangJie@users.noreply.github.com> Date: Thu, 5 Dec 2019 16:21:11 +0800 Subject: [PATCH] =?UTF-8?q?[Update]=20=E4=BF=AE=E5=A4=8D=E5=BD=95=E5=83=8F?= =?UTF-8?q?=E5=9B=9E=E6=94=BE=20Bug=20(#3506)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/terminal/api/session.py | 6 +++--- apps/terminal/models.py | 24 ++++++++++++++++++++---- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/apps/terminal/api/session.py b/apps/terminal/api/session.py index 84ddc21be..52ea49fac 100644 --- a/apps/terminal/api/session.py +++ b/apps/terminal/api/session.py @@ -105,9 +105,9 @@ class SessionReplayViewSet(viewsets.ViewSet): data['src'] = url return Response(data) - # 去定义的外部storage查找 - configs = settings.TERMINAL_REPLAY_STORAGE - configs = {k: v for k, v in configs.items() if v['TYPE'] != 'server'} + # 去 Session 相关的 Terminal 中关联的存储中查找 + replay_storage = session.terminal.get_replay_storage() + configs = {replay_storage.name: replay_storage.config} if not configs: return HttpResponseNotFound() diff --git a/apps/terminal/models.py b/apps/terminal/models.py index 63590204c..cb00c99d0 100644 --- a/apps/terminal/models.py +++ b/apps/terminal/models.py @@ -58,20 +58,36 @@ class Terminal(models.Model): self.user.is_active = active self.user.save() + def get_command_storage(self): + storage = CommandStorage.objects.filter(name=self.command_storage).first() + return storage + def get_command_storage_config(self): - s = CommandStorage.objects.filter(name=self.command_storage).first() + s = self.get_command_storage() if s: config = s.config else: config = settings.DEFAULT_TERMINAL_COMMAND_STORAGE + return config + + def get_command_storage_setting(self): + config = self.get_command_storage_config() return {"TERMINAL_COMMAND_STORAGE": config} + def get_replay_storage(self): + storage = ReplayStorage.objects.filter(name=self.replay_storage).first() + return storage + def get_replay_storage_config(self): - s = ReplayStorage.objects.filter(name=self.replay_storage).first() + s = self.get_replay_storage() if s: config = s.config else: config = settings.DEFAULT_TERMINAL_REPLAY_STORAGE + return config + + def get_replay_storage_setting(self): + config = self.get_replay_storage_config() return {"TERMINAL_REPLAY_STORAGE": config} @property @@ -81,8 +97,8 @@ class Terminal(models.Model): if not k.startswith('TERMINAL'): continue configs[k] = getattr(settings, k) - configs.update(self.get_command_storage_config()) - configs.update(self.get_replay_storage_config()) + configs.update(self.get_command_storage_setting()) + configs.update(self.get_replay_storage_setting()) configs.update({ 'SECURITY_MAX_IDLE_TIME': settings.SECURITY_MAX_IDLE_TIME })