From 41f1c3f7f74f2b5c70f081c2e1cdfa33ae717b98 Mon Sep 17 00:00:00 2001 From: ibuler Date: Sun, 21 Jan 2018 15:12:59 +0800 Subject: [PATCH] [Feature] terminal config load --- apps/terminal/api.py | 7 +++++-- apps/terminal/models.py | 14 ++++++++++++-- apps/terminal/urls/api_urls.py | 3 ++- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/apps/terminal/api.py b/apps/terminal/api.py index e587d8928..25408b6b4 100644 --- a/apps/terminal/api.py +++ b/apps/terminal/api.py @@ -262,8 +262,11 @@ class SessionReplayViewSet(viewsets.ViewSet): return HttpResponseNotFound() -class LoadConfig(APIView): +class TerminalConfig(APIView): permission_classes = (IsAppUser,) def get(self, request): - pass + user = request.user + terminal = user.terminal + configs = terminal.config + return Response(configs, status=200) diff --git a/apps/terminal/models.py b/apps/terminal/models.py index b8524f727..4c5244bcb 100644 --- a/apps/terminal/models.py +++ b/apps/terminal/models.py @@ -44,14 +44,24 @@ class Terminal(models.Model): self.user.save() def get_common_storage(self): - pass + storage_all = settings.TERMINAL_COMMAND_STORAGE + if self.command_storage in storage_all: + storage = storage_all.get(self.command_storage) + else: + storage = storage_all.get('default') + return {"TERMINAL_COMMAND_STORAGE": storage} def get_replay_storage(self): pass @property def config(self): - return + configs = {} + for k in dir(settings): + if k.startswith('TERMINAL'): + configs[k] = getattr(settings, k) + configs.update(self.get_common_storage()) + return configs def create_app_user(self): random = uuid.uuid4().hex[:6] diff --git a/apps/terminal/urls/api_urls.py b/apps/terminal/urls/api_urls.py index 55d77ee00..a3ebc2129 100644 --- a/apps/terminal/urls/api_urls.py +++ b/apps/terminal/urls/api_urls.py @@ -20,7 +20,8 @@ urlpatterns = [ url(r'^v1/sessions/(?P[0-9a-zA-Z\-]{36})/replay/$', api.SessionReplayViewSet.as_view({'get': 'retrieve', 'post': 'create'}), name='session-replay'), - url(r'^v1/terminal/(?P[a-zA-Z0-9\-]{36})/access-key', api.TerminalTokenApi.as_view(), name='terminal-access-key') + url(r'^v1/terminal/(?P[a-zA-Z0-9\-]{36})/access-key', api.TerminalTokenApi.as_view(), name='terminal-access-key'), + url(r'^v1/terminal/config', api.TerminalConfig.as_view(), name='terminal-config'), ] urlpatterns += router.urls