def create_workflow(): """ Create a new workflow. Payload should be a JSON object. The only required attribute is 'name' for the desired workflow name. Optionally, 'config' can be set to a configuration object in the form "plugin_name: { setting: value, ...}". Returns the newly created workflow as a JSON object. """ data = json.loads(request.data) path = Path(app.config['base_path'])/unicode(data['name']) # Setup default configuration config = app.config['default_config'] # Overlay user-supplied values, if existant user_config = data.get('config', None) if user_config is not None: config = config.with_overlay(user_config) workflow = Workflow(config=config, path=path, step=data.get('step', None), step_done=data.get('step_done', None)) try: workflow.id = persistence.save_workflow(workflow) except persistence.ValidationError as e: return make_response(json.dumps(dict(errors=e.errors)), 400, {'Content-Type': 'application/json'}) return make_response(json.dumps(workflow), 200, {'Content-Type': 'application/json'})
def create_workflow(): """ Create a new workflow. Payload should be a JSON object. The only required attribute is 'name' for the desired workflow name. Optionally, 'config' can be set to a configuration object in the form "plugin_name: { setting: value, ...}". Returns the newly created workflow as a JSON object. """ data = json.loads(request.data) path = Path(app.config['base_path']) / unicode(data['name']) # Setup default configuration config = app.config['default_config'] # Overlay user-supplied values, if existant user_config = data.get('config', None) if user_config is not None: config = config.with_overlay(user_config) workflow = Workflow(config=config, path=path, step=data.get('step', None), step_done=data.get('step_done', None)) try: workflow.id = persistence.save_workflow(workflow) except persistence.ValidationError as e: return make_response(json.dumps(dict(errors=e.errors)), 400, {'Content-Type': 'application/json'}) return make_response(json.dumps(workflow), 200, {'Content-Type': 'application/json'})
def update_workflow(workflow): """ Update a single workflow. Payload should be a JSON object, as returned by the '/workflow/<id>' endpoint. Currently the only attribute that can be updated from the client is the configuration. Returns the updated workflow as a JSON object. """ # TODO: Support renaming a workflow, i.e. rename directory as well data = json.loads(request.data) name = data.get('name') if workflow.path.name != name: new_path = workflow.path.parent/name workflow.path.rename(new_path) workflow.path = new_path config = data.get('config') # Update workflow configuration workflow.config.set(config) # Persist to disk persistence.save_workflow(workflow) return make_response(json.dumps(workflow), 200, {'Content-Type': 'application/json'})
def update_workflow(workflow): """ Update a single workflow. Payload should be a JSON object, as returned by the '/workflow/<id>' endpoint. Currently the only attribute that can be updated from the client is the configuration. Returns the updated workflow as a JSON object. """ # TODO: Support renaming a workflow, i.e. rename directory as well data = json.loads(request.data) name = data.get('name') if workflow.path.name != name: new_path = workflow.path.parent / name workflow.path.rename(new_path) workflow.path = new_path config = data.get('config') # Update workflow configuration workflow.config.set(config) # Persist to disk persistence.save_workflow(workflow) return make_response(json.dumps(workflow), 200, {'Content-Type': 'application/json'})