Skip to content

Commit 3046f27

Browse files
author
viegasdom
committed
Adds a fetch that extracts findings in a csv format
1 parent b92b627 commit 3046f27

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env python
2+
3+
import csv
4+
import requests
5+
from urllib.parse import urljoin
6+
7+
8+
token = input("API Token:")
9+
headers = {"Authorization": "JWT {}".format(token)}
10+
11+
api_base_url = "https://api.qa.probely.com"
12+
findings_endpoint = urljoin(
13+
api_base_url, "findings/?include=compliance&length=10000"
14+
)
15+
16+
response = requests.get(findings_endpoint, headers=headers)
17+
results = response.json()["results"]
18+
with open("findings.csv", "w") as csv_file:
19+
csv_writer = csv.writer(
20+
csv_file, delimiter=",", quotechar='"', quoting=csv.QUOTE_ALL
21+
)
22+
for result in results:
23+
labels = result["labels"] if result.get("labels") else []
24+
labels_name = [label["name"] for label in labels]
25+
row = [
26+
result["id"],
27+
result["severity"],
28+
result["definition"]["name"],
29+
result["url"],
30+
result["last_found"],
31+
result["state"],
32+
result.get("assignee")["email"] if result.get("assignee") else " ",
33+
*labels_name
34+
]
35+
csv_writer.writerow(row)

0 commit comments

Comments
 (0)