forked from SUNET/docker-varnish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen-vcl.py
executable file
·42 lines (33 loc) · 977 Bytes
/
gen-vcl.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
#!/usr/bin/env python3
import sys
import os
import yaml
from jinja2 import Template
from urllib.parse import urlparse
def _render(d):
with open(sys.argv[1]) as template:
t = Template(template.read())
print(t.render(**d))
data = None
if len(sys.argv) == 3:
with open(sys.argv[2]) as config:
data = yaml.load(config.read())
elif 'BACKEND_PORT' in os.environ:
backend_uri = os.environ['BACKEND_PORT']
backend_uri = backend_uri.replace("tcp://", "http://")
if not backend_uri.endswith("/"):
backend_uri = "%s/" % backend_uri
uri = urlparse(backend_uri)
data = {
'backend': {
'hostname': uri.hostname,
'port': uri.port,
'path': uri.path,
}
}
else:
print("No linked applications and no config")
sys.exit(-1)
if 'FORBIDDEN_PATHS' in os.environ:
data['forbidden_paths'] = [p.strip() for p in os.environ['FORBIDDEN_PATHS'].split(';')]
_render(data)