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

Add filter keep_keys #8438

Closed
1 task done
vbotka opened this issue May 30, 2024 · 2 comments · Fixed by #8456
Closed
1 task done

Add filter keep_keys #8438

vbotka opened this issue May 30, 2024 · 2 comments · Fixed by #8456
Labels
feature This issue/PR relates to a feature request has_pr

Comments

@vbotka
Copy link
Contributor

vbotka commented May 30, 2024

Summary

Create filter keep_keys.

The collection ansible.utils provides the filter keep_keys. Unfortunately:

  • It is not working properly. See keep_keys doesn't exclude a key if the value is list. ansible.utils#353
  • The documentation is poor. For example, it is not clear what "recursively" means in "Keep specific keys from a data recursively"
  • There are only two examples and two tests. An example of "matching_parameter=regex" is missing. It is unclear whether the parameter target should be a list for regex. A list of regex(es) would be an antipattern.
  • But, the main hurdle to fix this filter is the class AnsibleArgSpecValidator that is used in all ansible.utils/plugins. Such complexity is inefficient in a filter where a couple of comprehensions would do the job. This also violates the golden Unix rule Tools, not policy

The goal is to keep the code simple and test it properly.

Issue Type

Feature Idea

Component Name

community.genera.keep_keys

Additional Information

  t: [k0, k1]
  l1:
    - {k0: A, k1: B, k2: C}
    - {k0: D, k1: E, k2: F}
  r1: "{{ l1 | community.general.keep_keys(target=t) }}"

gives

  r1:
  - k0: A
    k1: B
  - k0: D
    k1: E

Code of Conduct

  • I agree to follow the Ansible Code of Conduct
vbotka added a commit to vbotka/community.general that referenced this issue May 30, 2024
@ansibullbot
Copy link
Collaborator

Files identified in the description:
None

If these files are incorrect, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibullbot ansibullbot added the feature This issue/PR relates to a feature request label May 30, 2024
This was referenced May 31, 2024
This was referenced Jun 1, 2024
vbotka added a commit to vbotka/community.general that referenced this issue Jun 2, 2024
vbotka added a commit to vbotka/community.general that referenced this issue Jun 2, 2024
@vbotka
Copy link
Contributor Author

vbotka commented Jun 3, 2024

This feature request is implemented in PR #8456

@felixfontein felixfontein linked a pull request Jun 3, 2024 that will close this issue
felixfontein added a commit that referenced this issue Jun 4, 2024
* Add filter keep_keys. Implement feature request #8438

* Fix comment indentation.

* Fix regex reference.

* Fix indentation.

* Fix isinstance list.

* Update plugins/plugin_utils/keys_filter.py

Co-authored-by: Felix Fontein <[email protected]>

* Update plugins/plugin_utils/keys_filter.py

Co-authored-by: Felix Fontein <[email protected]>

* Update plugins/plugin_utils/keys_filter.py

Co-authored-by: Felix Fontein <[email protected]>

* Update plugins/plugin_utils/keys_filter.py

Co-authored-by: Felix Fontein <[email protected]>

* Update plugins/filter/keep_keys.py

Co-authored-by: Felix Fontein <[email protected]>

* Update documentation, examples, and integration tests.

* _keys_filter_target_str returns tuple of unique target strings if
target is list. Update documentation, function comments, and error
messages.

* Sort maintainers.

* Update plugins/filter/keep_keys.py

Co-authored-by: Felix Fontein <[email protected]>

* Update examples with explicit collection.

---------

Co-authored-by: Felix Fontein <[email protected]>
patchback bot pushed a commit that referenced this issue Jun 4, 2024
* Add filter keep_keys. Implement feature request #8438

* Fix comment indentation.

* Fix regex reference.

* Fix indentation.

* Fix isinstance list.

* Update plugins/plugin_utils/keys_filter.py

Co-authored-by: Felix Fontein <[email protected]>

* Update plugins/plugin_utils/keys_filter.py

Co-authored-by: Felix Fontein <[email protected]>

* Update plugins/plugin_utils/keys_filter.py

Co-authored-by: Felix Fontein <[email protected]>

* Update plugins/plugin_utils/keys_filter.py

Co-authored-by: Felix Fontein <[email protected]>

* Update plugins/filter/keep_keys.py

Co-authored-by: Felix Fontein <[email protected]>

* Update documentation, examples, and integration tests.

* _keys_filter_target_str returns tuple of unique target strings if
target is list. Update documentation, function comments, and error
messages.

* Sort maintainers.

* Update plugins/filter/keep_keys.py

Co-authored-by: Felix Fontein <[email protected]>

* Update examples with explicit collection.

---------

Co-authored-by: Felix Fontein <[email protected]>
(cherry picked from commit 6f8f12f)
felixfontein pushed a commit that referenced this issue Jun 4, 2024
Feature filter keep_keys (#8456)

* Add filter keep_keys. Implement feature request #8438

* Fix comment indentation.

* Fix regex reference.

* Fix indentation.

* Fix isinstance list.

* Update plugins/plugin_utils/keys_filter.py

Co-authored-by: Felix Fontein <[email protected]>

* Update plugins/plugin_utils/keys_filter.py

Co-authored-by: Felix Fontein <[email protected]>

* Update plugins/plugin_utils/keys_filter.py

Co-authored-by: Felix Fontein <[email protected]>

* Update plugins/plugin_utils/keys_filter.py

Co-authored-by: Felix Fontein <[email protected]>

* Update plugins/filter/keep_keys.py

Co-authored-by: Felix Fontein <[email protected]>

* Update documentation, examples, and integration tests.

* _keys_filter_target_str returns tuple of unique target strings if
target is list. Update documentation, function comments, and error
messages.

* Sort maintainers.

* Update plugins/filter/keep_keys.py

Co-authored-by: Felix Fontein <[email protected]>

* Update examples with explicit collection.

---------

Co-authored-by: Felix Fontein <[email protected]>
(cherry picked from commit 6f8f12f)

Co-authored-by: Vladimir Botka <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature This issue/PR relates to a feature request has_pr
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants