From 26f091c9b4ec43b44468e84db69d410c65cfeccd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B0=D0=BC=D0=BE=D1=85=D0=B2=D0=B0=D0=BB=D0=BE?= =?UTF-8?q?=D0=B2=20=D0=90=D0=BD=D0=B4=D1=80=D0=B5=D0=B9=20=D0=A0=D0=B5?= =?UTF-8?q?=D0=BC=D0=BE=D0=B2=D0=B8=D1=87?= Date: Fri, 2 Oct 2026 14:54:25 +0300 Subject: [PATCH] fix: Include broker bootstrap helper in lab6 baseline (U1) --- scripts/init_local_broker.py | 38 ++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 scripts/init_local_broker.py diff --git a/scripts/init_local_broker.py b/scripts/init_local_broker.py new file mode 100644 index 0000000..e24bf49 --- /dev/null +++ b/scripts/init_local_broker.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python3 +"""Create local RabbitMQ credentials without writing them to tracked files.""" + +from pathlib import Path +from secrets import token_hex +from urllib.parse import quote + + +root = Path(__file__).resolve().parents[1] +secret_dir = root / "secrets" +secret_dir.mkdir(mode=0o700, exist_ok=True) +secret_dir.chmod(0o700) +config = secret_dir / "rabbitmq.conf" +url_file = secret_dir / "broker_url" +username = "lab5_app" + +if config.exists(): + values = dict( + line.split(" = ", 1) + for line in config.read_text(encoding="utf-8").splitlines() + if " = " in line + ) + if values.get("default_user") != username or not values.get("default_pass"): + raise SystemExit("Existing RabbitMQ config cannot be reused") + password = values["default_pass"] +else: + password = token_hex(24) + config.write_text( + f"default_user = {username}\ndefault_pass = {password}\n", + encoding="utf-8", + ) +config.chmod(0o600) +url_file.write_text( + f"amqp://{username}:{quote(password, safe='')}@broker:5672/%2F\n", + encoding="utf-8", +) +url_file.chmod(0o600) +print("Local broker credentials are ready in ignored secrets/")