From c4b65ff11fd8af783f7e0c5ac9a0ccece2147fa8 Mon Sep 17 00:00:00 2001 From: Administrator Date: Tue, 26 Sep 2023 00:19:48 +0300 Subject: [PATCH] configs and experiments --- .deploy/deploy-dev.yaml | 1 + .deploy/deploy-prod.yaml | 1 + Platform/settings.py | 2 ++ configs/urls.py | 3 ++- configs/views.py | 17 +++++++++++++++++ experiments/urls.py | 3 ++- experiments/views.py | 22 +++++++++++++++++++++- templates/profile.html | 7 ++----- 8 files changed, 48 insertions(+), 8 deletions(-) diff --git a/.deploy/deploy-dev.yaml b/.deploy/deploy-dev.yaml index 2745cd7..36e42f7 100644 --- a/.deploy/deploy-dev.yaml +++ b/.deploy/deploy-dev.yaml @@ -31,6 +31,7 @@ services: RABBITMQ_PASSWORD: $RABBITMQ_PASSWORD_DEV VK_SERVICE_TOKEN: $VK_SERVICE_TOKEN YANDEX_SERVICE_TOKEN: $YANDEX_SERVICE_TOKEN + PLATFORM_SECURITY_TOKEN: $PLATFORM_SECURITY_TOKEN command: runserver 0.0.0.0:8000 healthcheck: test: curl --fail http://0.0.0.0:8000/ping || exit 1 diff --git a/.deploy/deploy-prod.yaml b/.deploy/deploy-prod.yaml index f60b2dd..0927e1e 100644 --- a/.deploy/deploy-prod.yaml +++ b/.deploy/deploy-prod.yaml @@ -36,6 +36,7 @@ services: VK_SERVICE_TOKEN: $VK_SERVICE_TOKEN YANDEX_SERVICE_TOKEN: $YANDEX_SERVICE_TOKEN TELEGRAM_TOKEN: $TELEGRAM_TOKEN + PLATFORM_SECURITY_TOKEN: $PLATFORM_SECURITY_TOKEN command: runserver 0.0.0.0:8000 healthcheck: test: curl --fail http://0.0.0.0:8000/ping || exit 1 diff --git a/Platform/settings.py b/Platform/settings.py index e50ed33..9700b57 100644 --- a/Platform/settings.py +++ b/Platform/settings.py @@ -148,3 +148,5 @@ MINIO_BUCKET_NAME = 'platform' VK_SERVICE_TOKEN = os.getenv("VK_SERVICE_TOKEN", None) YANDEX_SERVICE_TOKEN = os.getenv("YANDEX_SERVICE_TOKEN", None) + +PLATFORM_SECURITY_TOKEN = os.getenv("PLATFORM_SECURITY_TOKEN", None) diff --git a/configs/urls.py b/configs/urls.py index d5e68fe..e2f9095 100644 --- a/configs/urls.py +++ b/configs/urls.py @@ -4,5 +4,6 @@ from django.urls import path from .views import * urlpatterns = [ - path(*ConfigsView.as_path()) + path(*ConfigsView.as_path()), + path('get', get_config) ] diff --git a/configs/views.py b/configs/views.py index 8e17542..62a9485 100644 --- a/configs/views.py +++ b/configs/views.py @@ -1,6 +1,9 @@ from json import loads +from django.http import HttpResponse, JsonResponse + from BaseLib.BaseView import BaseView +from Platform import settings from configs.models import Config @@ -41,3 +44,17 @@ class ConfigsView(BaseView): config.data = data config.save() return '/configs/?stage=' + config.stage + + +def get_config(request): + if request.headers.get("X-Security-Token") != settings.PLATFORM_SECURITY_TOKEN: + return HttpResponse('', status=403) + project = request.GET.get('project') + stage = request.GET.get('stage') + name = request.GET.get('name') + if project is None or stage is None or name is None: + return HttpResponse('', status=400) + config = Config.objects.filter(stage=stage, project=project, name=name).first() + if config is None: + return HttpResponse('', status=404) + return JsonResponse(config.data) diff --git a/experiments/urls.py b/experiments/urls.py index da2ec91..255769f 100644 --- a/experiments/urls.py +++ b/experiments/urls.py @@ -4,5 +4,6 @@ from django.urls import path from .views import * urlpatterns = [ - path(*ExperimentsView.as_path()) + path(*ExperimentsView.as_path()), + path('get', get_experiment) ] diff --git a/experiments/views.py b/experiments/views.py index 41fa5c3..b19b36f 100644 --- a/experiments/views.py +++ b/experiments/views.py @@ -1,4 +1,7 @@ +from django.http import HttpResponse, JsonResponse + from BaseLib.BaseView import BaseView +from Platform import settings from experiments.models import Experiment @@ -39,4 +42,21 @@ class ExperimentsView(BaseView): else: exp.condition = 'True' exp.save() - return '/experiments/?stage=' + self.stage \ No newline at end of file + return '/experiments/?stage=' + self.stage + + +def get_experiment(request): + if request.headers.get("X-Security-Token") != settings.PLATFORM_SECURITY_TOKEN: + return HttpResponse('', status=403) + project = request.GET.get('project') + stage = request.GET.get('stage') + name = request.GET.get('name') + if project is None or stage is None or name is None: + return HttpResponse('', status=400) + experiment = Experiment.objects.filter(stage=stage, project=project, name=name).first() + if experiment is None: + return HttpResponse('', status=404) + return JsonResponse({ + 'enabled': experiment.enabled, + 'condition': experiment.condition + }) diff --git a/templates/profile.html b/templates/profile.html index 32992cf..07f4861 100644 --- a/templates/profile.html +++ b/templates/profile.html @@ -7,7 +7,7 @@
- Фото профиля + Фото профиля
{% if owner %}

- {{ account.userinfo.surname }} {{ account.userinfo.name }} + {{ account.surname }} {{ account.name }} {{ account.userinfo.activity_status }}

@@ -55,9 +55,6 @@ {% if account.vk_id %}
{% endif %} - - -
{% if account.yandex_id %}