forked from mtusi2026/mtusi2026lab6
Реализация на 5
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Create synthetic local broker credentials, preserving existing settings."""
|
||||
from pathlib import Path
|
||||
import secrets
|
||||
from urllib.parse import quote
|
||||
root=Path(__file__).resolve().parents[1]
|
||||
env=root/'.env.lab6'
|
||||
values=dict(line.split('=',1) for line in env.read_text().splitlines() if '=' in line and not line.startswith('#'))
|
||||
password=values.get('BROKER_PASSWORD')
|
||||
if not password:
|
||||
password=secrets.token_hex(24)
|
||||
with env.open('a') as f: f.write('\nBROKER_PASSWORD='+password+'\n')
|
||||
p=root/'secrets/lab6/broker_url'
|
||||
if p.exists(): p.chmod(0o600)
|
||||
p.write_text('amqp://messenger:'+quote(password,safe='')+'@broker:5672/\n')
|
||||
p.chmod(0o444)
|
||||
print('Local broker credentials ready.')
|
||||
Reference in New Issue
Block a user