forked from mtusi2026/mtusi2026lab3
38 lines
1.2 KiB
Python
38 lines
1.2 KiB
Python
"""Create local credentials once. Run from the repository on Windows or Linux."""
|
|
|
|
from pathlib import Path
|
|
from secrets import token_hex
|
|
|
|
|
|
ROOT = Path(__file__).resolve().parent.parent
|
|
LOCAL = ROOT / "secrets"
|
|
|
|
|
|
def keep(path, value):
|
|
try:
|
|
with path.open("x", encoding="utf-8", newline="\n") as stream:
|
|
stream.write(value + "\n")
|
|
except FileExistsError:
|
|
pass
|
|
return path.read_text(encoding="utf-8").strip()
|
|
|
|
|
|
def main():
|
|
LOCAL.mkdir(mode=0o700, exist_ok=True)
|
|
db = keep(LOCAL / "db_password", token_hex(24))
|
|
cache = keep(LOCAL / "cache_password", token_hex(24))
|
|
keep(LOCAL / "database_url", f"postgresql://messenger:{db}@db:5432/messenger")
|
|
keep(LOCAL / "cache_url", f"redis://:{cache}@cache:6379/0")
|
|
keep(LOCAL / "cursor_key", token_hex(32))
|
|
keep(LOCAL / "redis.conf", "\n".join((
|
|
"bind 0.0.0.0", "protected-mode yes", "dir /data",
|
|
"appendonly yes", "appendfsync always", "maxmemory 64mb",
|
|
"maxmemory-policy noeviction", f"requirepass {cache}",
|
|
)))
|
|
keep(ROOT / ".env", "HTTP_PORT=8080\nSESSION_TTL_SECONDS=3600")
|
|
print("Локальная конфигурация готова.")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|