forked from mtusi2026/mtusi2026lab7
25 lines
766 B
Python
25 lines
766 B
Python
import pathlib
|
|
import subprocess
|
|
|
|
env = dict(x.split('=',1) for x in pathlib.Path('.env').read_text().splitlines() if '=' in x and not x.startswith('#'))
|
|
|
|
def run(*args):
|
|
subprocess.run(['docker','compose','exec','-T','broker','rabbitmqctl',*args],check=True)
|
|
|
|
users = subprocess.check_output(
|
|
['docker','compose','exec','-T','broker','rabbitmqctl','list_users'],
|
|
text=True
|
|
)
|
|
|
|
if 'messenger_worker' not in users:
|
|
run('add_user','messenger_worker',env['BROKER_WORKER_PASSWORD'])
|
|
else:
|
|
run('change_password','messenger_worker',env['BROKER_WORKER_PASSWORD'])
|
|
|
|
run('set_permissions','-p','/','messenger_worker',
|
|
r'^attachment\.jobs$',
|
|
r'^(attachment\.jobs|amq\.default)$',
|
|
r'^attachment\.jobs$')
|
|
|
|
print('PASS: RabbitMQ roles configured')
|