-
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
Open
Nawtest
wants to merge
10
commits into
moshekaplan:main
Choose a base branch
from
Nawtest:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6a36685
Update Readme with my options
Nawtest 139d944
Add support json file output
Nawtest 2fa7818
feat: :heavy_plus_sign: Control json detail
Nawtest 9a93efc
feat: Modification of validations to include the detail and checked t…
Nawtest 0216c5a
docs: :memo: Modified option output_format
Nawtest d84de03
fix: :bug: #81 Modifications commented have been made.
Nawtest 5b29aeb
fix: :bug: #81 Modified args and fixed bugs parsed json
Nawtest d68bc6e
Merge branch 'main' into main
Nawtest fcdf007
test: #81 Correct test for new changes
Nawtest a779aca
chore:
Nawtest 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
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 |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import logging | ||
|
||
from palo_alto_firewall_analyzer.core import Detail | ||
|
||
def get_value(data): | ||
if data is None: | ||
data = "" | ||
|
||
return data | ||
|
||
def parsed_details(details): | ||
|
||
detail = Detail( | ||
policy_type=get_value(details.get('policy_type')), | ||
policy_name=get_value(details.get('policy_name')), | ||
device_group=get_value(details.get('device_group')), | ||
entry_type=get_value(details.get('entry_type')), | ||
entry_name=get_value(details.get('entry_name')), | ||
entry_value=get_value(details.get('entry_value')), | ||
rule_type=get_value(details.get('rule_type')), | ||
rule_name=get_value(details.get('rule_name')), | ||
protocol=get_value(details.get('protocol')), | ||
port=get_value(details.get('port')), | ||
allowed_group_profiles=get_value(details.get('allowed_group_profiles')), | ||
group_profile_setting=get_value(details.get('group_profile_setting')), | ||
address=get_value(details.get('address')), | ||
fqdn=get_value(details.get('fqdn')), | ||
ip=get_value(details.get('ip')), | ||
ip_mask=get_value(details.get('ip_mask')), | ||
loc=get_value(details.get('loc')), | ||
shadowing_address_name=get_value(details.get('shadowing_address_name')), | ||
mandated_log_profile=get_value(details.get('mandated_log_profile')), | ||
log_setting=get_value(details.get('log_setting')), | ||
object_entry_name=get_value(details.get('object_entry_name')), | ||
policy_entry_name=get_value(details.get('policy_entry_name')), | ||
zone_type=get_value(details.get('zone_type')), | ||
zones=get_value(details.get('zones')), | ||
extra=get_value(details.get('extra')) | ||
) | ||
|
||
return detail | ||
|
||
|
||
def get_json_detail(detail): | ||
json_detail={ | ||
"policy_type":detail.policy_type, | ||
"policy_name":detail.policy_name, | ||
"device_group":detail.device_group, | ||
"entry_type":detail.entry_type, | ||
"entry_name":detail.entry_name, | ||
"rule_type":detail.rule_type, | ||
"rule_name":detail.rule_name, | ||
"protocol":detail.protocol, | ||
"port":detail.port, | ||
"allowed_group_profiles":detail.allowed_group_profiles, | ||
"group_profile_setting": detail.group_profile_setting, | ||
"address": detail.address, | ||
"fqdn": detail.fqdn, | ||
"ip":detail.ip, | ||
"ip_mask":detail.ip_mask, | ||
"loc":detail.loc, | ||
"shadowing_address_name":detail.shadowing_address_name, | ||
"mandated_log_profile":detail.mandated_log_profile, | ||
"log_setting":detail.log_setting, | ||
"object_entry_name":detail.object_entry_name, | ||
"policy_entry_name":detail.policy_entry_name, | ||
"zone_type":detail.zone_type, | ||
"zones":detail.zones, | ||
"extra":detail.extra | ||
} | ||
|
||
return json_detail |
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
Oops, something went wrong.
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.
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 :
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:The new code (what in this PR is called
xml_object_to_dict
) removes the@name
attribute, resulting in the following: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 :
Because the
@name
attribute is missing, the dictionary access failsThere 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:
if not delete the 'loc' tag, member is:
if delete the 'loc' tag, and include a if, the json generated is:
This example my file:
Not include 'name' tag