-
Notifications
You must be signed in to change notification settings - Fork 0
/
BoostSecurityToPowerBI.py
90 lines (78 loc) · 2.26 KB
/
BoostSecurityToPowerBI.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import pandas as pd
import json
import requests
def get_findings_with_offset(offset):
url = "https://api.boostsecurity.io/findings-view/graphql"
graphql_query = {
"query": """
query (
$first: Int,
$after: String,
$locateFindingId: String
) {
findings(
first: $first,
after: $after,
locateFindingId: $locateFindingId
) {
totalCount
pageInfo {
hasNextPage
endCursor
}
edges {
node {
timestamp
findingId
isViolation
analysisContext {
projectName
}
scmLink {
href
}
}
cursor
}
}
}
""",
"variables": {
"first": 100, # Adjust the batch size as needed
"after": offset,
# ... other variables
}
}
headers = {
"Content-Type": "application/json",
"Authorization": "ApiKey " + "<YOUR API KEY>"
}
response = requests.post(url, json=graphql_query, headers=headers)
response_json = response.json()
return response_json
# Fetch all data with pagination
offset = None
all_data = []
while True:
json_data = get_findings_with_offset(offset)
edges = json_data['data']['findings']['edges']
if not edges:
break
all_data.extend(edges)
end_cursor = json_data['data']['findings']['pageInfo']['endCursor']
if end_cursor == offset:
break
offset = end_cursor
# Extract relevant data and create DataFrame
flattened_data = []
for edge in all_data:
node = edge['node']
flattened_data.append({
'timestamp': node['timestamp'],
'findingId': node['findingId'],
'isViolation': node['isViolation'],
'projectName': node['analysisContext']['projectName'],
'fileUri': node['scmLink']['href'],
'cursor': edge['cursor']
})
df = pd.DataFrame(flattened_data)