From 920fa648837152255c0937b03ec373c13830da42 Mon Sep 17 00:00:00 2001 From: slinderud Date: Tue, 3 Dec 2019 20:23:36 +0100 Subject: Template: bugfixes on templating.py. Added test template that uses API and created a readme --- templating/README.md | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 templating/README.md (limited to 'templating/README.md') diff --git a/templating/README.md b/templating/README.md new file mode 100644 index 0000000..bea1c0a --- /dev/null +++ b/templating/README.md @@ -0,0 +1,70 @@ +# Templating Engine + +This engine does the templating for The Gathering. + +The flask server sits behind varnish and waits for incomming GET requests with a template name and optional variables. + +```varnish +backend templating { + .host = "::1"; + .port = "8081"; +} +.... +if (req.url ~ "^/api/templates") { + set req.url = regsub(req.url,"^/api/templates",""); + set req.backend_hint = templating; +} +``` + +## Requirements + +* Python3 +* jinja2 +* requests +* flask +* netaddr + +## Settings + +``` +python3 templating.py +usage: templating.py [-t TEMPLATES [TEMPLATES ...]] [-h HOST] [-p PORT] [-d] + [-s SERVER] [-x TIMEOUT] + +Process templates for gondul. + +optional arguments: + -t TEMPLATES [TEMPLATES ...], --templates TEMPLATES [TEMPLATES ...] + location of templates + -h HOST, --host HOST host address + -p PORT, --port PORT host port + -d, --debug enable debug mode + -s SERVER, --server SERVER + gondul server address + -x TIMEOUT, --timeout TIMEOUT + gondul server timeout +``` + +## How to test locally + +You need a directory with all the jinja2 templates. I just assume you git cloned the entire gondul repo. + +An example using [test.conf](../web/templates/test.conf) + +```bash +python3 templating.py --host ::1 --port 8081 --templates ../web/templates --server http://tech:rules@:80 +``` + +```bash +curl -s "http://[::1]:8081/test.conf?switch=e1-1" | jq . +{ + "distro_name": "core-dev", + "placement": { + "height": 20, + "width": 250, + "x": "830", + "y": "620" + }, + "tags": [] +} +``` -- cgit v1.2.3 From e9fdb3ff6b6356ba8acbf76781517d3e511cddca Mon Sep 17 00:00:00 2001 From: slinderud Date: Sun, 8 Dec 2019 13:38:13 +0100 Subject: templating: fixes based on PR feedback --- templating/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'templating/README.md') diff --git a/templating/README.md b/templating/README.md index bea1c0a..89f472e 100644 --- a/templating/README.md +++ b/templating/README.md @@ -18,7 +18,7 @@ if (req.url ~ "^/api/templates") { ## Requirements -* Python3 +* Python3.6 * jinja2 * requests * flask -- cgit v1.2.3