-
Notifications
You must be signed in to change notification settings - Fork 8
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
Data segmentation in JSON file #81
base: main
Are you sure you want to change the base?
Conversation
New methods for creating the detailed structure and generating the corresponding JSON.
…otals. The 'detail' block is added to segment the reported data, and all returns are modified to have the totals checked by each validator, thus enabling data collection for KPIs.
|
||
root = xml.etree.ElementTree.fromstring(obj_xml_string) | ||
|
||
list_atr_remove = ['loc'] |
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.
Could you add a comment here as to why you're removing the 'loc' attribute
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.
Okay, I'll add a comment, but I'll also comment it here just in case you see another solution. The issue is that they've added the 'loc' attribute, and now the script doesn't retrieve the data properly from the XML. Here's an example.
What I've done is clean the XML of attributes. I did it this way in case they add other attributes later on.
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 explaining
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.
Sorry for the long response time, my work and personal lives have both been very busy.
I was doing some testing and noticed a problem:
Some validators retrieve attributes, like the name, as is done here: https://github.com/moshekaplan/palo_alto_firewall_analyzer/blob/main/src/palo_alto_firewall_analyzer/validators/misleading_objects.py#L27 :
address_dict = xml_object_to_dict(address_entry)
entry_name = address_dict['entry']['@name']
Therefore, removing the attributes breaks at least that validator - probably more.
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.
Hi, no problem at all, I understand this is a hobby, there are more important things. I don't understand what you mean, I've been testing and I wasn't getting any errors, well, except for my files,... but the only tag I remove is 'loc' and I make it nominal, I don't remove any other name or anything. Could you provide some kind of example of your tests? As I mentioned, with the exported files I've been working with, both with the '@loc' tag and without it, I haven't had any issues. Thanks.
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.
Sorry for the super-delayed follow-up on this.
Say I have an address object with a single IP-netmask of 127.0.0.1.
The old code (now called with xml_object_to_dict1
) would result in a dict like the following:
(Pdb) xml_object_to_dict1(address_entry)
{'entry': {'@name': 'ip-127.0.0.1', 'ip-netmask': '127.0.0.1'}}
The new code (what in this PR is called xml_object_to_dict
) removes the @name
attribute, resulting in the following:
(Pdb) xml_object_to_dict(address_entry)
{'entry': {'ip-netmask': '127.0.0.1'}}
This is problematic because of code that accesses the @name
attribute, like:
https://github.com/Nawtest/palo_alto_firewall_analyzer/blob/main/src/palo_alto_firewall_analyzer/validators/misleading_objects.py#L28 :
entry_name = address_dict['entry']['@name']
Because the @name
attribute is missing, the dictionary access fails
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.
Okiz, don't worry, I'll review it. It's strange to me that this attribute gets removed; the one I remove is '@loc'. I'll check it to fix it.
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.
Hi, I am checking the code, and I don't understand why removing the 'loc' tag causes an error when looking for the 'name' tag. It is true that in my XML files, there are some entries without the 'name' tag. I added an if statement to check the issue, and this is the result:
Not include 'name' tag
I remove the check of output-format = None, and fixed problem with function parsed to json |
Would you be able to resolve the conflicts so I can review it for merging? |
Hi, I've resolved the conflicts but logically, due to having made structural changes, the tests are failing. I'm reviewing them and adding the correct returns. |
Hello, I have added the 'Detail' block to the JSON file to separate, as much as possible, the data in the report. Additionally, I have modified the returns by adding a count with the number of validations performed to calculate KPIs.
Here examples: