ЛР 3 — БВТ-2302 — Сабитов — на 3
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
"""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')
|
||||
Reference in New Issue
Block a user