22 lines
869 B
Python
22 lines
869 B
Python
"""Create local synthetic secrets once; never overwrite existing credentials."""
|
|
import secrets
|
|
from pathlib import Path
|
|
|
|
root = Path(__file__).resolve().parents[1]
|
|
directory = root / 'secrets'
|
|
directory.mkdir(exist_ok=True)
|
|
password_file = directory / 'db_password'
|
|
if not password_file.exists():
|
|
with password_file.open('x', encoding='utf-8') as file:
|
|
file.write(secrets.token_urlsafe(32))
|
|
password = password_file.read_text(encoding='utf-8').strip()
|
|
url_file = directory / 'database_url'
|
|
if not url_file.exists():
|
|
with url_file.open('x', encoding='utf-8') as file:
|
|
file.write('postgresql://messenger:' + password + '@db:5432/messenger')
|
|
env = root / '.env'
|
|
if not env.exists():
|
|
with env.open('x', encoding='utf-8') as file:
|
|
file.write('SESSION_TTL_SECONDS=3600\n')
|
|
print('Local configuration ready; credentials are not printed.')
|