diff --git a/infrastructure/backend/.env.template b/infrastructure/backend/.env.template index 8866be3..40ead7f 100644 --- a/infrastructure/backend/.env.template +++ b/infrastructure/backend/.env.template @@ -12,7 +12,7 @@ DJANGO_DB_URI=postgresql://postgres:postgres@postgres/postgres DJANGO_CREATE_SUPERUSER=True DJANGO_SUPERUSER_USERNAME=admin DJANGO_SUPERUSER_EMAIL=admin@mail.com -DJANGO_SUPERUSER_PASSWORD=admin +DJANGO_SUPERUSER_PASSWORD=prooooooood MINIO_ENDPOINT=minio:9000 MINIO_CUSTOM_ENDPOINT_URL=https://prod-team-15-minio-2pc0i3lc.final.prodcontest.ru diff --git a/services/backend/api/v1/competition/schemas.py b/services/backend/api/v1/competition/schemas.py index 0539b5b..079baab 100644 --- a/services/backend/api/v1/competition/schemas.py +++ b/services/backend/api/v1/competition/schemas.py @@ -8,8 +8,6 @@ from apps.competition.models import Competition, State class CompetitionOut(ModelSchema): id: UUID - type: Literal["edu", "competitive"] - participation_type: Literal["solo"] class Meta: model = Competition diff --git a/services/backend/apps/task/tasks.py b/services/backend/apps/task/tasks.py index 9899246..2ac935e 100644 --- a/services/backend/apps/task/tasks.py +++ b/services/backend/apps/task/tasks.py @@ -19,6 +19,7 @@ ALLOWED_MODULES = { "csv", "math", "statistics", + "statsmodels", } @@ -63,18 +64,28 @@ def validate_code(code_str): raise SecurityException(f"Security check failed: {e!s}") -def secure_exec(code_str, result_path): +def secure_exec(code_str, result_path, input_files=None): original_dir = os.getcwd() original_stdout = sys.stdout sys.stdout = captured_stdout = StringIO() result_content = None + if input_files is None: + input_files = [] + with tempfile.TemporaryDirectory() as temp_dir: try: os.chdir(temp_dir) + + for file in input_files: + file_path = os.path.join(temp_dir, file["bind_at"]) + os.makedirs(os.path.dirname(file_path), exist_ok=True) + with open(file_path, "wb") as f: + f.write(file["content"]) + restricted_globals = { "__builtins__": { - "open": lambda f, *a, **kw: open(f, *a, **kw), + "open": open, "print": print, "str": str, "int": int, @@ -105,11 +116,13 @@ def secure_exec(code_str, result_path): @app.task(bind=True) -def analyze_data_task(self, code_str, result_path, expected_bytes): +def analyze_data_task( + self, code_str, result_path, expected_bytes, input_files=[] +): try: validate_code(code_str) - result_content = secure_exec(code_str, result_path) + result_content = secure_exec(code_str, result_path, input_files) result_hash = hashlib.sha256(result_content).hexdigest() expected_hash = hashlib.sha256(expected_bytes).hexdigest()