15 lines
588 B
Python
15 lines
588 B
Python
"""Create local credentials once. Never print or overwrite an existing secret."""
|
|
from pathlib import Path
|
|
import secrets
|
|
|
|
root = Path(__file__).resolve().parents[1]
|
|
path = root / '.env'
|
|
if path.exists():
|
|
print('Existing .env retained')
|
|
else:
|
|
settings = (root / '.env.example').read_text(encoding='utf-8')
|
|
settings = settings.replace('POSTGRES_PASSWORD=', 'POSTGRES_PASSWORD=' + secrets.token_hex(24))
|
|
with path.open('x', encoding='utf-8', newline='\n') as output:
|
|
output.write(settings)
|
|
print('Created local .env with a random password; keep it outside Git')
|