Skip to content
This repository was archived by the owner on Dec 5, 2025. It is now read-only.

Commit 73a510d

Browse files
author
Samuel Hassine
committed
[client] Adapt client to new way to connect RabbitMQ
1 parent dc6b355 commit 73a510d

File tree

3 files changed

+32
-8
lines changed

3 files changed

+32
-8
lines changed

pycti/api/opencti_api_connector.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@ def list(self) -> Dict:
2626
id
2727
name
2828
config {
29-
uri
29+
connection {
30+
host
31+
port
32+
user
33+
pass
34+
}
3035
listen
3136
push
3237
}
@@ -75,7 +80,12 @@ def register(self, connector: OpenCTIConnector) -> Dict:
7580
id
7681
connector_state
7782
config {
78-
uri
83+
connection {
84+
host
85+
port
86+
user
87+
pass
88+
}
7989
listen
8090
listen_exchange
8191
push

pycti/connector/opencti_connector_helper.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,16 @@ class ListenQueue(threading.Thread):
6969

7070
def __init__(self, helper, config: dict, callback):
7171
threading.Thread.__init__(self)
72+
self.pika_credentials = None
73+
self.pika_parameters = None
7274
self.pika_connection = None
7375
self.channel = None
7476
self.helper = helper
7577
self.callback = callback
76-
self.uri = config["uri"]
78+
self.host = config["connection"]["host"]
79+
self.port = config["connection"]["port"]
80+
self.user = config["connection"]["user"]
81+
self.password = config["connection"]["pass"]
7782
self.queue_name = config["listen"]
7883

7984
# noinspection PyUnusedLocal
@@ -129,9 +134,11 @@ def run(self):
129134
while True:
130135
try:
131136
# Connect the broker
132-
self.pika_connection = pika.BlockingConnection(
133-
pika.URLParameters(self.uri)
137+
self.pika_credentials = pika.PlainCredentials(self.user, self.password)
138+
self.pika_parameters = pika.ConnectionParameters(
139+
self.host, self.port, "/", self.pika_credentials
134140
)
141+
self.pika_connection = pika.BlockingConnection(self.pika_parameters)
135142
self.channel = self.pika_connection.channel()
136143
self.channel.basic_consume(
137144
queue=self.queue_name, on_message_callback=self._process_message
@@ -505,9 +512,16 @@ def send_stix2_bundle(self, bundle, **kwargs) -> list:
505512
raise ValueError("Nothing to import")
506513
if work_id is not None:
507514
self.api.work.add_expectations(work_id, len(bundles))
508-
pika_connection = pika.BlockingConnection(
509-
pika.URLParameters(self.config["uri"])
515+
pika_credentials = pika.PlainCredentials(
516+
self.config["connection"]["user"], self.config["connection"]["pass"]
510517
)
518+
pika_parameters = pika.ConnectionParameters(
519+
self.config["connection"]["host"],
520+
self.config["connection"]["port"],
521+
"/",
522+
pika_credentials,
523+
)
524+
pika_connection = pika.BlockingConnection(pika_parameters)
511525
channel = pika_connection.channel()
512526
for sequence, bundle in enumerate(bundles, start=1):
513527
self._send_bundle(

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from setuptools import setup
66
from setuptools.command.install import install
77

8-
VERSION = "4.0.3"
8+
VERSION = "4.0.4"
99

1010
with open("README.md", "r") as fh:
1111
long_description = fh.read()

0 commit comments

Comments
 (0)