From 413964b92f65563dcf4e2bd34936dcdbd8039f3b Mon Sep 17 00:00:00 2001 From: "Brian C. Lane" Date: Thu, 8 Mar 2018 14:24:37 -0800 Subject: [PATCH] Add ?format=toml support to /recipes/info/ This will return the recipe in TOML format. Note that this does not include any extra information about errors. Just the recipes, any unrecognized recipe names will be skipped. --- src/pylorax/api/v0.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/pylorax/api/v0.py b/src/pylorax/api/v0.py index 6d80e847..2df76675 100644 --- a/src/pylorax/api/v0.py +++ b/src/pylorax/api/v0.py @@ -959,6 +959,7 @@ def v0_api(api): def v0_recipes_info(recipe_names): """Return the contents of the recipe, or a list of recipes""" branch = request.args.get("branch", "master") + out_fmt = request.args.get("format", "json") recipes = [] changes = [] errors = [] @@ -1003,7 +1004,11 @@ def v0_api(api): recipes = sorted(recipes, key=lambda r: r["name"].lower()) errors = sorted(errors, key=lambda e: e["recipe"].lower()) - return jsonify(changes=changes, recipes=recipes, errors=errors) + if out_fmt == "toml": + # With TOML output we just want to dump the raw recipe, skipping the rest. + return "\n\n".join([r.toml() for r in recipes]) + else: + return jsonify(changes=changes, recipes=recipes, errors=errors) @api.route("/api/v0/recipes/changes/") @crossdomain(origin="*")