forked from mtusi2026/mtusi2026lab6
Лабораторная 6: наблюдаемость мессенджера
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Generate local credentials once, never print them or overwrite existing files."""
|
||||
from pathlib import Path
|
||||
import os
|
||||
import secrets
|
||||
|
||||
root = Path(__file__).resolve().parents[1]
|
||||
folder = root / 'secrets'
|
||||
folder.mkdir(mode=0o700, exist_ok=True)
|
||||
password_file = folder / 'postgres_password'
|
||||
|
||||
def save(name, value):
|
||||
path = folder / name
|
||||
if path.exists():
|
||||
return
|
||||
fd = os.open(path, os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o600)
|
||||
with os.fdopen(fd, 'w') as handle:
|
||||
handle.write(value + '\n')
|
||||
|
||||
save('postgres_password', secrets.token_hex(24))
|
||||
password = password_file.read_text().strip()
|
||||
save('database_url', 'postgresql://messenger:%s@postgres:5432/messenger' % password)
|
||||
save('cache_url', 'redis://redis:6379/0')
|
||||
save('cursor_secret', secrets.token_hex(32))
|
||||
save('s3_root_user', 'lab6-admin-' + secrets.token_hex(8))
|
||||
save('s3_root_password', secrets.token_hex(32))
|
||||
save('s3_access_key_id', 'lab6-api-' + secrets.token_hex(8))
|
||||
save('s3_secret_access_key', secrets.token_hex(24))
|
||||
save('rabbitmq_password', secrets.token_hex(24))
|
||||
save('grafana_password', secrets.token_hex(24))
|
||||
print('PASS: local secret files ready (existing values preserved)')
|
||||
Reference in New Issue
Block a user