Skip to content

Set the current host in the SASL configs #2633

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 22, 2025
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
1 change: 1 addition & 0 deletions kafka/conn.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ def __init__(self, host, port, afi, **configs):
for key in self.config:
if key in configs:
self.config[key] = configs[key]
self.config['host'] = host
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is only used in sasl mechanisms, I think it would be better to limit the scope. How about adding host=self.host on L316 instead?


self.node_id = self.config.pop('node_id')

Expand Down
10 changes: 10 additions & 0 deletions test/test_conn.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,3 +386,13 @@ def test_maybe_throttle(conn):

time.return_value = 3000
assert not conn.throttled()


def test_host_in_sasl_config():
hostname = 'example.org'
port = 9092
for security_protocol in ('SASL_PLAINTEXT', 'SASL_SSL'):
with mock.patch("kafka.conn.get_sasl_mechanism") as get_sasl_mechanism:
BrokerConnection(hostname, port, socket.AF_UNSPEC, security_protocol=security_protocol)
call_config = get_sasl_mechanism.mock_calls[1].kwargs
assert call_config['host'] == hostname
Loading