config #11
@ -6,7 +6,8 @@ services:
|
|||||||
platform-nginx:
|
platform-nginx:
|
||||||
image: mathwave/sprint-repo:platform
|
image: mathwave/sprint-repo:platform
|
||||||
networks:
|
networks:
|
||||||
- common-infra-nginx
|
- common-infra-nginx-development
|
||||||
|
- configurator-development
|
||||||
environment:
|
environment:
|
||||||
DB_HOST: "pg.develop.sprinthub.ru"
|
DB_HOST: "pg.develop.sprinthub.ru"
|
||||||
DB_PASSWORD: $DB_PASSWORD_DEV
|
DB_PASSWORD: $DB_PASSWORD_DEV
|
||||||
@ -74,5 +75,7 @@ services:
|
|||||||
order: start-first
|
order: start-first
|
||||||
|
|
||||||
networks:
|
networks:
|
||||||
common-infra-nginx:
|
common-infra-nginx-development:
|
||||||
external: true
|
external: true
|
||||||
|
configurator-development:
|
||||||
|
external: true
|
||||||
|
@ -7,6 +7,7 @@ services:
|
|||||||
image: mathwave/sprint-repo:platform
|
image: mathwave/sprint-repo:platform
|
||||||
networks:
|
networks:
|
||||||
- common-infra-nginx
|
- common-infra-nginx
|
||||||
|
- configurator
|
||||||
environment:
|
environment:
|
||||||
DB_HOST: "pg.sprinthub.ru"
|
DB_HOST: "pg.sprinthub.ru"
|
||||||
DB_PASSWORD: $DB_PASSWORD_PROD
|
DB_PASSWORD: $DB_PASSWORD_PROD
|
||||||
@ -82,3 +83,5 @@ services:
|
|||||||
networks:
|
networks:
|
||||||
common-infra-nginx:
|
common-infra-nginx:
|
||||||
external: true
|
external: true
|
||||||
|
configurator:
|
||||||
|
external: true
|
||||||
|
@ -28,7 +28,7 @@ jobs:
|
|||||||
run: docker push mathwave/sprint-repo:platform
|
run: docker push mathwave/sprint-repo:platform
|
||||||
deploy-dev:
|
deploy-dev:
|
||||||
name: Deploy dev
|
name: Deploy dev
|
||||||
runs-on: [dev]
|
runs-on: [prod]
|
||||||
needs: push
|
needs: push
|
||||||
steps:
|
steps:
|
||||||
- name: login
|
- name: login
|
||||||
@ -46,4 +46,4 @@ jobs:
|
|||||||
RABBITMQ_PASSWORD: ${{ secrets.RABBITMQ_PASSWORD_DEV }}
|
RABBITMQ_PASSWORD: ${{ secrets.RABBITMQ_PASSWORD_DEV }}
|
||||||
VK_SERVICE_TOKEN: ${{ secrets.VK_SERVICE_TOKEN }}
|
VK_SERVICE_TOKEN: ${{ secrets.VK_SERVICE_TOKEN }}
|
||||||
YANDEX_SERVICE_TOKEN: ${{ secrets.YANDEX_SERVICE_TOKEN }}
|
YANDEX_SERVICE_TOKEN: ${{ secrets.YANDEX_SERVICE_TOKEN }}
|
||||||
run: docker stack deploy --with-registry-auth -c ./.deploy/deploy-dev.yaml platform
|
run: docker stack deploy --with-registry-auth -c ./.deploy/deploy-dev.yaml platform-development
|
||||||
|
58
BaseLib/configurator.py
Normal file
58
BaseLib/configurator.py
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
from requests import get, put, post, delete
|
||||||
|
from json import dumps
|
||||||
|
|
||||||
|
|
||||||
|
URL_CONFIGS = 'http://configurator/api/v1/configs'
|
||||||
|
URL_EXPERIMENTS = 'http://configurator/api/v1/experiments'
|
||||||
|
|
||||||
|
|
||||||
|
def get_configs(project, stage):
|
||||||
|
response = get(URL_CONFIGS, params={'project': project, 'stage': stage})
|
||||||
|
if response.status_code != 200:
|
||||||
|
return []
|
||||||
|
data = response.json()
|
||||||
|
for config in data:
|
||||||
|
config['value_pretty'] = dumps(config['value'], indent=4, ensure_ascii=False)
|
||||||
|
return data
|
||||||
|
|
||||||
|
|
||||||
|
def create_config(project, stage, name):
|
||||||
|
post(URL_CONFIGS, json={'project': project, 'stage': stage, 'name': name})
|
||||||
|
|
||||||
|
|
||||||
|
def update_config(id, value):
|
||||||
|
put(URL_CONFIGS, json={'id': id, 'value': value})
|
||||||
|
|
||||||
|
|
||||||
|
def delete_config(id):
|
||||||
|
delete(URL_CONFIGS, json={'id': id})
|
||||||
|
|
||||||
|
|
||||||
|
def get_experiments(project, stage):
|
||||||
|
response = get(URL_EXPERIMENTS, params={'project': project, 'stage': stage})
|
||||||
|
if response.status_code != 200:
|
||||||
|
return []
|
||||||
|
data = response.json()
|
||||||
|
for exp in data:
|
||||||
|
if exp['condition'] == 'False':
|
||||||
|
exp['exp_type'] = 0
|
||||||
|
elif exp['condition'] == 'user.is_superuser':
|
||||||
|
exp['exp_type'] = 1
|
||||||
|
elif exp['condition'] == 'user.platform_staff':
|
||||||
|
exp['exp_type'] = 2
|
||||||
|
elif exp['condition'] == 'True':
|
||||||
|
exp['exp_type'] = 3
|
||||||
|
else:
|
||||||
|
exp['exp_type'] = 4
|
||||||
|
return data
|
||||||
|
|
||||||
|
def create_experiment(project, stage, name):
|
||||||
|
post(URL_EXPERIMENTS, json={'project': project, 'stage': stage, 'name': name})
|
||||||
|
|
||||||
|
|
||||||
|
def update_experiment(id, enabled, condition):
|
||||||
|
put(URL_EXPERIMENTS, json={'id': id, 'enabled': enabled, 'condition': condition})
|
||||||
|
|
||||||
|
|
||||||
|
def delete_experiment(id):
|
||||||
|
delete(URL_CONFIGS, json={'id': id})
|
@ -3,6 +3,7 @@ from json import loads
|
|||||||
from django.http import HttpResponse, JsonResponse
|
from django.http import HttpResponse, JsonResponse
|
||||||
|
|
||||||
from BaseLib.BaseView import BaseView
|
from BaseLib.BaseView import BaseView
|
||||||
|
from BaseLib.configurator import *
|
||||||
from Platform import settings
|
from Platform import settings
|
||||||
from configs.models import Config
|
from configs.models import Config
|
||||||
|
|
||||||
@ -20,31 +21,35 @@ class ConfigsView(BaseView):
|
|||||||
return '/configs/?stage=production'
|
return '/configs/?stage=production'
|
||||||
self.stage = self.request.GET['stage']
|
self.stage = self.request.GET['stage']
|
||||||
self.context['stage'] = self.stage
|
self.context['stage'] = self.stage
|
||||||
self.context['configs'] = Config.objects.filter(project=self.request.user.selected_project,
|
# self.context['configs'] = Config.objects.filter(project=self.request.user.selected_project,
|
||||||
stage=self.stage).order_by('name')
|
# stage=self.stage).order_by('name')
|
||||||
|
self.context['configs'] = get_configs(self.request.user.selected_project.name, self.stage)
|
||||||
|
|
||||||
def post_create_config(self):
|
def post_create_config(self):
|
||||||
Config.objects.create(name=self.request.POST['name'], project=self.request.user.selected_project, stage=self.stage)
|
create_config(self.request.user.selected_project.name, self.stage, self.request.POST['name'])
|
||||||
|
# Config.objects.create(name=self.request.POST['name'], project=self.request.user.selected_project, stage=self.stage)
|
||||||
return '/configs/?stage=' + self.stage
|
return '/configs/?stage=' + self.stage
|
||||||
|
|
||||||
def post_delete(self):
|
def post_delete(self):
|
||||||
config = Config.objects.get(id=self.request.POST['config'])
|
# config = Config.objects.get(id=self.request.POST['config'])
|
||||||
config.delete()
|
# config.delete()
|
||||||
return '/configs/?stage=' + config.stage
|
delete_config(self.request.POST['config'])
|
||||||
|
return '/configs/?stage=' + self.stage
|
||||||
|
|
||||||
def post_save(self):
|
def post_save(self):
|
||||||
data = self.request.POST['data']
|
data = self.request.POST['data']
|
||||||
config = Config.objects.get(id=self.request.POST['config'])
|
# config = Config.objects.get(id=self.request.POST['config'])
|
||||||
try:
|
try:
|
||||||
data = loads(data)
|
data = loads(data)
|
||||||
except:
|
except:
|
||||||
self.context['incorrect_config'] = config
|
self.context['incorrect_config'] = self.request.POST['config']
|
||||||
self.context['incorrect_data'] = data
|
self.context['incorrect_data'] = data
|
||||||
self.context['error'] = True
|
self.context['error'] = True
|
||||||
return
|
return
|
||||||
config.data = data
|
update_config(self.request.POST['config'], data)
|
||||||
config.save()
|
# config.data = data
|
||||||
return '/configs/?stage=' + config.stage
|
# config.save()
|
||||||
|
return '/configs/?stage=' + self.stage
|
||||||
|
|
||||||
|
|
||||||
def get_config(request):
|
def get_config(request):
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
from django.http import HttpResponse, JsonResponse
|
from django.http import HttpResponse, JsonResponse
|
||||||
|
|
||||||
from BaseLib.BaseView import BaseView
|
from BaseLib.BaseView import BaseView
|
||||||
|
from BaseLib.configurator import *
|
||||||
from Platform import settings
|
from Platform import settings
|
||||||
from experiments.models import Experiment
|
from experiments.models import Experiment
|
||||||
|
|
||||||
@ -17,31 +18,48 @@ class ExperimentsView(BaseView):
|
|||||||
self.context['stage'] = self.stage
|
self.context['stage'] = self.stage
|
||||||
|
|
||||||
def get(self):
|
def get(self):
|
||||||
self.context['experiments'] = Experiment.objects.filter(project=self.request.user.selected_project,
|
# self.context['experiments'] = Experiment.objects.filter(project=self.request.user.selected_project,
|
||||||
stage=self.stage).order_by('name')
|
# stage=self.stage).order_by('name')
|
||||||
|
self.context['experiments'] = get_experiments(self.request.user.selected_project.name, self.stage)
|
||||||
|
|
||||||
def post_create(self):
|
def post_create(self):
|
||||||
Experiment.objects.create(project=self.request.user.selected_project, stage=self.stage, name=self.request.POST['name'])
|
# Experiment.objects.create(project=self.request.user.selected_project, stage=self.stage, name=self.request.POST['name'])
|
||||||
|
create_experiment(self.request.user.selected_project.name, self.stage, self.request.POST['name'])
|
||||||
return '/experiments/?stage=' + self.stage
|
return '/experiments/?stage=' + self.stage
|
||||||
|
|
||||||
def post_delete(self):
|
def post_delete(self):
|
||||||
Experiment.objects.get(id=self.request.POST['experiment_id']).delete()
|
# Experiment.objects.get(id=self.request.POST['experiment_id']).delete()
|
||||||
|
delete_experiment(self.request.POST['experiment_id'])
|
||||||
return '/experiments/?stage=' + self.stage
|
return '/experiments/?stage=' + self.stage
|
||||||
|
|
||||||
def post_change(self):
|
def post_change(self):
|
||||||
exp = Experiment.objects.get(id=self.request.POST['experiment_id'])
|
# exp = Experiment.objects.get(id=self.request.POST['experiment_id'])
|
||||||
exp.enabled = 'enabled' in self.request.POST
|
# exp.enabled = 'enabled' in self.request.POST
|
||||||
|
# condition = self.request.POST['condition_select']
|
||||||
|
# if condition == 'Другое (только для техлидов)':
|
||||||
|
# exp.condition = self.request.POST['condition']
|
||||||
|
# elif condition == 'Никому':
|
||||||
|
# exp.condition = 'False'
|
||||||
|
# elif condition == 'Только админам':
|
||||||
|
# exp.condition = 'user.is_superuser'
|
||||||
|
# elif condition == 'Только сотрудникам':
|
||||||
|
# exp.condition = 'user.platform_staff'
|
||||||
|
# else:
|
||||||
|
# exp.condition = 'True'
|
||||||
|
# exp.save()
|
||||||
|
enabled = 'enabled' in self.request.POST
|
||||||
condition = self.request.POST['condition_select']
|
condition = self.request.POST['condition_select']
|
||||||
if condition == 'Другое (только для техлидов)':
|
if condition == 'Другое (только для техлидов)':
|
||||||
exp.condition = self.request.POST['condition']
|
condition = self.request.POST['condition']
|
||||||
elif condition == 'Никому':
|
elif condition == 'Никому':
|
||||||
exp.condition = 'False'
|
condition = 'False'
|
||||||
elif condition == 'Только админам':
|
elif condition == 'Только админам':
|
||||||
exp.condition = 'user.is_superuser'
|
condition = 'user.is_superuser'
|
||||||
elif condition == 'Только сотрудникам':
|
elif condition == 'Только сотрудникам':
|
||||||
exp.condition = 'user.platform_staff'
|
condition = 'user.platform_staff'
|
||||||
else:
|
else:
|
||||||
exp.condition = 'True'
|
condition = 'True'
|
||||||
exp.save()
|
update_experiment(self.request.POST['experiment_id'], enabled, condition)
|
||||||
return '/experiments/?stage=' + self.stage
|
return '/experiments/?stage=' + self.stage
|
||||||
|
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@
|
|||||||
</div>
|
</div>
|
||||||
{% if error %}
|
{% if error %}
|
||||||
<div class="alert alert-danger" role="alert">
|
<div class="alert alert-danger" role="alert">
|
||||||
Конфиг {{ incorrect_config.name }} не имеет вид JSON!
|
Конфиг не имеет вид JSON!
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<table class="table">
|
<table class="table">
|
||||||
@ -52,7 +52,7 @@
|
|||||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<textarea style="width: 100%; height: 800px;{% if config.id == incorrect_config.id %}border: 1px solid #f00;{% endif %}" name="data">{% if config.id == incorrect_config.id %}{{ incorrect_data }}{% else %}{{ config.data_pretty }}{% endif %}</textarea>
|
<textarea style="width: 100%; height: 800px;{% if config.id == incorrect_config %}border: 1px solid #f00;{% endif %}" name="data">{% if config.id == incorrect_config %}{{ incorrect_data }}{% else %}{{ config.value_pretty }}{% endif %}</textarea>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<button type="submit" name="action" value="save" class="btn btn-secondary">Сохранить</button>
|
<button type="submit" name="action" value="save" class="btn btn-secondary">Сохранить</button>
|
||||||
|
Loading…
Reference in New Issue
Block a user