From 9ff118ed87b34a37d2e2596e859a35a59d518a77 Mon Sep 17 00:00:00 2001 From: "Brian C. Lane" Date: Mon, 13 Nov 2017 10:30:38 -0800 Subject: [PATCH] Add POST /recipes/workspace route Also fix use of workspace in /recipes/info (was using filename instead of recipe name and logic for changed was backwards). --- src/pylorax/api/v0.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/pylorax/api/v0.py b/src/pylorax/api/v0.py index 82290032..1c2bc6e4 100644 --- a/src/pylorax/api/v0.py +++ b/src/pylorax/api/v0.py @@ -79,7 +79,7 @@ def v0_api(api): # Get the workspace version (if it exists) try: with api.config["GITLOCK"].lock: - ws_recipe = workspace_read(api.config["GITLOCK"].repo, "master", filename) + ws_recipe = workspace_read(api.config["GITLOCK"].repo, "master", recipe_name) except Exception as e: ws_recipe = None exceptions.append(str(e)) @@ -105,7 +105,7 @@ def v0_api(api): recipes.append(git_recipe) else: # Both exist, maybe changed, return the workspace recipe - changes.append({"name":recipe_name, "changed":ws_recipe == git_recipe}) + changes.append({"name":recipe_name, "changed":ws_recipe != git_recipe}) recipes.append(ws_recipe) # Sort all the results by case-insensitive recipe name @@ -147,7 +147,6 @@ def v0_api(api): @crossdomain(origin="*") def v0_recipes_new(): """Commit a new recipe""" - errors = [] try: if request.headers['Content-Type'] == "text/x-toml": recipe = recipe_from_toml(request.data) @@ -164,3 +163,20 @@ def v0_api(api): return jsonify(status=False, error={"msg":str(e)}), 400 else: return jsonify(status=True) + + @api.route("/api/v0/recipes/workspace", methods=["POST"]) + @crossdomain(origin="*") + def v0_recipes_workspace(): + """Write a recipe to the workspace""" + try: + if request.headers['Content-Type'] == "text/x-toml": + recipe = recipe_from_toml(request.data) + else: + recipe = recipe_from_dict(request.get_json(cache=False)) + + with api.config["GITLOCK"].lock: + workspace_write(api.config["GITLOCK"].repo, "master", recipe) + except Exception as e: + return jsonify(status=False, error={"msg":str(e)}), 400 + else: + return jsonify(status=True)