-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add ACL protocol and admin methods #1646
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5132fa8
Add KafkaAdmin ACL methods
628cc48
Add basic test for AclResource
fc54f94
Use new client errors
7fa3c51
Bugfix, match against correct schema
ae9ab37
Send Acl requests to least loaded node
0349bc9
Capitalize ACL types properly
7c7f5bf
Fix pep-8 blank line issue
6f40051
Require resource type objects when creating an ACLResource
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
from __future__ import absolute_import | ||
from kafka.errors import IllegalArgumentError | ||
|
||
# enum in stdlib as of py3.4 | ||
try: | ||
from enum import IntEnum # pylint: disable=import-error | ||
except ImportError: | ||
# vendored backport module | ||
from kafka.vendor.enum34 import IntEnum | ||
|
||
|
||
class ACLResourceType(IntEnum): | ||
"""An enumerated type of config resources""" | ||
|
||
ANY = 1, | ||
BROKER = 4, | ||
DELEGATION_TOKEN = 6, | ||
GROUP = 3, | ||
TOPIC = 2, | ||
TRANSACTIONAL_ID = 5 | ||
|
||
class ACLOperation(IntEnum): | ||
"""An enumerated type of acl operations""" | ||
|
||
ANY = 1, | ||
ALL = 2, | ||
READ = 3, | ||
WRITE = 4, | ||
CREATE = 5, | ||
DELETE = 6, | ||
ALTER = 7, | ||
DESCRIBE = 8, | ||
CLUSTER_ACTION = 9, | ||
DESCRIBE_CONFIGS = 10, | ||
ALTER_CONFIGS = 11, | ||
IDEMPOTENT_WRITE = 12 | ||
|
||
|
||
class ACLPermissionType(IntEnum): | ||
"""An enumerated type of permissions""" | ||
|
||
ANY = 1, | ||
DENY = 2, | ||
ALLOW = 3 | ||
|
||
class ACLResourcePatternType(IntEnum): | ||
"""An enumerated type of resource patterns""" | ||
|
||
ANY = 1, | ||
MATCH = 2, | ||
LITERAL = 3, | ||
PREFIXED = 4 | ||
|
||
class ACLResource(object): | ||
"""A class for specifying config resources. | ||
Arguments: | ||
resource_type (ConfigResourceType): the type of kafka resource | ||
name (string): The name of the kafka resource | ||
configs ({key : value}): A maps of config keys to values. | ||
""" | ||
|
||
def __init__( | ||
self, | ||
resource_type, | ||
operation, | ||
permission_type, | ||
name=None, | ||
principal=None, | ||
host=None, | ||
pattern_type=ACLResourcePatternType.LITERAL | ||
): | ||
if not isinstance(resource_type, ACLResourceType): | ||
raise IllegalArgumentError("resource_param must be of type ACLResourceType") | ||
self.resource_type = resource_type | ||
if not isinstance(operation, ACLOperation): | ||
raise IllegalArgumentError("operation must be of type ACLOperation") | ||
self.operation = operation | ||
if not isinstance(permission_type, ACLPermissionType): | ||
raise IllegalArgumentError("permission_type must be of type ACLPermissionType") | ||
self.permission_type = permission_type | ||
self.name = name | ||
self.principal = principal | ||
self.host = host | ||
if not isinstance(pattern_type, ACLResourcePatternType): | ||
raise IllegalArgumentError("pattern_type must be of type ACLResourcePatternType") | ||
self.pattern_type = pattern_type |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style nit: pep8 suggests 2 blank lines between imports and code