mirror of
https://gitlab.com/megazordpobeda/DataRush.git
synced 2026-05-22 23:17:09 +00:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -12,7 +12,7 @@ DJANGO_DB_URI=postgresql://postgres:postgres@postgres/postgres
|
|||||||
DJANGO_CREATE_SUPERUSER=True
|
DJANGO_CREATE_SUPERUSER=True
|
||||||
DJANGO_SUPERUSER_USERNAME=admin
|
DJANGO_SUPERUSER_USERNAME=admin
|
||||||
DJANGO_SUPERUSER_EMAIL=admin@mail.com
|
DJANGO_SUPERUSER_EMAIL=admin@mail.com
|
||||||
DJANGO_SUPERUSER_PASSWORD=admin
|
DJANGO_SUPERUSER_PASSWORD=prooooooood
|
||||||
|
|
||||||
MINIO_ENDPOINT=minio:9000
|
MINIO_ENDPOINT=minio:9000
|
||||||
MINIO_CUSTOM_ENDPOINT_URL=https://prod-team-15-minio-2pc0i3lc.final.prodcontest.ru
|
MINIO_CUSTOM_ENDPOINT_URL=https://prod-team-15-minio-2pc0i3lc.final.prodcontest.ru
|
||||||
|
|||||||
@@ -8,8 +8,6 @@ from apps.competition.models import Competition, State
|
|||||||
|
|
||||||
class CompetitionOut(ModelSchema):
|
class CompetitionOut(ModelSchema):
|
||||||
id: UUID
|
id: UUID
|
||||||
type: Literal["edu", "competitive"]
|
|
||||||
participation_type: Literal["solo"]
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Competition
|
model = Competition
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ ALLOWED_MODULES = {
|
|||||||
"csv",
|
"csv",
|
||||||
"math",
|
"math",
|
||||||
"statistics",
|
"statistics",
|
||||||
|
"statsmodels",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -63,18 +64,28 @@ def validate_code(code_str):
|
|||||||
raise SecurityException(f"Security check failed: {e!s}")
|
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_dir = os.getcwd()
|
||||||
original_stdout = sys.stdout
|
original_stdout = sys.stdout
|
||||||
sys.stdout = captured_stdout = StringIO()
|
sys.stdout = captured_stdout = StringIO()
|
||||||
result_content = None
|
result_content = None
|
||||||
|
|
||||||
|
if input_files is None:
|
||||||
|
input_files = []
|
||||||
|
|
||||||
with tempfile.TemporaryDirectory() as temp_dir:
|
with tempfile.TemporaryDirectory() as temp_dir:
|
||||||
try:
|
try:
|
||||||
os.chdir(temp_dir)
|
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 = {
|
restricted_globals = {
|
||||||
"__builtins__": {
|
"__builtins__": {
|
||||||
"open": lambda f, *a, **kw: open(f, *a, **kw),
|
"open": open,
|
||||||
"print": print,
|
"print": print,
|
||||||
"str": str,
|
"str": str,
|
||||||
"int": int,
|
"int": int,
|
||||||
@@ -105,11 +116,13 @@ def secure_exec(code_str, result_path):
|
|||||||
|
|
||||||
|
|
||||||
@app.task(bind=True)
|
@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:
|
try:
|
||||||
validate_code(code_str)
|
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()
|
result_hash = hashlib.sha256(result_content).hexdigest()
|
||||||
expected_hash = hashlib.sha256(expected_bytes).hexdigest()
|
expected_hash = hashlib.sha256(expected_bytes).hexdigest()
|
||||||
|
|||||||
Reference in New Issue
Block a user