feat(lab4): implement S3 attachments with fault tolerance
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
"""Generate local credentials once; never overwrite an existing secret."""
|
||||
from pathlib import Path
|
||||
import secrets
|
||||
root = Path(__file__).resolve().parents[1]
|
||||
directory = root / 'secrets'
|
||||
directory.mkdir(mode=0o700, exist_ok=True)
|
||||
values = {'postgres_password': secrets.token_hex(24), 's3_root_user': 'lab4root', 's3_root_password': secrets.token_hex(24), 's3_access_key_id': 'lab4api', 's3_secret_access_key': secrets.token_hex(24)}
|
||||
for name, value in values.items():
|
||||
path = directory / name
|
||||
if not path.exists():
|
||||
path.write_text(value + '\n')
|
||||
path.chmod(0o600)
|
||||
path = directory / 'database_url'
|
||||
if not path.exists():
|
||||
password = (directory / 'postgres_password').read_text().strip()
|
||||
path.write_text(f'postgresql://messenger:{password}@postgres:5432/messenger\n')
|
||||
path.chmod(0o600)
|
||||
path = root / '.env'
|
||||
if not path.exists():
|
||||
path.write_text('COMPOSE_PROJECT_NAME=mtusi2026lab4\nPUBLIC_PORT=8084\n')
|
||||
print('Local configuration ready (secret values suppressed)')
|
||||
Reference in New Issue
Block a user