Skip to content

Commit

Permalink
better_update
Browse files Browse the repository at this point in the history
  • Loading branch information
gsanchietti committed Aug 21, 2023
1 parent cb54662 commit c70deb3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 28 deletions.
39 changes: 11 additions & 28 deletions imageroot/bin/redis2yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,13 @@ try:
except:
instance = 'traefik1'

config_tls = { "tls": { "stores": { "default": { "defaultCertificate": { "certFile": "", "keyFile": "" } } } } }
middlewares = {}
services = {}
routers = {}

prefix = f'module/{instance}/kv/'
rdb = agent.redis_connect(host='127.0.0.1', privileged = True)

# TLS default certificate
for key in ["certFile", "keyFile"]:
config_tls["tls"]["stores"]["default"]["defaultCertificate"][key] = rdb.get(f'{prefix}tls/stores/default/defaultCertificate/{key}')

# HTTP
for kv in rdb.scan_iter(f'{prefix}http/*'):
value = rdb.get(kv)
Expand Down Expand Up @@ -77,33 +72,21 @@ for kv in rdb.scan_iter(f'{prefix}http/*'):
# module/traefik1/kv/http/routers/instance1-https/tls/domains/0/main
routers[tmp[1]]['tls']['domains'].append({last: value})

# cleanup routes using default cert
# Cleanup routes using default cert
for r in routers:
if "tls" in routers[r] and (not routers[r]["tls"]["certresolver"] and not routers[r]["tls"]["domains"]):
routers[r]["tls"] = {}

# Generate config files
os.makedirs('configs', exist_ok = True)
with open('configs/_default_cert.yml', 'w') as fpc:
fpc.write(yaml.safe_dump(config_tls, default_flow_style=False, sort_keys=False, allow_unicode=True))

config_middleware = {"http": {"middlewares": {'http2https-redirectscheme': middlewares.pop('http2https-redirectscheme')}}}
with open('configs/_http2https.yml', 'w') as fpm:
fpm.write(yaml.safe_dump(config_middleware, default_flow_style=False, sort_keys=False, allow_unicode=True))

route_api = routers.pop('ApisEndpointHttp')
route_api['priority'] = '100000'
config_api = {"http": {"middlewares": {'ApisEndpointMw0': middlewares.pop('ApisEndpointMw0'), 'ApisEndpointMw1': middlewares.pop('ApisEndpointMw1')}, "routers": {"ApisEndpointHttp": route_api}}}
with open('configs/_api.yml', 'w') as fpm:
fpm.write(yaml.safe_dump(config_api, default_flow_style=False, sort_keys=False, allow_unicode=True))

route_api_server_https = routers.pop('ApiServer-https')
route_api_server_https['priority'] = '100000'
route_api_server_http = routers.pop('ApiServer-http')
route_api_server_http['priority'] = '100000'
config_api_server = {"http": {"middlewares": {'ApiServerMw2': middlewares.pop('ApiServerMw2'), 'ApiServer-stripprefix': middlewares.pop('ApiServer-stripprefix')}, "routers": {"ApiServer-https": route_api_server_https, "ApiServer-https": route_api_server_http}, "services": {"ApiServer": services.pop("ApiServer")}}}
with open('configs/_api_server.yml', 'w') as fpm:
fpm.write(yaml.safe_dump(config_api_server, default_flow_style=False, sort_keys=False, allow_unicode=True))
# Remove well-known configs
try:
middlewares.pop('http2https-redirectscheme')
middlewares.pop('ApisEndpointMw0')
middlewares.pop('ApisEndpointMw1')
routers.pop('ApisEndpointHttp')
routers.pop('ApiServer-https')
routers.pop('ApiServer-http')
except:
pass

for service in services:
config_service = {"http": { "routers": {}, "services": {service: services[service]}}}
Expand Down
1 change: 1 addition & 0 deletions imageroot/bin/upgrade_to_beta2
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
#

~/.config/actions/create-module/10expandconfig
~/.config/actions/create-module/50create
~/.config/bin/redis2yaml
systemctl --user restart traefik

0 comments on commit c70deb3

Please sign in to comment.