forked from mtusi2026/mtusi2026lab5
31 lines
1.2 KiB
Python
31 lines
1.2 KiB
Python
"""Создаёт только отсутствующие локальные настройки и файловые секреты."""
|
|
|
|
import os
|
|
from pathlib import Path
|
|
import secrets
|
|
|
|
|
|
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 ("db_password", "redis_password", "minio_root_user", "minio_root_password", "s3_access_key_id", "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)))
|
|
print("Настройки готовы; существующие значения сохранены")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|