Skip to content

Commit 6f40051

Browse files
author
Ulrik Johansson
committed
Require resource type objects when creating an ACLResource
1 parent 7c7f5bf commit 6f40051

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

kafka/admin/acl_resource.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from __future__ import absolute_import
2+
from kafka.errors import IllegalArgumentError
23

34
# enum in stdlib as of py3.4
45
try:
@@ -69,17 +70,17 @@ def __init__(
6970
pattern_type=ACLResourcePatternType.LITERAL
7071
):
7172
if not isinstance(resource_type, ACLResourceType):
72-
resource_type = ACLResourceType[str(resource_type).upper()] # pylint: disable-msg=unsubscriptable-object
73+
raise IllegalArgumentError("resource_param must be of type ACLResourceType")
7374
self.resource_type = resource_type
7475
if not isinstance(operation, ACLOperation):
75-
operation = ACLOperation[str(operation).upper()] # pylint: disable-msg:unsubscriptable-object
76+
raise IllegalArgumentError("operation must be of type ACLOperation")
7677
self.operation = operation
7778
if not isinstance(permission_type, ACLPermissionType):
78-
permission_type = ACLPermissionType[str(permission_type).upper()] # pylint: disable-msg=unsubscriptable-object
79+
raise IllegalArgumentError("permission_type must be of type ACLPermissionType")
7980
self.permission_type = permission_type
8081
self.name = name
8182
self.principal = principal
8283
self.host = host
8384
if not isinstance(pattern_type, ACLResourcePatternType):
84-
pattern_type = ACLResourcePatternType[str(pattern_type).upper()] # pylint: disable-msg=unsubscriptable-object
85+
raise IllegalArgumentError("pattern_type must be of type ACLResourcePatternType")
8586
self.pattern_type = pattern_type

test/test_admin.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,23 @@ def test_new_partitions():
2727

2828

2929
def test_acl_resource():
30-
good_resource = kafka.admin.ACLResource("TOPIC", "ALL", "ALLOW", "foo",
31-
"User:bar", "*", "LITERAL")
30+
good_resource = kafka.admin.ACLResource(
31+
kafka.admin.ACLResourceType.TOPIC,
32+
kafka.admin.ACLOperation.ALL,
33+
kafka.admin.ACLPermissionType.ALLOW,
34+
"foo",
35+
"User:bar",
36+
"*",
37+
kafka.admin.ACLResourcePatternType.LITERAL
38+
)
3239
assert(good_resource.resource_type == kafka.admin.ACLResourceType.TOPIC)
3340
assert(good_resource.operation == kafka.admin.ACLOperation.ALL)
3441
assert(good_resource.permission_type == kafka.admin.ACLPermissionType.ALLOW)
3542
assert(good_resource.pattern_type == kafka.admin.ACLResourcePatternType.LITERAL)
3643

44+
with pytest.raises(IllegalArgumentError):
45+
bad_resource = kafka.admin.ACLResource("TOPIC", "ALL", "ALLOW", "foo", "User:bar", "*", "LITERAL")
46+
3747
def test_new_topic():
3848
with pytest.raises(IllegalArgumentError):
3949
bad_topic = kafka.admin.NewTopic('foo', -1, -1)

0 commit comments

Comments
 (0)