-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcreate_clean_vo_data.py
64 lines (57 loc) · 2.18 KB
/
create_clean_vo_data.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
#!/bin/env python
import json
import requests
from ruamel import yaml
import jsbeautifier
def get_data():
vars = yaml.safe_load(open('../defaults/main.yml'))
url = vars['lavoisier']['base_url'] + vars['lavoisier']['vo_id_card_endpoint']
try:
data = requests.get(url).json()
except UserWarning as e:
print e
return data
def filter_data(data):
"""
Filter the json from Lavoisier, by excluding VOs which do not have a VOMS server.
This method takes the raw json from Lavoisier and loops over the entries in it,
extracting the relevant information for the VO.
The result is an object (data) with an array of dicts containing:
VO name
voms server hostname
voms port
VOMS Server cert DN
CA DN of the issueing CA
:param data=vo: the json object to parse
"""
cleaned_data = {"data": []}
for i, vo in enumerate(data['voVoms']):
for k, vomses in enumerate(vo['Vo']):
try:
clean_vo = {
'name': None,
'voms': {
'DN': None,
'CA_DN': None,
'hostname': None,
}
}
clean_vo['name'] = vo['name']
clean_vo['voms']['DN'] = vo['Vo'][k]['VoVomsServer'][0]['VoVomsServer'][2]['X509Cert'][0]['DN'][0]
clean_vo['voms']['CA_DN'] = vo['Vo'][k]['VoVomsServer'][0]['VoVomsServer'][2]['X509Cert'][1]['CA_DN'][0]
clean_vo['voms']['hostname'] = vo['Vo'][k]['VoVomsServer'][0]['VoVomsServer'][2]['host']
clean_vo['voms']['port'] = vo['Vo'][k]['VoVomsServer'][0]['vomses_port']
cleaned_data['data'].append(clean_vo)
except IndexError:
print "VO " + vo['name'] + " is bad"
print str(i) + " vos configured"
# write it to a file
with open('data.yml', 'w') as file:
yaml.dump(cleaned_data,file,Dumper=yaml.RoundTripDumper)
return 0
if __name__ == "__main__":
opts = jsbeautifier.default_options()
opts.indent_size = 2
opts.space_in_empty_paren = True
data = get_data()
filter_data(get_data())