-
Notifications
You must be signed in to change notification settings - Fork 698
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
Refactor templates v2 #9870
Merged
jan-cerny
merged 13 commits into
ComplianceAsCode:master
from
evgenyz:refactor_templates_v2
Nov 25, 2022
Merged
Refactor templates v2 #9870
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
f6dfe66
Refactor template builder
evgenyz 219ea25
Refactor templates and XCCDFEntities
evgenyz 395af0e
Refactor templates: Rule and Templatable and products
evgenyz b7ff233
Refactor templates: move XCCDFEntity-specific code into Templatable
evgenyz 3e0d2c0
Refactor build_yaml
evgenyz b19366e
Refactor templates
evgenyz 3952bda
Refactor common.Templatable
evgenyz 35e075b
Refactor templates
evgenyz 5c7cf43
Refactor entities/common
evgenyz c0b411e
Add max_line_length parameter to .editorconfig
evgenyz cc7ecd7
Refactor entities/common
evgenyz 24be147
Fix line length in build_sce.py
evgenyz 85e3553
Remove offending stigid from apple_os/auditing/service_com_apple_audi…
evgenyz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
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 is a modification of condition without any compensation, so no wonder that it may change the behavior of the function, as reported in #9894
new_items
is not an empty dict for the whole time, but theitems_dict
ordering is different between Python2 and Python3, so the loop may behave differently in those interpreters.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.
And it is the case in that issue -
pkgname@rhel7: pam_pkcs11
is supposed to take precedence overpkgname: openssl-pkcs11
. What happened probably was thatnew_items["pkgname"]
was set topam_pkcs11
, and it got overwritten byopenssl-pkcs11
. The condition protected product-qualified items from being overwritten by generic items.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 feels like this case should fall right into https://github.com/evgenyz/content/blob/5c7cf430a1012bf3151872519f7873b99218f5cb/ssg/entities/common.py#L46 instead of being short-circuited.
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.
Otherwise this no-overwrite policy depends on the order of dictionary items (which is not ordered in any way by definition).
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.
Is it formulated anywhere besides the exception message? I can't find anything in the docs. Maybe I don't even understand it to the full extent.
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 funny thing is that CodeClimate was right about that method being too cognitively complex. I think (may be wrong though) that
is triggered in case that there is an override attempt of a product-qualified value by a generic value, so now it looks like to me that the exception is not thrown, but the value also isn't overwritten, so it works fine on Python3.
Anyway, only exhaustive unit-testing could bring sufficient level of confidence, and although we would like that, it's out of scope of this PR. The truth is that removing the second part of that conditional was a mistake, and the best thing to do is to fix it - we all know that anybody can make mistakes, and this one was a very educational one that plenty of people can learn from.
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 truth is that it ain't over yet: #9910
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.
happens after the possible exception.
Python 2 and 3 difference is in the order of items storage/emission. I've reproduced it in a test case using update().
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 that the exception happened after this sequence. FTR, the original code can be viewed here:
content/ssg/build_yaml.py
Line 949 in 219ea25
The issue #9894 was about product-qualified package, which is definitely not a "global reference". Therefore, the next line
if label in items_dict and not allow_overwrites and value != items_dict[label]
was one that could trigger an exception, but I don't recall our policy regardingallow_overwrites
. That clause probably aims to enforce existence of either only product-qualified specs, or no product-qualified specs at all.Naming sucks, but at least the commit messages that explain why the function got into that shape are quite solid.
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 function has not been used for de-qualifying template variables before refactoring.