fix auth, decryption, api interaction

This commit is contained in:
Alex Bezdieniezhnykh
2025-01-20 10:17:35 +02:00
parent e21dd7e70f
commit ce25ef38b0
12 changed files with 146 additions and 103 deletions
+20 -15
View File
@@ -1,3 +1,4 @@
import asyncio
import json
import socket
import struct
@@ -13,23 +14,21 @@ from processor_command cimport FileCommand, ProcessorType
from annotation cimport Annotation
cdef class QueueConfig:
cdef str host
cdef str host,
cdef int port
cdef str producer_user
cdef str producer_pw
cdef str consumer_user
cdef str consumer_pw
cdef str producer_user, producer_pw, consumer_user, consumer_pw
@staticmethod
cdef QueueConfig from_json(str json_string):
cdef dict config_dict = json.loads(<str>json_string)
cdef dict config_dict = json.loads(<str>json_string)["QueueConfig"]
cdef QueueConfig config = QueueConfig()
config.Host = config_dict["Host"]
config.Port = config_dict["Port"]
config.ProducerUsername = config_dict["ProducerUsername"]
config.ProducerPassword = config_dict["ProducerPassword"]
config.ConsumerUsername = config_dict["ConsumerUsername"]
config.ConsumerPassword = config_dict["ConsumerPassword"]
config.host = config_dict["Host"]
config.port = config_dict["Port"]
config.producer_user = config_dict["ProducerUsername"]
config.producer_pw = config_dict["ProducerPassword"]
config.consumer_user = config_dict["ConsumerUsername"]
config.consumer_pw = config_dict["ConsumerPassword"]
return config
cdef class SocketHandler:
@@ -75,7 +74,7 @@ cdef class SocketHandler:
cdef class RabbitHandler:
def __init__(self, ApiClient api_client, object on_message):
self.on_message = on_message
cdef str config_str = api_client.load_file(constants.QUEUE_CONFIG_FILENAME).decode(encoding='utf-8')
cdef str config_str = api_client.load_queue_config()
queue_config = QueueConfig.from_json(config_str)
self.annotation_producer = Producer(
host=<str>queue_config.host,
@@ -91,8 +90,14 @@ cdef class RabbitHandler:
)
cdef start(self):
self.command_consumer.start()
self.command_consumer.subscribe(stream=<str>constants.COMMANDS_QUEUE, callback=self.on_message_inner,
threading.Thread(target=self._run_async, daemon=True).start()
def _run_async(self):
asyncio.run(self.start_inner())
async def start_inner(self):
await self.command_consumer.start()
await self.command_consumer.subscribe(stream=<str>constants.COMMANDS_QUEUE, callback=self.on_message_inner,
offset_specification=ConsumerOffsetSpecification(OffsetType.FIRST, None)) # put real offset
def on_message_inner(self, message: AMQPMessage, message_context: MessageContext):