-
Notifications
You must be signed in to change notification settings - Fork 0
/
googleapis.py
42 lines (31 loc) · 1.18 KB
/
googleapis.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
import base64
import json
import github3
from utils import _get_secret
def _fetch_jons_json():
token = _get_secret("client-coverage-status-ghtoken", "latest")
g = github3.login(token=token)
dotnet = g.repository("googleapis", "google-cloud-dotnet")
file_b64 = dotnet.file_contents("apis/ServiceDirectory/directory.json").content
file_decoded = base64.b64decode(file_b64).decode("utf-8")
return json.loads(file_decoded)
def _parse_jons_json(jons_json):
services = {}
for service in jons_json.get("Services"):
name = service.get("Name")
version = service.get("Version")
if name in services.keys():
if version not in services.get(name).get("versions"):
services[name]["versions"].append(version)
else:
services[name] = {"title": service.get("Title"), "versions": [version]}
return services
def get_published_protos():
apis_json = _fetch_jons_json()
protos = _parse_jons_json(apis_json)
print(f"googleapis: found {len(protos)} services.")
return protos
if __name__ == "__main__":
import pprint
pp = pprint.PrettyPrinter(indent=4)
pp.pprint(get_published_protos())