Created
August 10, 2021 14:11
-
-
Save JonasGroeger/6a776cfe808454dc55aee444dcc7ce3f to your computer and use it in GitHub Desktop.
mergeconf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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