Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow also posix and community.general Ansible modules #279

Merged
Merged
Changes from all 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
2 changes: 2 additions & 0 deletions static-checks/ansible/allowed-modules/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ def process_task(task, all_allowed_modules):
found_allowed_modules.update(process_task(block_task, all_allowed_modules))
else:
keywords = set(kw.replace('ansible.builtin.', '') for kw in original_keywords)
keywords = set(kw.replace('community.general.', '') for kw in keywords)
Copy link
Contributor

Choose a reason for hiding this comment

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

What about something like this:

keywords = set()
for kw in original_keywords:
    keywords.add(re.sub(r'(ansible.builtin.|community.general.|ansible.posix.)', r'', kw))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changes 3 similar lines to 3 different lines and that's fine. But adds complexity and reduces readability. So I'd stay with my solution.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's probably pointless now, but maybe this would have been a reasonable alternative for avoiding the multiple iterations of keywords:

filters = lambda kw: (kw
    .replace('ansible.builtin.', '')
    .replace('community.general.', '')
    .replace('ansible.posix.', '')
)
keywords = set(map(filters, original_keywords))

(or a more traditional version with backslashes instead of wrapping the lambda body in ( )).

keywords = set(kw.replace('ansible.posix.', '') for kw in keywords)
allowed_module = keywords.intersection(all_allowed_modules)
if allowed_module:
found_allowed_modules.update(allowed_module)
Expand Down