ЛР5: закрыть review края broker, staging replay и полной валидации изображений
This commit is contained in:
+17
-3
@@ -24,6 +24,7 @@ from .storage import ObjectStorage
|
||||
logger = logging.getLogger("messenger.worker")
|
||||
logging.basicConfig(level=logging.INFO, format="%(message)s")
|
||||
stopping = False
|
||||
MAX_JOB_BYTES = 8192
|
||||
|
||||
|
||||
def stop(signum, frame):
|
||||
@@ -105,7 +106,15 @@ def cleanup_ready(store, storage, attachment_id):
|
||||
|
||||
|
||||
def validate_delivery(body):
|
||||
data = json.loads(body)
|
||||
if not isinstance(body, (str, bytes, bytearray)):
|
||||
raise ValueError("invalid_job")
|
||||
encoded = body.encode("utf-8") if isinstance(body, str) else body
|
||||
if len(encoded) > MAX_JOB_BYTES:
|
||||
raise ValueError("invalid_job")
|
||||
try:
|
||||
data = json.loads(encoded)
|
||||
except RecursionError:
|
||||
raise ValueError("invalid_job") from None
|
||||
expected = {
|
||||
"schema_version",
|
||||
"job_id",
|
||||
@@ -126,8 +135,13 @@ def validate_delivery(body):
|
||||
raise ValueError("invalid_job")
|
||||
if not isinstance(data["job_id"], str) or not isinstance(data["attachment_id"], str):
|
||||
raise ValueError("invalid_job")
|
||||
UUID(data["job_id"])
|
||||
UUID(data["attachment_id"])
|
||||
for field in ("job_id", "attachment_id"):
|
||||
canonical = str(UUID(data[field]))
|
||||
if data[field].lower() != canonical:
|
||||
raise ValueError("invalid_job")
|
||||
# RFC UUID hex is case-insensitive; PostgreSQL and state comparisons use
|
||||
# the same canonical spelling, so a valid uppercase delivery is not lost.
|
||||
data[field] = canonical
|
||||
if type(data["pipeline_version"]) is not int or data["pipeline_version"] < 1:
|
||||
raise ValueError("invalid_job")
|
||||
if type(data["attempt"]) is not int or data["attempt"] < 1:
|
||||
|
||||
Reference in New Issue
Block a user