- Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathpathmap.py
33 lines (20 loc) · 734 Bytes
/
pathmap.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
# type: ignore
"""Makes GCP path map string for use with a load balancer of all the flask app's routes
For use with gcloud compute url-maps add-path-matcher
See https://cloud.google.com/load-balancing/docs/url-map
"""
importsys
frombrowse.factoryimportcreate_web_app
backend_service=sys.argv[1]
app=create_web_app()
defmappingline(rule):
"""For a bluprint rule it makes the LB mapping line for use with GCP path map."""
hasParam='<'inrule.rule
ifhasParam:
path=rule.rule.split('<')[0] +"*"
else:
path=rule.rule
returnf"{path}={backend_service}"
withapp.app_context():
lines= [mappingline(path) forpathinapp.url_map.iter_rules()]
print(','.join(lines))