summaryrefslogtreecommitdiff
path: root/kafka/admin/acl_resource.py
diff options
context:
space:
mode:
authorTyler Lubeck <tyler@tylerlubeck.com>2019-12-29 15:51:41 -0800
committerDana Powers <dana.powers@gmail.com>2019-12-29 15:51:41 -0800
commitbc25877a6bf4d579508b1ee9df3ca7870757f029 (patch)
tree1f7b8f24bf81b57a9af5c4b41cf99d3eb18aae14 /kafka/admin/acl_resource.py
parent5c477f2642a4d0b6bcb4010447a5e113fedf3e7f (diff)
downloadkafka-python-bc25877a6bf4d579508b1ee9df3ca7870757f029.tar.gz
Implement __eq__ and __hash__ for ACL objects (#1955)
Diffstat (limited to 'kafka/admin/acl_resource.py')
-rw-r--r--kafka/admin/acl_resource.py34
1 files changed, 33 insertions, 1 deletions
diff --git a/kafka/admin/acl_resource.py b/kafka/admin/acl_resource.py
index 7a012d2..fd997a1 100644
--- a/kafka/admin/acl_resource.py
+++ b/kafka/admin/acl_resource.py
@@ -112,6 +112,24 @@ class ACLFilter(object):
resource=self.resource_pattern
)
+ def __eq__(self, other):
+ return all((
+ self.principal == other.principal,
+ self.host == other.host,
+ self.operation == other.operation,
+ self.permission_type == other.permission_type,
+ self.resource_pattern == other.resource_pattern
+ ))
+
+ def __hash__(self):
+ return hash((
+ self.principal,
+ self.host,
+ self.operation,
+ self.permission_type,
+ self.resource_pattern,
+ ))
+
class ACL(ACLFilter):
"""Represents a concrete ACL for a specific ResourcePattern
@@ -181,6 +199,20 @@ class ResourcePatternFilter(object):
self.pattern_type.name
)
+ def __eq__(self, other):
+ return all((
+ self.resource_type == other.resource_type,
+ self.resource_name == other.resource_name,
+ self.pattern_type == other.pattern_type,
+ ))
+
+ def __hash__(self):
+ return hash((
+ self.resource_type,
+ self.resource_name,
+ self.pattern_type
+ ))
+
class ResourcePattern(ResourcePatternFilter):
"""A resource pattern to apply the ACL to
@@ -209,4 +241,4 @@ class ResourcePattern(ResourcePatternFilter):
if self.pattern_type in [ACLResourcePatternType.ANY, ACLResourcePatternType.MATCH]:
raise IllegalArgumentError(
"pattern_type cannot be {} on a concrete ResourcePattern".format(self.pattern_type.name)
- ) \ No newline at end of file
+ )