-
Notifications
You must be signed in to change notification settings - Fork 24k
Refactor vault #80675
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
base: devel
Are you sure you want to change the base?
Refactor vault #80675
Conversation
The test
The test
|
The test
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've done an initial review and it looks like all changes are cosmetic and generally looks good to me 👍 This will need a thorough review every time it needs to be rebased, so if you can remove unnecessary changes that aren't an explicit goal of this PR (for example, modified function signatures/variable names/whitespace), that would make reviewing code parity easier.
It looks like a bunch of class methods have been turned into staticmethods, but none of them are called without a class instance. Until that's needed for some reason, those changes can be removed.
Since lib/ansible/parsing/vault/__init__.py
is internal API, the backwards incompatible changes to the classes/methods available may not matter, but I'd like to mention it was easy to find some things in the wild that would break from that. Some examples: https://engineering.adjust.com/post/secrets_management_with_ansible_vault/#vault-python-api, https://github.com/nuagenetworks/nuage-metroae/blob/master/encrypt_credentials.py#L8, https://github.com/arenadata/adcm/blob/develop/python/cm/adcm_config/ansible.py#L14
The few changes to variable names, signatures etc. are meant to make the code easier to understand. I already tried to keep those to a minimum.
I changed a few functions that didn't use
Do you suggest, I import every class and metod in |
Thanks for the quick update.
I didn't want to make a comprehensive list of these because they're all very minor, but there are quite a few. To keep this general:
Ideally to me, most of these would be removed so it's easier to see that yes, this function was just moved from file1 to file2 with no actual changes other than format strings.
I'm not sure, maybe. You could wait for others to weigh in on this. |
I have a strong opinion about this. Methods, that don't use
I'm in slight favor of separating words for readability, but I guess there are enough changes in this PR, so I reverted all
Those should mostly be docstrings and comments. The starting quotes were inconsistent, sometimes on a separate line, and sometimes not. That itched me a little and I find it more optically pleasing if they have their own lines. As I like to have those things consistent, I formatted them all the same way.
What is the best way forward in this case? Should I post to a mailing-list? |
The test
The test
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for reducing some of the extraneous changes. Still LGTM in general, but there are a few more minor changes that could be tidied up.
lib/ansible/parsing/vault/lib.py
Outdated
b_data = to_bytes(to_text(data, encoding='ascii', errors='strict', nonstring='strict'), encoding='ascii', | ||
errors='strict') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
b_data = to_bytes(to_text(data, encoding='ascii', errors='strict', nonstring='strict'), encoding='ascii', | |
errors='strict') | |
b_data = to_bytes(to_text(data, encoding='ascii', errors='strict', nonstring='strict'), encoding='ascii', errors='strict') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this would cause tests to fail, as the line is too long
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It shouldn't. My suggestion was the original line, which is < 160 characters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you're right, my editor is set to 120 characters
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The git blame with -C
looks great now. I don't think there's a way to see from the UI, so here's the current state of things squashed to a single commit: https://gist.github.com/s-hertel/6f7038adf383a7746269da94943dcf0e.
lib/ansible/parsing/vault/secret.py
Outdated
@staticmethod | ||
def confirm(b_vault_pass_1, b_vault_pass_2): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@staticmethod | |
def confirm(b_vault_pass_1, b_vault_pass_2): | |
def confirm(self, b_vault_pass_1, b_vault_pass_2): |
lib/ansible/parsing/vault/editor.py
Outdated
os.chown(filename, prev.st_uid, prev.st_gid) | ||
|
||
display.vvvvv( | ||
f'Re-keyed file "{to_text(filename)}" (decrypted with vault id "{to_text(vault_id_used)}") was encrypted ' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
f'Re-keyed file "{to_text(filename)}" (decrypted with vault id "{to_text(vault_id_used)}") was encrypted ' | |
f'Rekeyed file "{to_text(filename)}" (decrypted with vault id "{to_text(vault_id_used)}") was encrypted ' |
lib/ansible/parsing/vault/ciphers.py
Outdated
# (c) 2014, James Tanner <tanner.jc@gmail.com> | ||
# (c) 2016, Adrian Likins <alikins@redhat.com> | ||
# (c) 2016 Toshio Kuratomi <tkuratomi@ansible.com> | ||
# (c) 2023, Thomas Ziegler <thomas.ziegler.pa@gmail.com> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think rewrites/refactoring usually warrant a copyright addition (same for the other files). Adding your name would be more applicable on a PR containing feature work.
lib/ansible/parsing/vault/lib.py
Outdated
b_data = to_bytes(to_text(data, encoding='ascii', errors='strict', nonstring='strict'), encoding='ascii', | ||
errors='strict') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It shouldn't. My suggestion was the original line, which is < 160 characters.
f1f1779
to
c981c86
Compare
c981c86
to
fbade62
Compare
Hello @s-hertel, do you have a suggestion on how I can get attention to this PR? I posted on the chat a few weeks back, but to no success. |
(needs review, major changes to vault coming) |
@nitzmahone is this going to get attention? I had given up on it, but if it is going to be picked up, I'm going to rebase and resolve conflicts |
@toydarian no, the point is that this PR might need to be redone or even made irrelevant with upcoming changes. We have kept it open waiting for the relevant core members having some time to do a deep review and comparison to make a final decision. |
SUMMARY
This is a refactoring-only PR for vault.
I plan to add some quality-of-life improvements and features to vault, but before doing so, I wanted to split up the code from one 1.2k-lines file into several files and make it a little more modern.
Those are the major changes in this PR:
ISSUE TYPE
or more like
COMPONENT NAME
vault
ADDITIONAL INFORMATION
Most classes and functions are not available on the package
ansible.parsing.vault
anymore, but some that are used in other components are imported in__init__.py
to avoid making this PR even larger than it already is.