Skip to content

Commit 1492774

Browse files
committed
- Added user and password to config.
issue #1283
1 parent f7aa9b6 commit 1492774

File tree

6 files changed

+33
-3
lines changed

6 files changed

+33
-3
lines changed

packages/plugins/minos-broker-rabbitmq/minos/plugins/rabbitmq/common.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,7 @@ def with_config(self, config: Config):
2323
self.kwargs |= {
2424
"host": common_config.get("host"),
2525
"port": common_config.get("port"),
26+
"user": common_config.get("user"),
27+
"password": common_config.get("password"),
2628
}
2729
return super().with_config(config)

packages/plugins/minos-broker-rabbitmq/minos/plugins/rabbitmq/publisher.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,37 @@
2828
class RabbitMQBrokerPublisher(BrokerPublisher):
2929
"""RabbitMQ Broker Publisher class."""
3030

31-
def __init__(self, *args, host: Optional[str] = None, port: Optional[int] = None, **kwargs):
31+
def __init__(
32+
self,
33+
*args,
34+
host: Optional[str] = None,
35+
port: Optional[int] = None,
36+
user: Optional[str] = None,
37+
password: Optional[str] = None,
38+
**kwargs,
39+
):
3240
super().__init__(*args, **kwargs)
3341

3442
if host is None:
3543
host = "localhost"
3644
if port is None:
3745
port = 5672
46+
if user is None:
47+
user = "guest"
48+
if password is None:
49+
password = "guest"
3850

3951
self.host = host
4052
self.port = port
53+
self.user = user
54+
self.password = password
4155

4256
self.connection = None
4357
self.channel = None
4458

4559
async def _setup(self) -> None:
4660
await super()._setup()
47-
self.connection = await connect(f"amqp://guest:guest@{self.host}:{self.port}/")
61+
self.connection = await connect(f"amqp://{self.user}:{self.password}@{self.host}:{self.port}/")
4862
self.channel = await self.connection.channel()
4963

5064
async def _destroy(self) -> None:

packages/plugins/minos-broker-rabbitmq/minos/plugins/rabbitmq/subscriber.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ def __init__(
4747
topics: Iterable[str],
4848
host: Optional[str] = None,
4949
port: Optional[int] = None,
50+
user: Optional[str] = None,
51+
password: Optional[str] = None,
5052
**kwargs,
5153
):
5254
super().__init__(topics, **kwargs)
@@ -55,9 +57,15 @@ def __init__(
5557
host = "localhost"
5658
if port is None:
5759
port = 5672
60+
if user is None:
61+
user = "guest"
62+
if password is None:
63+
password = "guest"
5864

5965
self.host = host
6066
self.port = port
67+
self.user = user
68+
self.password = password
6169

6270
self.connection = None
6371

@@ -66,7 +74,7 @@ def __init__(
6674

6775
async def _setup(self) -> None:
6876
await super()._setup()
69-
self.connection = await connect(f"amqp://guest:guest@{self.host}:{self.port}/")
77+
self.connection = await connect(f"amqp://{self.user}:{self.password}@{self.host}:{self.port}/")
7078
await self._start_task()
7179

7280
async def _destroy(self) -> None:

packages/plugins/minos-broker-rabbitmq/tests/test_config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ snapshot:
2424
broker:
2525
host: localhost
2626
port: 5672
27+
user: guest
28+
password: guest
2729
queue:
2830
database: order_db
2931
user: minos

packages/plugins/minos-broker-rabbitmq/tests/test_rabbitmq/test_common.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ def test_constructor(self):
2323
expected = {
2424
"host": common_config["host"],
2525
"port": common_config["port"],
26+
"user": common_config["user"],
27+
"password": common_config["password"],
2628
}
2729
self.assertEqual(expected, mixin.kwargs)
2830

packages/plugins/minos-broker-rabbitmq/tests/test_rabbitmq/test_subscriber.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ def test_with_config(self):
6565
expected = {
6666
"host": common_config["host"],
6767
"port": common_config["port"],
68+
"user": common_config["user"],
69+
"password": common_config["password"],
6870
}
6971
self.assertEqual(expected, builder.kwargs)
7072

0 commit comments

Comments
 (0)