intersect-sdk-common 0.9.3__tar.gz → 0.9.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. {intersect_sdk_common-0.9.3 → intersect_sdk_common-0.9.4}/PKG-INFO +2 -2
  2. {intersect_sdk_common-0.9.3 → intersect_sdk_common-0.9.4}/README.md +1 -1
  3. {intersect_sdk_common-0.9.3 → intersect_sdk_common-0.9.4}/pyproject.toml +5 -3
  4. {intersect_sdk_common-0.9.3 → intersect_sdk_common-0.9.4}/src/intersect_sdk_common/control_plane/brokers/amqp_client.py +7 -2
  5. {intersect_sdk_common-0.9.3 → intersect_sdk_common-0.9.4}/src/intersect_sdk_common/control_plane/brokers/broker_client.py +2 -1
  6. {intersect_sdk_common-0.9.3 → intersect_sdk_common-0.9.4}/src/intersect_sdk_common/control_plane/brokers/mqtt_client.py +3 -3
  7. {intersect_sdk_common-0.9.3 → intersect_sdk_common-0.9.4}/src/intersect_sdk_common/control_plane/control_plane_manager.py +1 -1
  8. intersect_sdk_common-0.9.4/src/intersect_sdk_common/control_plane/custom_binary_protocol.py +77 -0
  9. {intersect_sdk_common-0.9.3 → intersect_sdk_common-0.9.4}/src/intersect_sdk_common/__init__.py +0 -0
  10. {intersect_sdk_common-0.9.3 → intersect_sdk_common-0.9.4}/src/intersect_sdk_common/config.py +0 -0
  11. {intersect_sdk_common-0.9.3 → intersect_sdk_common-0.9.4}/src/intersect_sdk_common/constants.py +0 -0
  12. {intersect_sdk_common-0.9.3 → intersect_sdk_common-0.9.4}/src/intersect_sdk_common/control_plane/__init__.py +0 -0
  13. {intersect_sdk_common-0.9.3 → intersect_sdk_common-0.9.4}/src/intersect_sdk_common/control_plane/brokers/__init__.py +0 -0
  14. {intersect_sdk_common-0.9.3 → intersect_sdk_common-0.9.4}/src/intersect_sdk_common/control_plane/definitions.py +0 -0
  15. {intersect_sdk_common-0.9.3 → intersect_sdk_common-0.9.4}/src/intersect_sdk_common/control_plane/messages/__init__.py +0 -0
  16. {intersect_sdk_common-0.9.3 → intersect_sdk_common-0.9.4}/src/intersect_sdk_common/control_plane/messages/event.py +0 -0
  17. {intersect_sdk_common-0.9.3 → intersect_sdk_common-0.9.4}/src/intersect_sdk_common/control_plane/messages/lifecycle.py +0 -0
  18. {intersect_sdk_common-0.9.3 → intersect_sdk_common-0.9.4}/src/intersect_sdk_common/control_plane/messages/userspace.py +0 -0
  19. {intersect_sdk_common-0.9.3 → intersect_sdk_common-0.9.4}/src/intersect_sdk_common/control_plane/topic_handler.py +0 -0
  20. {intersect_sdk_common-0.9.3 → intersect_sdk_common-0.9.4}/src/intersect_sdk_common/core_definitions.py +0 -0
  21. {intersect_sdk_common-0.9.3 → intersect_sdk_common-0.9.4}/src/intersect_sdk_common/data_plane/__init__.py +0 -0
  22. {intersect_sdk_common-0.9.3 → intersect_sdk_common-0.9.4}/src/intersect_sdk_common/data_plane/data_plane_manager.py +0 -0
  23. {intersect_sdk_common-0.9.3 → intersect_sdk_common-0.9.4}/src/intersect_sdk_common/data_plane/minio_utils.py +0 -0
  24. {intersect_sdk_common-0.9.3 → intersect_sdk_common-0.9.4}/src/intersect_sdk_common/exceptions.py +0 -0
  25. {intersect_sdk_common-0.9.3 → intersect_sdk_common-0.9.4}/src/intersect_sdk_common/logger.py +0 -0
  26. {intersect_sdk_common-0.9.3 → intersect_sdk_common-0.9.4}/src/intersect_sdk_common/py.typed +0 -0
  27. {intersect_sdk_common-0.9.3 → intersect_sdk_common-0.9.4}/src/intersect_sdk_common/utils/__init__.py +0 -0
  28. {intersect_sdk_common-0.9.3 → intersect_sdk_common-0.9.4}/src/intersect_sdk_common/utils/multi_flag_thread_event.py +0 -0
  29. {intersect_sdk_common-0.9.3 → intersect_sdk_common-0.9.4}/src/intersect_sdk_common/version.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: intersect-sdk-common
3
- Version: 0.9.3
3
+ Version: 0.9.4
4
4
  Summary: Python SDK to interact with INTERSECT
5
5
  Keywords: intersect
6
6
  Author: Lance Drane, Marshall McDonnell, Seth Hitefield, Andrew Ayres, Gregory Cage, Jesse McGaha, Robert Smith, Gavin Wiggins, Michael Brim, Rick Archibald, Addi Malviya Thakur
@@ -48,5 +48,5 @@ The INTERSECT-SDK MUST follow semantic versioning, and MUST update its semantic
48
48
  ```bash
49
49
  uv venv .venv
50
50
  source .venv/bin/activate
51
- uv sync --locked --all-extras --all-groups
51
+ uv sync --all-extras --all-groups
52
52
  ```
@@ -28,5 +28,5 @@ The INTERSECT-SDK MUST follow semantic versioning, and MUST update its semantic
28
28
  ```bash
29
29
  uv venv .venv
30
30
  source .venv/bin/activate
31
- uv sync --locked --all-extras --all-groups
31
+ uv sync --all-extras --all-groups
32
32
  ```
@@ -18,7 +18,7 @@ readme = "README.md"
18
18
  license = { text = "BSD-3-Clause" }
19
19
  requires-python = ">=3.10,<4.0"
20
20
  keywords = ["intersect"]
21
- version = "0.9.3"
21
+ version = "0.9.4"
22
22
  classifiers = [
23
23
  "Programming Language :: Python :: 3",
24
24
  "Programming Language :: Python :: 3.10",
@@ -34,13 +34,15 @@ dependencies = [
34
34
  ]
35
35
 
36
36
  [dependency-groups]
37
- lint = [
37
+ dev = [
38
38
  "pre-commit>=3.3.1",
39
39
  "ruff==0.12.7",
40
40
  "mypy>=1.10.0",
41
41
  "codespell>=2.3.0",
42
+ "pytest>=7.3.2",
43
+ "pytest-cov>=4.1.0",
44
+ "httpretty>=1.1.4",
42
45
  ]
43
- test = ["pytest>=7.3.2", "pytest-cov>=4.1.0", "httpretty>=1.1.4"]
44
46
 
45
47
  [build-system]
46
48
  requires = ["uv_build>=0.10.2,<0.11.0"]
@@ -223,17 +223,22 @@ class AMQPClient(BrokerClient):
223
223
  else:
224
224
  logger.error('Unable to publish message %s on topic %s', payload, topic)
225
225
 
226
- def subscribe(self, topic: str, persist: bool) -> None:
226
+ def subscribe(self, topic: str, persist: bool, queue_name: str) -> None:
227
227
  """Subscribe to a topic.
228
228
 
229
229
  topic: system-of-system hierarchy. In AMQP parlance this gets translated to the routing key.
230
230
  persist: If True, we will create an idempotent queue name which should persist
231
231
  even on broker or application shutdown. If False, we will allow the server to create a unique
232
232
  queue name, and the queue will be destroyed once the associated channel is closed.
233
+ queue_name: The name of the queue to subscribe to.
233
234
  """
234
235
  topic = _hierarchy_2_amqp(topic)
235
236
  cb = functools.partial(
236
- self._create_queue, channel=self._channel_in, topic=topic, persist=persist
237
+ self._create_queue,
238
+ channel=self._channel_in,
239
+ topic=topic,
240
+ persist=persist,
241
+ queue_name=queue_name,
237
242
  )
238
243
  self._connection.ioloop.add_callback_threadsafe(cb)
239
244
 
@@ -55,7 +55,7 @@ class BrokerClient(Protocol):
55
55
  """
56
56
  ...
57
57
 
58
- def subscribe(self, topic: str, persist: bool) -> None:
58
+ def subscribe(self, topic: str, persist: bool, queue_name: str) -> None:
59
59
  """Subscribe to a topic over the pre-existing connection (via connect()).
60
60
 
61
61
  This function should ALSO be called by reconnect handlers, and not just directly.
@@ -64,6 +64,7 @@ class BrokerClient(Protocol):
64
64
  Args:
65
65
  topic: Topic to subscribe to.
66
66
  persist: Whether or not the queue subscribed to is intended to be long-lived.
67
+ queue_name: The name of the queue to subscribe to. Used or ignored depending on the protocol.
67
68
  """
68
69
  ...
69
70
 
@@ -35,7 +35,6 @@ _MQTT_MAX_RETRIES = 10
35
35
  # this will be a breaking change, so only add it when ready to break
36
36
  def _hierarchy_2_mqtt(hierarchy: str) -> str:
37
37
  """Take the hierarchy string format saved in the Service and map it to the MQTT topic format. Currently just covers wildcards."""
38
- # return hierarchy.replace('#', '+')
39
38
  return hierarchy.replace('*', '+')
40
39
 
41
40
 
@@ -166,12 +165,13 @@ class MQTTClient(BrokerClient):
166
165
  resolved_topic, payload, qos=self._max_supported_qos if persist else 0, properties=props
167
166
  )
168
167
 
169
- def subscribe(self, topic: str, persist: bool) -> None:
168
+ def subscribe(self, topic: str, persist: bool, queue_name: str) -> None: # noqa: ARG002
170
169
  """Subscribe to a topic over the pre-existing connection (via connect()).
171
170
 
172
171
  Args:
173
172
  topic: Topic to subscribe to.
174
173
  persist: Determine if the associated message queue of the topic is long-lived (True) or not (False)
174
+ queue_name: The name of the queue to subscribe to. Ignored with current MQTT implementation.
175
175
  """
176
176
  resolved_topic = _hierarchy_2_mqtt(topic)
177
177
  # NOTE: RabbitMQ only works with QOS of 1 and 0, and seems to convert QOS2 to QOS1
@@ -302,7 +302,7 @@ class MQTTClient(BrokerClient):
302
302
 
303
303
  self._connected_flag.set()
304
304
  for topic, topic_handler in self._control_plane_manager.get_all_subscription_channels():
305
- self.subscribe(topic, topic_handler.topic_persist)
305
+ self.subscribe(topic, topic_handler.topic_persist, topic_handler.queue_name)
306
306
  else:
307
307
  # This will generally suggest a misconfiguration
308
308
  self._connected = False
@@ -115,7 +115,7 @@ class ControlPlaneManager:
115
115
  topic_handler.queue_name = queue_name
116
116
  if self.is_connected():
117
117
  for provider in self._control_providers:
118
- provider.subscribe(channel, persist)
118
+ provider.subscribe(channel, persist, queue_name)
119
119
 
120
120
  def remove_subscription_channel(self, channel: str) -> bool:
121
121
  """Stop subscribing to a channel on all configured brokers.
@@ -0,0 +1,77 @@
1
+ """This module contains the binary specification for an INTERSECT message IF the protocol does not provide any built-in header support. If it does, use the built-in functionality of the protocol.
2
+
3
+ Some protocols do not have any built-in header support, leaving it up to us to define the binary structure of the message. We want to avoid "chunking" messages into multiple parts, so a message should be guaranteed to include all metadata.
4
+ """
5
+
6
+ from intersect_sdk_common import IntersectApplicationError
7
+
8
+ _HEADER_KV_SEPARATOR = b'\x02'
9
+ """Indicates end of a header key and start of a header value.
10
+
11
+ Used because applications should generally assign no special meaning to this byte, and this byte has no reason to appear in header keys or values.
12
+ """
13
+ _HEADER_VALUE_SEPARATOR = b'\x03'
14
+ """Indicates end of a header value and start of the next header key.
15
+
16
+ Used because applications should generally assign no special meaning to this byte, and this byte has no reason to appear in header keys or values.
17
+ """
18
+ _PAYLOAD_SEPARATOR = b'\x01'
19
+ """Indicates end of headers and start of the payload.
20
+
21
+ Used because applications should generally assign no special meaning to this byte, and this byte has no reason to appear in header keys or values.
22
+ """
23
+
24
+ _TOTAL_REASONABLE_HEADER_BYTES = 131072
25
+ """The total number of bytes that should be reasonably expected to be used for header keys, values, and header separators combined. This provides applications with some level of DOS protection.
26
+
27
+ It is rare in practice for ANY application to use this number of bytes for the total amount of headers, for example http2_max_header_size in NGINX is rarely set above 128KB
28
+ """
29
+
30
+ CONTENT_TYPE_HEADER_KEY = 'content_type'
31
+ CONTENT_TYPE_HEADER_KEY_BYTES = CONTENT_TYPE_HEADER_KEY.encode()
32
+
33
+
34
+ def create_binary_message(body: bytes, content_type: str, headers: dict[str, str]) -> bytes:
35
+ """Create a binary message from the body, headers, and content type."""
36
+ return b''.join(
37
+ [
38
+ # content-type 'header' first (this is generally handled separately from other headers in many protocols)
39
+ CONTENT_TYPE_HEADER_KEY_BYTES,
40
+ _HEADER_KV_SEPARATOR,
41
+ content_type.encode(),
42
+ _HEADER_VALUE_SEPARATOR if len(headers) else b'',
43
+ # headers
44
+ _HEADER_VALUE_SEPARATOR.join(
45
+ _HEADER_KV_SEPARATOR.join([key.encode(), value.encode()])
46
+ for key, value in headers.items()
47
+ ),
48
+ # end of headers
49
+ _PAYLOAD_SEPARATOR,
50
+ # body
51
+ body,
52
+ ]
53
+ )
54
+
55
+
56
+ def parse_binary_message(message: bytes) -> tuple[bytes, str, dict[str, str]]:
57
+ """Parse a binary message into its body, content type, and headers."""
58
+ # IMPORTANT!!! ----- Total length of header keys and values combined should be limited to first several bytes, terminate header search early if headers aren't a reasonable length.
59
+ payload_sep_location = message.find(_PAYLOAD_SEPARATOR, 0, _TOTAL_REASONABLE_HEADER_BYTES)
60
+ if payload_sep_location == -1:
61
+ msg = 'Probable malformed message: no payload separator found in first expected bytes, .'
62
+ raise IntersectApplicationError(msg)
63
+ header_string = message[:payload_sep_location]
64
+ headers = {
65
+ key.decode(): value.decode()
66
+ for key, value in (
67
+ header.split(_HEADER_KV_SEPARATOR)
68
+ for header in header_string.split(_HEADER_VALUE_SEPARATOR)
69
+ )
70
+ }
71
+ try:
72
+ content_type = headers.pop(CONTENT_TYPE_HEADER_KEY)
73
+ except KeyError as e:
74
+ msg = 'Probable malformed message: no content_type header found in message, discarding it.'
75
+ raise IntersectApplicationError(msg) from e
76
+
77
+ return message[payload_sep_location + 1 :], content_type, headers