From db37c69251b8937054fc6d2ed30e3e88cb0c7161 Mon Sep 17 00:00:00 2001 From: Diego Rodriguez Date: Fri, 6 Oct 2017 15:48:30 +0200 Subject: [PATCH] api: add workflow seeding endpoint Signed-off-by: Diego Rodriguez --- docs/openapi.json | 75 +++++++++++++++++++++++++++++++ reana_workflow_controller/rest.py | 74 ++++++++++++++++++++++++++++++ 2 files changed, 149 insertions(+) diff --git a/docs/openapi.json b/docs/openapi.json index e8671a5d..42b2a801 100644 --- a/docs/openapi.json +++ b/docs/openapi.json @@ -97,6 +97,81 @@ "summary": "Returns all workflows." } }, + "/api/workflows/{workflow_id}/workspace": { + "post": { + "consumes": [ + "multipart/form-data" + ], + "description": "This resource is expecting a workflow UUID and a file to place in the workflow workspace.", + "operationId": "seed_workflow", + "parameters": [ + { + "description": "Required. Organization which the worklow belongs to.", + "in": "query", + "name": "organization", + "required": true, + "type": "string" + }, + { + "description": "Required. UUID of workflow owner.", + "in": "query", + "name": "user", + "required": true, + "type": "string" + }, + { + "description": "Required. Workflow UUID.", + "in": "path", + "name": "workflow_id", + "required": true, + "type": "string" + }, + { + "description": "Required. File to add to the workflow workspace.", + "in": "formData", + "name": "file_content", + "required": true, + "type": "file" + }, + { + "description": "Required. File name.", + "in": "query", + "name": "file_name", + "required": true, + "type": "string" + } + ], + "produces": [ + "application/json" + ], + "responses": { + "200": { + "description": "Request succeeded. The file has been added to the workspace.", + "examples": { + "application/json": { + "message": "Workflow has been added to the workspace", + "workflow_id": "cdcf48b1-c2f3-4693-8230-b066e088c6ac" + } + }, + "schema": { + "properties": { + "message": { + "type": "string" + }, + "workflow_id": { + "type": "string" + } + }, + "type": "object" + } + }, + "400": { + "description": "Request failed. The incoming data specification seems malformed" + } + }, + "summary": "Adds a file to the workflow workspace." + } + }, "/api/yadage/remote": { "post": { "consumes": [ diff --git a/reana_workflow_controller/rest.py b/reana_workflow_controller/rest.py index 5f5ecc54..9d498107 100644 --- a/reana_workflow_controller/rest.py +++ b/reana_workflow_controller/rest.py @@ -25,6 +25,7 @@ import traceback from flask import Blueprint, abort, jsonify, request +from werkzeug.utils import secure_filename from .factory import db from .fsdb import get_all_workflows @@ -147,6 +148,79 @@ def get_workflows(): # noqa return jsonify({"message": str(e)}), 500 +@restapi_blueprint.route('/workflows//workspace', + methods=['POST']) +def seed_workflow_workspace(workflow_id): + r"""Seed workflow workspace. + + --- + post: + summary: Adds a file to the workflow workspace. + description: >- + This resource is expecting a workflow UUID and a file to place in the + workflow workspace. + operationId: seed_workflow + consumes: + - multipart/form-data + produces: + - application/json + parameters: + - name: organization + in: query + description: Required. Organization which the worklow belongs to. + required: true + type: string + - name: user + in: query + description: Required. UUID of workflow owner. + required: true + type: string + - name: workflow_id + in: path + description: Required. Workflow UUID. + required: true + type: string + - name: file_content + in: formData + description: Required. File to add to the workflow workspace. + required: true + type: file + - name: file_name + in: query + description: Required. File name. + required: true + type: string + responses: + 200: + description: >- + Request succeeded. The file has been added to the workspace. + schema: + type: object + properties: + message: + type: string + workflow_id: + type: string + examples: + application/json: + { + "message": "Workflow has been added to the workspace", + "workflow_id": "cdcf48b1-c2f3-4693-8230-b066e088c6ac" + } + 400: + description: >- + Request failed. The incoming data specification seems malformed + """ + try: + file_ = request.files['file_content'].stream.read() + file_name = secure_filename(request.args['file_name']) + return jsonify({'message': 'File successfully transferred'}), 200 + except KeyError as e: + return jsonify({"message": str(e)}), 400 + except Exception as e: + return jsonify({"message": str(e)}), 500 + + @restapi_blueprint.route('/yadage/remote', methods=['POST']) def run_yadage_workflow_from_remote_endpoint(): # noqa r"""Create a new yadage workflow from a remote repository.