forked from mtusi2026/mtusi2026lab7
skeleton lab7 and tasks for grade 3
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
"""Создаёт только отсутствующие локальные настройки и файловые секреты."""
|
||||
|
||||
import os
|
||||
from pathlib import Path
|
||||
import secrets
|
||||
|
||||
from scripts.init_broker import initialize as initialize_broker
|
||||
from scripts.init_tls import initialize
|
||||
|
||||
|
||||
def main() -> None:
|
||||
root = Path(__file__).resolve().parents[1]
|
||||
destination = root / ".env"
|
||||
if not destination.exists():
|
||||
with destination.open("x") as target:
|
||||
target.write((root / ".env.example").read_text())
|
||||
destination.chmod(0o600)
|
||||
directory = root / "secrets"
|
||||
directory.mkdir(mode=0o700, exist_ok=True)
|
||||
for name in (
|
||||
"grafana_admin_password",
|
||||
"db_password",
|
||||
"api_db_password",
|
||||
"worker_db_password",
|
||||
"publisher_db_password",
|
||||
"cleanup_db_password",
|
||||
"redis_password",
|
||||
"test_redis_password",
|
||||
"broker_password",
|
||||
"worker_broker_password",
|
||||
"publisher_broker_password",
|
||||
"minio_root_user",
|
||||
"minio_root_password",
|
||||
"s3_access_key_id",
|
||||
"s3_secret_access_key",
|
||||
"worker_s3_access_key_id",
|
||||
"worker_s3_secret_access_key",
|
||||
):
|
||||
path = directory / name
|
||||
try:
|
||||
descriptor = os.open(path, os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o444)
|
||||
except FileExistsError:
|
||||
continue
|
||||
with os.fdopen(descriptor, "w") as target:
|
||||
target.write(secrets.token_urlsafe(24))
|
||||
print("Создан файл " + str(path.relative_to(root)))
|
||||
settings = {
|
||||
key: value for line in destination.read_text().splitlines()
|
||||
if line and not line.lstrip().startswith("#") and "=" in line
|
||||
for key, value in [line.split("=", 1)]
|
||||
}
|
||||
initialize_broker(directory, settings["BROKER_QUEUE"], settings["BROKER_VHOST"],
|
||||
settings["BROKER_USER"])
|
||||
initialize(root)
|
||||
print("Настройки готовы; существующие значения сохранены")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user