-
Notifications
You must be signed in to change notification settings - Fork 9
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
Reorganization of OVAL Test results #221
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7bb3305
Add map of OVAL endpoints
Honny1 e0c340e
Add onclick function
Honny1 94ca392
Add new elements
Honny1 f268e95
Change the presentation of referenced endpoints
Honny1 79369ea
Use default dict
Honny1 0f46012
Reduce complexity of function generate_referenced_endpoints
Honny1 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,43 +78,59 @@ def _get_variables_by_id(self): | |
return self._get_data_by_id(data) | ||
|
||
@staticmethod | ||
def _iter_over_data_and_get_references(dict_, out): | ||
def _iter_over_data_and_get_references(dict_, out, data_id, map_referenced_oval_endpoints): | ||
for key, value in dict_.items(): | ||
if isinstance(value, dict): | ||
OVALTestParser._iter_over_data_and_get_references(value, out) | ||
OVALTestParser._iter_over_data_and_get_references( | ||
value, out, data_id, map_referenced_oval_endpoints | ||
) | ||
else: | ||
matches_key = ["object_reference", "var_ref", "object_ref", "filter"] | ||
matches_val = [":var:", ":obj:", ":ste:"] | ||
if any(s in key for s in matches_key) and any(s in value for s in matches_val): | ||
out.append(value) | ||
if data_id not in map_referenced_oval_endpoints: | ||
map_referenced_oval_endpoints[data_id] = [] | ||
if value not in map_referenced_oval_endpoints[data_id]: | ||
map_referenced_oval_endpoints[data_id].append(value) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can the map be a collections.defaultdict? I think that would help you avoid this construction. |
||
|
||
def _resolve_reference(self, ref_id, new_ref, out): | ||
def _resolve_reference(self, ref_id, new_ref, out, map_referenced_oval_endpoints): | ||
if ":var:" in ref_id: | ||
variable = self.variable_parser.get_variable(ref_id) | ||
self._iter_over_data_and_get_references(variable.variable_data, new_ref) | ||
self._iter_over_data_and_get_references( | ||
variable.variable_data, new_ref, ref_id, map_referenced_oval_endpoints | ||
) | ||
out[ref_id] = variable | ||
elif ":obj:" in ref_id: | ||
object_ = self.objects_parser.get_object(ref_id) | ||
self._iter_over_data_and_get_references(object_.object_data, new_ref) | ||
self._iter_over_data_and_get_references( | ||
object_.object_data, new_ref, ref_id, map_referenced_oval_endpoints | ||
) | ||
out[ref_id] = object_ | ||
elif ":ste:" in ref_id: | ||
state = self.states_parser.get_state(ref_id) | ||
self._iter_over_data_and_get_references(state.state_data, new_ref) | ||
self._iter_over_data_and_get_references( | ||
state.state_data, new_ref, ref_id, map_referenced_oval_endpoints | ||
) | ||
out[ref_id] = state | ||
else: | ||
logging.warning(ref_id) | ||
|
||
def _get_referenced_endpoints(self, oval_object, oval_states): | ||
def _get_referenced_endpoints(self, oval_object, oval_states, map_referenced_oval_endpoints): | ||
references = [] | ||
object_data = oval_object.object_data if oval_object is not None else {} | ||
self._iter_over_data_and_get_references(object_data, references) | ||
self._iter_over_data_and_get_references( | ||
object_data, references, oval_object.object_id, map_referenced_oval_endpoints, | ||
) | ||
for state in oval_states: | ||
self._iter_over_data_and_get_references(state.state_data, references) | ||
self._iter_over_data_and_get_references( | ||
state.state_data, references, state.state_id, map_referenced_oval_endpoints, | ||
) | ||
|
||
out = {} | ||
while len(references) != 0: | ||
ref = references.pop() | ||
self._resolve_reference(ref, references, out) | ||
self._resolve_reference(ref, references, out, map_referenced_oval_endpoints) | ||
return out | ||
|
||
def get_test_info(self, test_id): | ||
|
@@ -134,7 +150,11 @@ def get_test_info(self, test_id): | |
for oval_state_el in list_state_of_test: | ||
oval_states.append(self.states_parser.get_state(oval_state_el.get("state_ref", ""))) | ||
|
||
referenced_oval_endpoints = self._get_referenced_endpoints(oval_object, oval_states) | ||
map_referenced_oval_endpoints = {} | ||
|
||
referenced_oval_endpoints = self._get_referenced_endpoints( | ||
oval_object, oval_states, map_referenced_oval_endpoints | ||
) | ||
|
||
return OvalTest( | ||
test_id=test_id, | ||
|
@@ -145,4 +165,5 @@ def get_test_info(self, test_id): | |
oval_object=oval_object, | ||
oval_states=oval_states, | ||
referenced_oval_endpoints=referenced_oval_endpoints, | ||
map_referenced_oval_endpoints=map_referenced_oval_endpoints, | ||
) |
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.
Consider if the code complexity of this function can be reduced, for example by inverting the condition or extracting the inner for loop to a separate function.