generated from stephdl/ns8-kickstart-mariadb
/
20configure_traefik
executable file
·52 lines (43 loc) · 1.32 KB
/
20configure_traefik
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
#!/usr/bin/env python3
#
# Copyright (C) 2022 Nethesis S.r.l.
# SPDX-License-Identifier: GPL-3.0-or-later
#
import json
import sys
import agent
import agent.tasks
import os
# Try to parse the stdin as JSON.
# If parsing fails, output everything to stderr
data = json.load(sys.stdin)
# Setup default values
host = data.get("host")
h2hs = data.get("http2https", True)
le = data.get("lets_encrypt", False)
# Talk with agent using file descriptor.
# Setup configuration from user input.
agent.set_env("TRAEFIK_HOST", host)
agent.set_env("TRAEFIK_HTTP2HTTPS", h2hs)
agent.set_env("TRAEFIK_LETS_ENCRYPT", le)
# Make sure everything is saved inside the environment file
# just before starting systemd unit
agent.dump_env()
# Find default traefik instance for current node
default_traefik_id = agent.resolve_agent_id('traefik@node')
if default_traefik_id is None:
sys.exit(2)
response = agent.tasks.run(
agent_id=agent.resolve_agent_id('traefik@node'),
action='set-route',
data={
'instance': os.environ['MODULE_ID'],
'url': 'http://127.0.0.1:' + os.environ["TCP_PORT"],
'host': host,
'http2https': h2hs,
'lets_encrypt': le,
'headers': {"request":{"X-Forwarded-Proto": "https"}}
},
)
# Check if traefik configuration has been successfull
agent.assert_exp(response['exit_code'] == 0)