Skip to content
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

Improve error handling in create-firewall-data.py #16

Open
rgmz opened this issue Nov 10, 2021 · 0 comments
Open

Improve error handling in create-firewall-data.py #16

rgmz opened this issue Nov 10, 2021 · 0 comments

Comments

@rgmz
Copy link

rgmz commented Nov 10, 2021

When running the scripts in the reports2/ directory, the create-firewall-data.py (and potentially others) doesn't properly handler failures from the IQ API.

$ cd reports2 && ./create-data.sh http://localhost:8070 admin admin123
applicationevaluations.json
applicationevaluations.csv
policyviolations.json
policyviolations.csv
componentsinquarantine.json
componentsinquarantine.csv
componentwaivers.json
componentwaivers.csv
./quarantine_data/autoreleased_from_quarantine_summary.json
Traceback (most recent call last):
  File "/Users/me/code/succes-metrics/successmetrics-84/reports2/create-firewall-data.py", line 249, in <module>
    main()
  File "/Users/me/code/succes-metrics/successmetrics-84/reports2/create-firewall-data.py", line 239, in main
    summary_report("autoreleased_from_quarantine_summary", "releaseQuarantine/summary")
  File "/Users/me/code/succes-metrics/successmetrics-84/reports2/create-firewall-data.py", line 66, in summary_report
    for key in data.keys():
AttributeError: 'str' object has no attribute 'keys'

This error is caused by the autoreleased_from_quarantine_summary.json file containing "Error fetching data" instead of the expected JSON.

$ cat reports2/quarantine_data/autoreleased_from_quarantine_summary.json
"Error fetching data"

When API requests fail, get_nexusiq_data returns "Error fetching data" (str); however, certain parts of the code expect that method to always return a dict:

line = []
for key in data.keys():
line.append(key)

if req.status_code == 200:
res = req.json()
else:
res = "Error fetching data"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant