Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/omnibase_infra/event_bus/kafka_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def build_aiokafka_auth_kwargs(config: ModelKafkaEventBusConfig) -> dict[str, ob
kwargs["sasl_mechanism"] = "OAUTHBEARER"
kwargs["sasl_oauth_token_provider"] = MSKTokenProvider(region=config.msk_region)

if config.ssl_ca_file is not None:
if config.security_protocol in ("SSL", "SASL_SSL"):
kwargs["ssl_context"] = ssl.create_default_context(cafile=config.ssl_ca_file)

return kwargs
Expand Down
17 changes: 17 additions & 0 deletions tests/unit/event_bus/test_msk_auth_direct_clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,23 @@ def test_ssl_ca_file_builds_aiokafka_ssl_context() -> None:
create_context.assert_called_once_with(cafile="/etc/ssl/certs/custom-ca.pem")


def test_msk_iam_builds_default_aiokafka_ssl_context() -> None:
with patch("ssl.create_default_context") as create_context:
context = object()
create_context.return_value = context
config = ModelKafkaEventBusConfig(
bootstrap_servers="b-1.example:9098",
security_protocol="SASL_SSL",
sasl_mechanism="AWS_MSK_IAM",
msk_region="us-east-1",
)

kwargs = build_aiokafka_auth_kwargs(config)

assert kwargs["ssl_context"] is context
create_context.assert_called_once_with(cafile=None)


@pytest.mark.asyncio
async def test_provider_kafka_producer_passes_msk_auth_kwargs() -> None:
auth_kwargs = {"security_protocol": "SASL_SSL", "sasl_mechanism": "OAUTHBEARER"}
Expand Down
Loading