diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index abe8715..6e04b51 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -41,6 +41,7 @@ deploy-dev: DB_PASSWORD: "$DB_PASSWORD_DEMO" DEBUG: "true" TELEGRAM_TOKEN: "$TELEGRAM_TOKEN_DEMO" + FS_TOKEN: "$FS_TOKEN_DEV" deploy-prod: extends: @@ -59,3 +60,4 @@ deploy-prod: FS_HOST: "77.246.159.65" DB_PASSWORD: "$DB_PASSWORD_PROD" TELEGRAM_TOKEN: "$TELEGRAM_TOKEN_PROD" + FS_TOKEN: "$FS_TOKEN_PROD" diff --git a/FileStorage/views/delete_file.py b/FileStorage/views/delete_file.py index c581cf6..239b6f9 100644 --- a/FileStorage/views/delete_file.py +++ b/FileStorage/views/delete_file.py @@ -1,8 +1,11 @@ +import os from os import remove from aiohttp import web async def delete_file(request): + if 'token' not in request.headers or request.headers['token'] != os.getenv('FS_TOKEN'): + return web.json_response({"success": False}, status=403) remove("data/" + request.rel_url.query['id']) return web.json_response({"success": True}) diff --git a/FileStorage/views/get_file.py b/FileStorage/views/get_file.py index e89cc2a..d40267e 100644 --- a/FileStorage/views/get_file.py +++ b/FileStorage/views/get_file.py @@ -1,8 +1,12 @@ +import os + import aiofiles from aiohttp import web async def get_file(request): + if 'token' not in request.headers or request.headers['token'] != os.getenv('FS_TOKEN'): + return web.json_response({"success": False}, status=403) response = web.StreamResponse() await response.prepare(request) async with aiofiles.open("data/" + request.rel_url.query['id'], "rb") as fs: diff --git a/FileStorage/views/upload_file.py b/FileStorage/views/upload_file.py index c5f2ff6..b0392ea 100644 --- a/FileStorage/views/upload_file.py +++ b/FileStorage/views/upload_file.py @@ -1,3 +1,5 @@ +import os + from aiohttp import web from FileStorage.sync import write_meta @@ -5,6 +7,8 @@ import aiofiles async def upload_file(request): + if 'token' not in request.headers or request.headers['token'] != os.getenv('FS_TOKEN'): + return web.json_response({"success": False}, status=403) file_id = await write_meta(request) async with aiofiles.open("data/" + str(file_id), "wb") as fs: await fs.write(await request.content.read()) diff --git a/Main/views/CheckersView.py b/Main/views/CheckersView.py index 18a2de0..e2e5217 100644 --- a/Main/views/CheckersView.py +++ b/Main/views/CheckersView.py @@ -9,9 +9,8 @@ class CheckersView(BaseView): set: Set def pre_handle(self): - self.current_set = self.set if ( - self.request.user != self.current_set.creator - and self.request.user.username not in self.current_set.editors + self.request.user != self.set.creator + and self.request.user.username not in self.set.editors ): raise AccessError() diff --git a/SprintLib/queue.py b/SprintLib/queue.py index 2b50657..5d799a0 100644 --- a/SprintLib/queue.py +++ b/SprintLib/queue.py @@ -28,7 +28,10 @@ class MessagingSupport(BaseCommand): raise NotImplementedError def consume(self, ch, method, properties, body): - self.process(json.loads(body.decode('utf-8'))) + data = json.loads(body.decode('utf-8')) + print(f"Got {data}, processing...") + self.process(data) + print("Process finished successfully") def handle(self, *args, **options): if self.queue_name is None: diff --git a/SprintLib/utils.py b/SprintLib/utils.py index 0ca8c5b..b3d5f20 100644 --- a/SprintLib/utils.py +++ b/SprintLib/utils.py @@ -1,4 +1,5 @@ import datetime +import os from random import choice from requests import get, post @@ -9,19 +10,19 @@ from Sprint import settings def write_bytes(data: bytes): url = settings.FS_HOST + ":" + str(settings.FS_PORT) + "/upload_file" print(url) - return post(url, data=data).json()["id"] + return post(url, data=data, headers={'token': os.getenv('FS_TOKEN')}).json()["id"] def get_bytes(num: int) -> bytes: url = settings.FS_HOST + ":" + str(settings.FS_PORT) + "/get_file?id=" + str(num) print(url) - return get(url).content + return get(url, headers={'token': os.getenv('FS_TOKEN')}).content def delete_file(num: int): url = settings.FS_HOST + ":" + str(settings.FS_PORT) + "/delete_file?id=" + str(num) print(url) - post(url) + post(url, headers={'token': os.getenv('FS_TOKEN')}) def generate_token(): diff --git a/docker-compose-deploy.yaml b/docker-compose-deploy.yaml index 7cd7874..44a2fb4 100644 --- a/docker-compose-deploy.yaml +++ b/docker-compose-deploy.yaml @@ -33,6 +33,7 @@ services: FS_HOST: $FS_HOST DEBUG: $DEBUG TELEGRAM_TOKEN: $TELEGRAM_TOKEN + FS_TOKEN: $FS_TOKEN deploy: mode: replicated restart_policy: @@ -48,6 +49,7 @@ services: FS_HOST: $FS_HOST DEBUG: $DEBUG TELEGRAM_TOKEN: $TELEGRAM_TOKEN + FS_TOKEN: $FS_TOKEN volumes: - /sprint-data/static:/usr/src/app/static command: ./manage.py collectstatic --noinput @@ -66,6 +68,7 @@ services: FS_HOST: $FS_HOST DEBUG: $DEBUG TELEGRAM_TOKEN: $TELEGRAM_TOKEN + FS_TOKEN: $FS_TOKEN volumes: - /sprint-data/static:/usr/src/app/static command: ./manage.py runserver 0.0.0.0:80 --noreload --insecure @@ -90,6 +93,7 @@ services: FS_HOST: $FS_HOST DEBUG: $DEBUG TELEGRAM_TOKEN: $TELEGRAM_TOKEN + FS_TOKEN: $FS_TOKEN ports: - "5555:5555" volumes: @@ -112,6 +116,7 @@ services: FS_HOST: $FS_HOST DEBUG: $DEBUG TELEGRAM_TOKEN: $TELEGRAM_TOKEN + FS_TOKEN: $FS_TOKEN command: ./manage.py bot deploy: mode: replicated @@ -131,6 +136,7 @@ services: FS_HOST: $FS_HOST DEBUG: $DEBUG TELEGRAM_TOKEN: $TELEGRAM_TOKEN + FS_TOKEN: $FS_TOKEN command: ./manage.py loop deploy: mode: replicated @@ -164,6 +170,7 @@ services: FS_HOST: $FS_HOST DEBUG: $DEBUG TELEGRAM_TOKEN: $TELEGRAM_TOKEN + FS_TOKEN: $FS_TOKEN volumes: - /sprint-data/solutions:/usr/src/app/solutions - /var/run/docker.sock:/var/run/docker.sock @@ -187,6 +194,7 @@ services: FS_HOST: $FS_HOST DEBUG: $DEBUG TELEGRAM_TOKEN: $TELEGRAM_TOKEN + FS_TOKEN: $FS_TOKEN deploy: mode: replicated replicas: 1 @@ -207,6 +215,7 @@ services: FS_HOST: $FS_HOST DEBUG: $DEBUG TELEGRAM_TOKEN: $TELEGRAM_TOKEN + FS_TOKEN: $FS_TOKEN deploy: mode: replicated replicas: 1 @@ -227,6 +236,7 @@ services: FS_HOST: $FS_HOST DEBUG: $DEBUG TELEGRAM_TOKEN: $TELEGRAM_TOKEN + FS_TOKEN: $FS_TOKEN deploy: mode: replicated restart_policy: