Added error-checking when accessing policy file to catch changes.

This commit is contained in:
kououken 2019-03-01 14:11:05 -08:00
parent 9658afda32
commit d0fa8dbea8
3 changed files with 32 additions and 30 deletions

View file

@ -1,4 +0,0 @@
EMAIL_HOST_USER=accountemail@yourmail.com
EMAIL_HOST_PASSWORD=accountpasswordhere
SUBMIT_REPORT_DESTINATION_EMAIL=to-address@yourmail.com
SUBMIT_REPORT_FROM_EMAIL=from-address@yourmail.com

View file

@ -52,6 +52,7 @@ def get_sections(r_id):
data.update(get_fields(i.id))
# process rules from the policy file if the section is completed
if i.completed:
try:
rules = pol.sections[index].rules
for rule in rules:
try:
@ -65,6 +66,8 @@ def get_sections(r_id):
data['rule_violations'].append(info)
except Exception as e:
print('Rule "{}" encountered an error. {}'.format(rule['title'], e))
except Exception as e:
print('Error accessing policy section {}. Policy file may have changed.'.format(index))
# append section to the array
section_set["sections"].append(data.copy())
@ -339,6 +342,7 @@ def section(request, report_pk, section_pk):
data.update(get_fields(s.id))
# process rules from the policy file if the section is completed
if s.completed:
try:
rules = pol.sections[s.number].rules
for rule in rules:
try:
@ -352,6 +356,8 @@ def section(request, report_pk, section_pk):
data['rule_violations'].append(info)
except Exception as e:
print('Rule "{}" encountered an error. {}'.format(rule['title'], e))
except Exception as e:
print('Error accessing policy section {}. Policy file may have been changed.'.format(s.number))
return JsonResponse(data)
def section_complete(section_pk):

Binary file not shown.