Skip to content

Instantly share code, notes, and snippets.

@JonasGroeger
Created August 10, 2021 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JonasGroeger/6a776cfe808454dc55aee444dcc7ce3f to your computer and use it in GitHub Desktop.
Save JonasGroeger/6a776cfe808454dc55aee444dcc7ce3f to your computer and use it in GitHub Desktop.
mergeconf
from flask import Flask
import requests
import yaml
app = Flask(__name__)
def combine(a, b):
a = dict(a)
b = dict(b)
c = {"http": {}}
c["http"]["routers"] = dict(a["http"]["routers"] | b["http"]["routers"])
c["http"]["middlewares"] = dict(a["http"]["middlewares"] | b["http"]["middlewares"])
c["http"]["services"] = dict(a["http"]["services"] | b["http"]["services"])
return c
@app.route("/api")
def merge():
a = yaml.safe_load(requests.get("http://nginx1/config.yml").text)
b = yaml.safe_load(requests.get("http://nginx2/config.yml").text)
c = combine(a, b)
return yaml.safe_dump(c), 200
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment