Skip to content

Adds support for multiple documents in a YAML file and encrypted_regex options#14

Open
mgaruccio wants to merge 5 commits intoyuvipanda:mainfrom
mgaruccio:main
Open

Adds support for multiple documents in a YAML file and encrypted_regex options#14
mgaruccio wants to merge 5 commits intoyuvipanda:mainfrom
mgaruccio:main

Conversation

@mgaruccio
Copy link

This PR adds two new features to the pre-commit hook. Both primarily designed to make the hook work better in a kubernetes/flux workflow, but also helpful in other contexts like ansible playbooks.

First it allows multiple documents using an option matching the one used in the check_yaml hook provided by the upstream project relevant PR I tried to match their patterning as well as possible and make as few changes to the underlying code of this project as possible, but it may be better to do something like always using the _load_all() function and simply error out if there is more than one doc and the -m flag was not passed (or assume that multiple docs are fine and allow users to perform that type of check using the check_yaml hook itself). I'm happy to make those changes if you'd like me to. fixes #12

Second it adds support for sops encrypted_regex option, which limits the actual fields sops encrypts to only ones the user expects/intends to contain secrets. This change looks for the encrypted_regex key within the sops configuration and uses it if available, if not, it uses \S to match any valid string (and so all keys). I omitted a flag for this one since the behavior remains unchanged for any file that does not include the encrypted-regex key, and any file that does specify it will always fail without this additional filtering, but I'm happy to add a flag if you feel that being explicit here is better, just let me know if you'd like to see that or any other changes before the commit. fixes #13

@yuvipanda
Copy link
Owner

Somehow I never got notified of this :( I will take a look at this shortly. Apologies, @mgaruccio and thank you for your patience & contribution.

@eloo
Copy link

eloo commented Sep 19, 2023

was just looking if this feature is supported and then i found this open PR

would be really nice so this merged :)

Copy link
Owner

@yuvipanda yuvipanda left a comment

Choose a reason for hiding this comment

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

Well well well, if it isn't me being slow to respond to a wonderful PR on a project I maintain. So sorry for the slow response!

I've asked for one change, but happy to merge after that.

Again, sorry for the delayed response, and thank you for the PR!

# otherwise, sets the value to "match all strings" \S regex
if 'encrypted_regex' in doc['sops']:
encrypted_regex = doc['sops']['encrypted_regex']
else:
Copy link
Owner

Choose a reason for hiding this comment

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

If it's not set, let's just not do any regex matching at all?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

support for encrypted_regex Support for multiple documents in a single YAML file

3 participants

Comments