Skip to content

Commit de60469

Browse files
authored
kafka.admin: Fix DESCRIBE_TOKENS ACLOperation enum; support authorized_operations=None (#2731)
1 parent 164b958 commit de60469

5 files changed

Lines changed: 21 additions & 8 deletions

File tree

kafka/admin/acl_resource.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class ACLOperation(IntEnum):
3838
ALTER_CONFIGS = 11,
3939
IDEMPOTENT_WRITE = 12,
4040
CREATE_TOKENS = 13,
41-
DESCRIBE_TOKENS = 13
41+
DESCRIBE_TOKENS = 14
4242

4343

4444
class ACLPermissionType(IntEnum):

kafka/admin/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -532,10 +532,10 @@ def delete_topics(self, topics, timeout_ms=None):
532532

533533
def _process_metadata_response(self, metadata_response):
534534
obj = metadata_response.to_object()
535-
if 'authorized_operations' in obj:
535+
if obj.get('authorized_operations', None) is not None:
536536
obj['authorized_operations'] = list(map(lambda acl: acl.name, valid_acl_operations(obj['authorized_operations'])))
537537
for t in obj['topics']:
538-
if 'authorized_operations' in t:
538+
if t.get('authorized_operations', None) is not None:
539539
t['authorized_operations'] = list(map(lambda acl: acl.name, valid_acl_operations(t['authorized_operations'])))
540540
return obj
541541

kafka/protocol/types.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,8 @@ def decode(cls, data):
339339

340340
@classmethod
341341
def encode(cls, value):
342+
if value is None:
343+
value = {}
342344
ret = UnsignedVarInt32.encode(len(value))
343345
for k, v in value.items():
344346
# do we allow for other data types ?? It could get complicated really fast
@@ -388,10 +390,15 @@ def decode(self, data):
388390
class BitField(AbstractType):
389391
@classmethod
390392
def decode(cls, data):
391-
return cls.from_32_bit_field(Int32.decode(data))
393+
vals = cls.from_32_bit_field(Int32.decode(data))
394+
if vals == {31}:
395+
vals = None
396+
return vals
392397

393398
@classmethod
394399
def encode(cls, vals):
400+
if vals is None:
401+
vals = {31}
395402
# to_32_bit_field returns unsigned val, so we need to
396403
# encode >I to avoid crash if/when byte 31 is set
397404
# (note that decode as signed still works fine)

test/protocol/test_bit_field.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,14 @@
66

77

88
@pytest.mark.parametrize(('test_set',), [
9-
(set([0, 1, 5, 10, 31]),),
10-
(set(range(32)),),
9+
(set([0, 1, 5, 10]),),
10+
(set(range(15)),),
11+
(None,),
1112
])
1213
def test_bit_field(test_set):
1314
assert BitField.decode(io.BytesIO(BitField.encode(test_set))) == test_set
15+
16+
17+
def test_bit_field_null():
18+
assert BitField.from_32_bit_field(-2147483648) == {31}
19+
assert BitField.decode(io.BytesIO(BitField.encode({31}))) is None

test/protocol/test_parser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
'response': (
7373
b'\x00\x00\x00E\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\tlocalhost\x00\x00\xb9}\xff\xff\x00\x1634wjNp3hRJixCRvMlK9Znw\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00',
7474
3,
75-
MetadataResponse[8](throttle_time_ms=0, brokers=[(0, 'localhost', 47485, None)], cluster_id='34wjNp3hRJixCRvMlK9Znw', controller_id=0, topics=[], authorized_operations={31}),
75+
MetadataResponse[8](throttle_time_ms=0, brokers=[(0, 'localhost', 47485, None)], cluster_id='34wjNp3hRJixCRvMlK9Znw', controller_id=0, topics=[], authorized_operations=None),
7676
),
7777
},
7878
{
@@ -83,7 +83,7 @@
8383
'response': (
8484
b'\x00\x00\x00E\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\tlocalhost\x00\x00\xb9}\xff\xff\x00\x1634wjNp3hRJixCRvMlK9Znw\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00',
8585
4,
86-
MetadataResponse[8](throttle_time_ms=0, brokers=[(0, 'localhost', 47485, None)], cluster_id='34wjNp3hRJixCRvMlK9Znw', controller_id=0, topics=[], authorized_operations={31}),
86+
MetadataResponse[8](throttle_time_ms=0, brokers=[(0, 'localhost', 47485, None)], cluster_id='34wjNp3hRJixCRvMlK9Znw', controller_id=0, topics=[], authorized_operations=None),
8787
),
8888
}
8989
),

0 commit comments

Comments
 (0)