-
Notifications
You must be signed in to change notification settings - Fork 0
/
metadata.py
executable file
·113 lines (99 loc) · 2.98 KB
/
metadata.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import requests
import sys
import yaml
class MyDumper(yaml.Dumper):
def increase_indent(self, flow=False, indentless=False):
return super(MyDumper, self).increase_indent(flow, False)
drive_scopes = ["antagning.se",
"bth.se",
"chalmers.se",
"du.se",
"esh.se",
"fhs.se",
"gih.se",
"gu.se",
"hb.se",
"hh.se",
"hhs.se",
"hig.se",
"his.se",
"hj.se",
"hkr.se",
"hv.se",
"irf.se",
"kau.se",
"kb.se",
"ki.se",
"kkh.se",
"kmh.se",
"konstfack.se",
"kth.se",
"kva.se",
"liu.se",
"lnu.se",
"ltu.se",
"lu.se",
"mau.se",
"mdu.se",
"miun.se",
"nordu.net",
"nrm.se",
"oru.se",
"rkh.se",
"scilifelab.se",
"shh.se",
"slu.se",
"smhi.se",
"su.se",
"sunet.se",
"suni.se",
"swamid.se",
"ths.se",
"uhr.se",
"umu.se",
"uniarts.se",
"user.uu.se",
"vinnova.se",
"vr.se"]
def validate(idps):
seen = []
problem = False
for key in idps:
idp = idps[key]
for entityID in idp['entityIDs']:
if entityID not in seen:
seen.append(entityID)
else:
problem = True
print(f"Duplicate entityID: {entityID}")
if problem:
sys.exit(1)
def output(idps):
transformed = {"idps": []}
for key in idps:
idp = idps[key]
transformed["idps"].append(
{"id": key, "entityIDs": idp['entityIDs']})
yaml.dump(transformed, sys.stdout, Dumper=MyDumper, sort_keys=False)
def main():
idps = {}
# idps["extern"] = {"name": "Extern", 'entityIDs': []}
r = requests.get("https://mds.swamid.se/md/swamid-transitive-ds.json")
metadata = r.json()
for entity in metadata:
if 'scope' in entity and 'type' in entity and entity['type'] == 'idp':
scopes = entity['scope'].split(',')
for scope in scopes:
if scope in drive_scopes:
index = scope
for substring in ["user.", ".se", ".net"]:
index = index.replace(substring, "")
if index not in idps:
idps[index] = {'entityIDs': []}
idps[index]['entityIDs'].append(entity['entityID'])
validate(idps)
output(idps)
if __name__ == '__main__':
main()