Skip to content

Commit

Permalink
fix: Properly load auth settings for producer/consumer (#27)
Browse files Browse the repository at this point in the history
Common auth settings were ignored since 0.3.1.
  • Loading branch information
timmc-edx authored Aug 24, 2022
1 parent ee14619 commit cfb9710
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 3 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ Unreleased

*

[0.4.2] - 2022-08-24
********************

Fixed
=====

* Properly load auth settings for producer/consumer. (Auth settings were ignored since 0.3.1.)

[0.4.1] - 2022-08-18
********************

Expand Down
2 changes: 1 addition & 1 deletion edx_event_bus_kafka/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
Kafka implementation for Open edX event bus.
"""

__version__ = '0.4.1'
__version__ = '0.4.2'
6 changes: 4 additions & 2 deletions edx_event_bus_kafka/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ def create_schema_registry_client():
def load_common_settings() -> Optional[dict]:
"""
Load common settings, a base for either producer or consumer configuration.
Warns and returns None if essential settings are missing.
"""
bootstrap_servers = getattr(settings, 'EVENT_BUS_KAFKA_BOOTSTRAP_SERVERS', None)
if bootstrap_servers is None:
Expand All @@ -55,8 +57,8 @@ def load_common_settings() -> Optional[dict]:
'bootstrap.servers': bootstrap_servers,
}

key = getattr(base_settings, 'EVENT_BUS_KAFKA_API_KEY', None)
secret = getattr(base_settings, 'EVENT_BUS_KAFKA_API_SECRET', None)
key = getattr(settings, 'EVENT_BUS_KAFKA_API_KEY', None)
secret = getattr(settings, 'EVENT_BUS_KAFKA_API_SECRET', None)

if key and secret:
base_settings.update({
Expand Down
51 changes: 51 additions & 0 deletions edx_event_bus_kafka/tests/test_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
"""
Test common configuration loading.
"""

from unittest import TestCase

from django.test.utils import override_settings

from edx_event_bus_kafka import config

# See https://github.com/openedx/event-bus-kafka/blob/main/docs/decisions/0005-optional-import-of-confluent-kafka.rst
try:
from confluent_kafka.schema_registry import SchemaRegistryClient
except ImportError: # pragma: no cover
pass


class TestSchemaRegistryClient(TestCase):
def test_unconfigured(self):
assert config.create_schema_registry_client() is None

def test_configured(self):
with override_settings(EVENT_BUS_KAFKA_SCHEMA_REGISTRY_URL='http://localhost:12345'):
assert isinstance(config.create_schema_registry_client(), SchemaRegistryClient)


class TestCommonSettings(TestCase):
def test_unconfigured(self):
assert config.load_common_settings() is None

def test_minimal(self):
with override_settings(
EVENT_BUS_KAFKA_BOOTSTRAP_SERVERS='http://localhost:54321',
):
assert config.load_common_settings() == {
'bootstrap.servers': 'http://localhost:54321',
}

def test_full(self):
with override_settings(
EVENT_BUS_KAFKA_BOOTSTRAP_SERVERS='http://localhost:54321',
EVENT_BUS_KAFKA_API_KEY='some_other_key',
EVENT_BUS_KAFKA_API_SECRET='some_other_secret',
):
assert config.load_common_settings() == {
'bootstrap.servers': 'http://localhost:54321',
'sasl.mechanism': 'PLAIN',
'security.protocol': 'SASL_SSL',
'sasl.username': 'some_other_key',
'sasl.password': 'some_other_secret',
}

0 comments on commit cfb9710

Please sign in to comment.