Tomodachi

Latest version: v0.27.0

Safety actively analyzes 619528 Python packages for vulnerabilities to keep your Python projects secure.

Scan your dependencies

Page 1 of 24

1.1.0

New features

- ([180](https://github.com/filipsnastins/tomodachi-testcontainers/pull/180))
`clients.SNSSQSTestClient`: `SNSSQSTestClient.receive` now returns message attributes.
The returned message is now wrapped in a `SQSMessage` dataclass, containing the `payload` and `message_attributes` fields.
It's a small breaking change for clients that use the `receive` method, because the message's payload is now wrapped in the `payload` attribute.

1.0.1

Fixes

- ([179](https://github.com/filipsnastins/tomodachi-testcontainers/pull/179))
`WireMockContainer`: fixed `mapping_stubs` and `mapping_files` argument precedence over environment variables.

1.0.0

New features

- New documentation available at <https://filipsnastins.github.io/tomodachi-testcontainers/>

- `WireMockContainer`: adds `wiremock_container` pytest fixture.

- `WireMockContainer`: adds `reset_wiremock_container_on_teardown` pytest fixture that deletes all WireMock stub mappings after each test.

- `edge_port` in all Testcontainers now defaults to `None`.
When it's `None`, the container will be started with a random port generated by `tomodachi_testcontainers.utils.get_available_port()`.

- `tomodachi_testcontainers.pytest` module removed, and the code moved one level up:

- `tomodachi_testcontainers.fixtures`
- `tomodachi_testcontainers.assertions`
- `tomodachi_testcontainers.async_probes`

Breaking changes

- Removed the leading underscore from `restart_localstack_container_on_teardown` and `reset_moto_container_on_teardown` pytest fixture names.

- Fixtures `moto_snssqs_tc` and `localstack_snssqs_tc` are now session-scoped (`pytest.fixture(scope="session")`).

- Fixture `testcontainers_docker_image` renamed to `testcontainer_image`.

- Renamed environment variables:

| Old name | New name |
| :--------------------------------------------- | :----------------------------------- |
| `TOMODACHI_TESTCONTAINER_DOCKER_NETWORK` | `TESTCONTAINER_DOCKER_NETWORK` |
| `TOMODACHI_TESTCONTAINER_DOCKERFILE_PATH` | `TESTCONTAINER_DOCKERFILE_PATH` |
| `TOMODACHI_TESTCONTAINER_DOCKER_BUILD_CONTEXT` | `TESTCONTAINER_DOCKER_BUILD_CONTEXT` |
| `TOMODACHI_TESTCONTAINER_DOCKER_BUILD_TARGET` | `TESTCONTAINER_DOCKER_BUILD_TARGET` |
| `TOMODACHI_TESTCONTAINER_IMAGE_ID` | `TESTCONTAINER_IMAGE_ID` |

0.27.1

- ...

0.27.0

**Send messages directly to SQS queues (SQS.SendMessage)**

- Added the function `tomodachi.sqs_send_message` (`tomodachi.aws_sns_sqs_send_message`) to send a message directly to an SQS queue. It mostly works the same way as the `tomodachi.sns_publish` (`tomodachi.aws_sns_sqs_publish`) function, but sends a message directly to the specified SQS queue.

This is useful when you know the recipient queue of a message, for example when manually sending messages to a dead-letter queue or to do command-like messaging instead of event-based messaging.

- The message body of `tomodachi.sqs_send_message` calls is by default built using the `tomodachi.transport.aws_sns_sqs.MessageBodyFormatter` implementation, which will encode the message body as JSON and embed it within the `"Message"` property also using the service specified message envelope functionality.

The message includes some additional properties, mimicing how SNS notifications are represented when they are sent to subscribed SQS queues (with the exception that these messages are of type `"Message"` to differentiate from SNS notifications that are by AWS typed `"Notification"`.

For custom or more advanced setups requiring more flexibility, the implementation can be overridden by providing a callable to the `message_body_formatter` keyword argument of `sqs_send_message` calls. The callable receives a message context object and returns the raw message (as a string) that will be sent to SQS as the message body.

Setting `message_body_formatter` to `None` will disable default message body formatting (and incidentally also the message envelope builder), causing the message body to be as is specified within the `data` argument to the `sqs_send_message` call.

- Trying to send messages to an SQS queue that does not exist will result in a `tomodachi.transport.aws_sns_sqs.QueueDoesNotExistError` exception being raised, which can be caught also by `tomodachi.transport.aws_sns_sqs.AWSSNSSQSException`, `botocore.exceptions.ClientError` or `<botocore_sqs_client>.exceptions.QueueDoesNotExist`.

**Message attributes' improvements and fixes**

- Receives and propagates message attributes for all messages received on a queue, which means message attribute propagation will work for messages published to SNS, using either raw message delivery or not, and/or messages that were directly sent to SQS via SQS.SendMessage calls.

Currently, messages on SQS queues consumed and parsed by tomodachi services still need to be JSON formatted and be embedded within the `"Message"` property (which is how SNS notification messages are represented by default, unless a queue is setup for raw message delivery).

- Fixes a bug that was causing message attributes in binary form to be invalidly processed.

**OTEL updates**

- OTEL auto instrumentation for the new `tomodachi.sqs_send_message` functionality.
- OTEL attributes for AWS SNS+SQS messaging have been updated according to the latest OTEL semantic conventions, where the original publish destination is recorded as `messaging.destination_publish.name`.
- OTEL metrics for AWS SNS+SQS messaging uses the new metric instrument name `messaging.aws_sqs.duration`, which was previously named `messaging.amazonsqs.duration`.

**Type hints and input validation**

- Additional support for the `types-aiobotocore-*` packages to provide improved type hints internally.
- AWS credentials provided to the aiobotocore connector are using stricter type hint annotations.
- Stricter argument validation when requesting aiobotocore connector clients to prevent issues caused by a mistyped AWS service, protecting against accidental use of wrong client for a specific service.

**Handler arguments**

- Added `message_type` (`str | None`) to the list of keyword argument provided transport values that can be used in function signatures for AWS SNS+SQS handlers. Holds the value `"Notification"` for messages received as part of an SNS notification, unless the queue uses raw message delivery. In other cases the value is set to the value from a message body's JSON property `"Type"` if it exists.
- Tailored for more advanced workflows, where more flexibility is needed, `raw_message_body` (`str`) has also been added to the list of keyword argument provided transport values for AWS SNS+SQS handlers. The `raw_message_body` value is set to the full content (non-decoded, as a string) from a received message' `"Body"`, which can be used to implement custom listener with greater access to the raw message data.
- Fixes an issue where the `topic` argument to message handlers in functions was always populated with the value of the `topic` argument to the `tomodachi.aws_sns_sqs` decorator, even if the message was sent to a different topic. The `topic` argument to message handlers in functions will now be populated with the actual topic name destination to where the message was published, if published via SNS. If the message was not published to a topic, the value is set to empty string.

**Other**

- Fixes issue where different OTEL tracers for the same `TracerProvider` could end up with different resource attributes, iff a service class' `name` attribute's value were to be used as the `service.name` OTEL resource attribute (instead set to `"unknown_service"` for tracers that were created before the service initialized).
- Multi-service execution won't accurately distinguish the service name of OTEL tracers, OTEL meters and OTEL loggers. In the rare case where there's multiple `tomodachi` services started within the same Python process, the name from the *first* instrumented service class will now be used as the `service.name` OTEL resource attribute for *all* tracers derived from the same tracer provider. The recommended solution if this is an issue, is to split the services into separate processes instead.
- Refactoring of `tomodachi.aws_sns_sqs.get_queue_url` and `tomodachi.aws_sns_sqs.get_queue_url_from_arn` with better support for additional types of input and/or potentially prefixing of queues. The function also now caches the queue URL to avoid unnecessary calls to the AWS API.
- Support for `aiobotocore` 2.10.x releases and 2.11.x releases.
- Documented the lifecycle termination process for services, for example when they receive a `SIGINT` or `SIGTERM` signal. Added details describing how handlers are awaited and for how long as part of the graceful termination sequence.
- Converted repo documentation from RST format to Markdown. It finally happened.

0.26.4

- Fixes an issue with the custom backport class of `ConsoleRenderer` extending `structlog.dev.ConsoleRenderer` (which caused an exception to be raised upon service start, when using `structlog` 23.3.0 or 24.1.0).
- Uses the native `ConsoleRenderer` class from `structlog` when a modern version of `structlog` is used (23.3.0 or newer).

Page 1 of 24

© 2024 Safety CLI Cybersecurity Inc. All Rights Reserved.