17 lines
774 B
Python
17 lines
774 B
Python
"""Create local synthetic credentials without printing or replacing existing ones."""
|
|
import secrets
|
|
from pathlib import Path
|
|
root=Path(__file__).resolve().parents[1]
|
|
folder=root/'secrets'
|
|
folder.mkdir(mode=0o700,exist_ok=True)
|
|
p=folder/'db_password'; d=folder/'database_url'
|
|
if p.exists()!=d.exists():
|
|
raise SystemExit('Incomplete secrets: restore the missing file; existing credentials were not changed')
|
|
if not p.exists():
|
|
password=secrets.token_hex(32)
|
|
# Docker secret source directory is private; files must be readable by container UIDs.
|
|
p.write_text(password+'\n')
|
|
d.write_text('postgresql://messenger:'+password+'@db:5432/messenger\n')
|
|
p.chmod(0o644); d.chmod(0o644)
|
|
print('Local secret files ready (values hidden). Do not commit secrets/.')
|