Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ ansible_cache/
roles
venv
build/

## IDE specific files/folders
.idea
38 changes: 7 additions & 31 deletions module_utils/kafka_lib_acl.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def process_module_acl(module):
'acl_resource_type': params['acl_resource_type'],
'state': params['state']
}]

params['mark_others_as_absent'] = False
Copy link
Collaborator

@ryarnyah ryarnyah May 6, 2022

Choose a reason for hiding this comment

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

mark_others_as_absent will always be False when calling from kafka_acl module (see line 43)

process_module_acls(module, params)


Expand Down Expand Up @@ -62,40 +62,16 @@ def process_module_acls(module, params=None):
'instead'
)

if len(acls) > 1:
acl_resource = ACLResource(
acl_resources_found = manager.describe_acls(
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure we need to get all ACLs when kafka_acl module is called. When you have many ACLs it might be very slow to retrieve them.

Maybe a more elegant solution might be to extract the if directly inside callers to pass it to process_module_acls? What do you think of it? @steppi91 @StephenSorriaux ?

ACLResource(
resource_type=ACLResourceType.ANY,
operation=ACLOperation.ANY,
permission_type=ACLPermissionType.ANY,
pattern_type=ACLPatternType.ANY,
name=None,
principal=None,
host=None
)
else:
acl = acls[0]

acl_name = acl['name']
acl_resource_type = acl['acl_resource_type']
acl_principal = acl['acl_principal']
acl_operation = acl['acl_operation']
acl_permission = acl['acl_permission']
acl_pattern_type = acl['acl_pattern_type']
acl_host = acl['acl_host']

acl_resource = ACLResource(
resource_type=ACLResourceType.from_name(acl_resource_type),
operation=ACLOperation.from_name(acl_operation),
permission_type=ACLPermissionType.from_name(
acl_permission
),
pattern_type=ACLPatternType.from_name(acl_pattern_type),
name=acl_name,
principal=acl_principal,
host=acl_host
)
acl_resource_found = manager.describe_acls(
acl_resource, api_version
), api_version
)

acls_marked_present = [ACLResource(
Expand Down Expand Up @@ -132,14 +108,14 @@ def process_module_acls(module, params=None):
return

acls_to_add = [acl for acl in acls_marked_present
if acl not in acl_resource_found]
if acl not in acl_resources_found]
acls_to_delete = [acl for acl in acls_marked_absent
if acl in acl_resource_found]
if acl in acl_resources_found]

# Cleanup others acls
if mark_others_as_absent:
acls_to_delete.extend(
[acl for acl in acl_resource_found
[acl for acl in acl_resources_found
if acl not in acls_marked_present + acls_marked_absent]
)
if len(acls_to_add) > 0:
Expand Down