"""Generate local synthetic credentials once. Never prints their values.""" from pathlib import Path import secrets root=Path(__file__).resolve().parents[1] target=root/'.env' if target.exists(): print('Existing .env preserved') else: password=secrets.token_hex(24) content=f'POSTGRES_PASSWORD={password}\nDATABASE_URL=postgresql://messenger:{password}@db:5432/messenger\nREDIS_URL=redis://cache:6379/0\nCURSOR_SECRET={secrets.token_hex(32)}\nSESSION_TTL_SECONDS=3600\n' with target.open('x',encoding='utf-8') as f: f.write(content) try: target.chmod(0o600) except OSError: pass print('Created local .env; values not displayed')