forked from EGI-Federation/fedcloud-catchall-operations
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-config.py
executable file
·102 lines (83 loc) · 2.81 KB
/
generate-config.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
#!/usr/bin/env python
import argparse
import json
import yaml
CHECKIN_ISS = "https://aai.egi.eu/oidc/"
def basic_mapping(local_group, entitlement):
return {
"local": [{"user": {"name": "{0}"}, "group": {"id": local_group}}],
"remote": [
{"type": "HTTP_OIDC_SUB"},
{"type": "HTTP_OIDC_ISS", "any_one_of": [CHECKIN_ISS]},
{
"type": "OIDC-eduperson_entitlement",
"regex": True,
"any_one_of": [f"^{entitlement}$"],
},
],
}
def get_entitlements(fqan, entitlements):
try:
return entitlements[fqan]
except KeyError:
if not fqan.startswith("/"):
raise Exception(f"No entitlement defined for vo {fqan}")
# FQAN is /<name of the VO>/extra/
# or /VO=<name of the VO>/extra/
vo_name = fqan.split("/")[1]
if vo_name.startswith("VO="):
vo_name = vo_name[3:]
try:
return entitlements[vo_name]
except KeyError:
raise Exception(f"No entitlement defined for vo {vo_name}")
def keystone_config(site, entitlements):
mapping = []
for vo in site.get("vos", []):
ent = get_entitlements(vo["name"], entitlements)
vo_project = vo["auth"]["project_id"]
mapping.append(basic_mapping(vo_project, ent))
print(json.dumps(mapping, indent=4))
def caso_config(site, *args):
mapping = {}
for vo in site.get("vos", []):
vo_name = vo["name"]
vo_project = vo["auth"]["project_id"]
mapping[vo_name] = {"projects": [vo_project]}
print(json.dumps(mapping, indent=4))
def cloudkeeper_config(site, *args):
mapping = {}
for vo in site.get("vos", []):
vo_name = vo["name"]
vo_project = vo["auth"]["project_id"]
mapping[vo_name] = {"tenant": vo_project}
print(json.dumps(mapping, indent=4))
def load_config(f):
return yaml.safe_load(open(f))
def main():
parser = argparse.ArgumentParser(
description="Generate config files for EGI integration."
)
parser.add_argument("site", metavar="SITE.yaml", help="site config file", nargs=1)
parser.add_argument(
"--vo-mappings",
default="vo-mappings.yaml",
help="File with the default mappings",
)
parser.add_argument(
"--config-type",
default="keystone",
choices=["keystone", "caso", "cloudkeeper-os"],
help="Type of configuration to generate",
)
args = parser.parse_args()
site = load_config(args.site[0])
entitlements = load_config(args.vo_mappings)["vos"]
config_options = {
"keystone": keystone_config,
"caso": caso_config,
"cloudkeeper-os": cloudkeeper_config,
}
config_options[args.config_type](site, entitlements)
if __name__ == "__main__":
main()