forked from iann0036/iam-dataset
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgcp_get_permissions.py
28 lines (23 loc) · 941 Bytes
/
gcp_get_permissions.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
import os
import json
import time
import requests
import re
from bs4 import BeautifulSoup
base_ref_page = requests.get("https://cloud.google.com/iam/docs/permissions-reference").text
frame_page_url = re.search('<iframe src="([^"]+)"', base_ref_page).group(1)
if frame_page_url[0] == "/":
frame_page_url = "https://cloud.google.com" + frame_page_url
frame_page = requests.get(frame_page_url).text
parsed_frame_page = BeautifulSoup(frame_page)
result = {}
for row in parsed_frame_page.find('tbody').find_all('tr'):
permission = row.find_all('td')[0].get('id')
result[permission] = []
for role in row.find_all('td')[1].find_all('li'):
result[permission].append({
'id': role.find('code').decode_contents().replace("<wbr/>", ""),
'name': role.decode_contents().split(" (")[0]
})
with open("gcp/permissions.json", "w") as f:
f.write(json.dumps(result, indent=2, sort_keys=True))