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