выполненная лаб3

This commit is contained in:
2026-10-23 18:29:24 +03:00
parent 0ab3a341aa
commit f026c27938
57 changed files with 32952 additions and 33 deletions
+17
View File
@@ -0,0 +1,17 @@
#!/usr/bin/env python3
"""Generate local synthetic credentials once; never print their values."""
from pathlib import Path
import secrets
root=Path(__file__).resolve().parents[1]
folder=root/'secrets'
folder.mkdir(mode=0o700,exist_ok=True)
folder.chmod(0o700)
password=folder/'db_password'
if not password.exists():
password.write_text(secrets.token_hex(32))
for name,value in {'database_url':'postgresql://messenger:'+password.read_text().strip()+'@postgres:5432/messenger','cache_url':'redis://redis:6379/0'}.items():
path=folder/name
if not path.exists(): path.write_text(value)
for path in folder.iterdir(): path.chmod(0o600)
if not (root/'.env').exists(): (root/'.env').write_text('API_REPLICAS=2\nSESSION_TTL_SECONDS=3600\n')
print('Local secrets ready (values hidden).')