lab3: Nginx, реплики и идемпотентность

This commit is contained in:
2026-11-06 20:20:43 +03:00
parent 0ab3a341aa
commit 69102247bc
69 changed files with 5271 additions and 38 deletions
+25
View File
@@ -0,0 +1,25 @@
#!/usr/bin/env python3
"""Generate local credentials once, never print them or overwrite existing files."""
from pathlib import Path
import os
import secrets
root = Path(__file__).resolve().parents[1]
folder = root / 'secrets'
folder.mkdir(mode=0o700, exist_ok=True)
password_file = folder / 'postgres_password'
def save(name, value):
path = folder / name
if path.exists():
return
fd = os.open(path, os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o600)
with os.fdopen(fd, 'w') as handle:
handle.write(value + '\n')
save('postgres_password', secrets.token_hex(24))
password = password_file.read_text().strip()
save('database_url', 'postgresql://messenger:%s@postgres:5432/messenger' % password)
save('cache_url', 'redis://redis:6379/0')
save('cursor_secret', secrets.token_hex(32))
print('PASS: local secret files ready (existing values preserved)')