Support lookup of a specific key in a SOPS file #158
Closed
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.
Motivation
I have a use case for looking up a specific key from a SOPS file. Often, said structure is not a simple
key: value
but a more complex dict from which I need to obtain the values of sub-keys in the dict.Right now with the community SOPS collection, a SOPS file containing a dict comes back as a string with
\n
line breaks and I am having to resort to a custom lookup plugin to do what I want. This PR achieves it for the community collection, so thought I'd offer it, but it may not be solid enough to work for wider cases - feel free to discard it.Changes description
An optional
key
argument can be passed to the lookup plugin. If that key is found in the SOPS file, it's that item that gets appended and returned.See the test suite and the README example for more information on how to use it.
Additional notes
I only tested it with YAML SOPS files, and I didn't test it with multiple SOPS files passed in as terms. The tests were all passing at time of writing.