Skip to content

Commit

Permalink
set-route: merge headers config to one file
Browse files Browse the repository at this point in the history
  • Loading branch information
gsanchietti committed Aug 11, 2023
1 parent e089b89 commit 4525fa2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 70 deletions.
19 changes: 16 additions & 3 deletions imageroot/actions/set-route/20writeconfig
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ elif data.get("host") is not None:
else:
route = { "rule": f'Path(`{path}`) || PathPrefix(`{path_prefix}`)', "priority": "1"}

# Setup routers
route["service"] = data["instance"]
router_http = { f'{data["instance"]}-http': route }
route_s = route.copy()
Expand Down Expand Up @@ -95,13 +96,25 @@ if data.get('user_created') is not None and data["user_created"] is True:
if data.get("forward_auth"):
middlewares[f'{data["instance"]}-auth'] = { "forwardAuth": {"address": data["forward_auth"]["address"], "tls": { "insecureSkipVerify": data["forward_auth"].get("skip_tls_verify", False) }}}
router_http[f'{data["instance"]}-http']["middlewares"].append(f'{data["instance"]}-auth')
router_https[f'{data["instance"]}-httw']["middlewares"].append(f'{data["instance"]}-auth')
router_https[f'{data["instance"]}-https']["middlewares"].append(f'{data["instance"]}-auth')

# Write headers configuration
if "headers" in data and data["headers"]:
headers = { 'headers': {} }
if ("request" in data["headers"] and data["headers"]["request"]):
headers['headers']['customRequestHeaders'] = data['headers']['request']
if ("response" in data["headers"] and data["headers"]["response"]):
headers['headers']['customResponseHeaders'] = data['headers']['response']
if headers['headers']:
middlewares[f'{data["instance"]}-headers'] = headers

router_http[f'{data["instance"]}-http']["middlewares"].append(f'{data["instance"]}-headers')
router_https[f'{data["instance"]}-https']["middlewares"].append(f'{data["instance"]}-headers')

# Write the configuration
config = { "http": {"services": services, "routers": [router_http, router_https] }}
if middlewares:
config["middlewares"] = middlewares


# Write the configuration
with open(f'configs/{data["instance"]}.yml', 'w') as fp:
fp.write(yaml.dump(config))
67 changes: 0 additions & 67 deletions imageroot/actions/set-route/21writeconfigfile

This file was deleted.

0 comments on commit 4525fa2

Please sign in to comment.