Skip to content

Commit

Permalink
rest: upload files and dirs to workflow fixes
Browse files Browse the repository at this point in the history
* FIXES formatting of the paths that are created
  from uploading files or directories to a workflow.

Signed-off-by: Dinos Kousidis <dinos.kousidis@cern.ch>
  • Loading branch information
dinosk committed Apr 17, 2018
1 parent 3e8554b commit 5dc9d80
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 4 additions & 0 deletions reana_workflow_controller/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,7 @@ class WorkflowInexistentError(Exception):

class REANAWorkflowControllerError(Exception):
"""Error when trying to manage workflows."""


class UploadPathError(Exception):
"""Provided paths contain '../'."""
11 changes: 8 additions & 3 deletions reana_workflow_controller/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from reana_workflow_controller.config import (DEFAULT_NAME_FOR_WORKFLOWS,
SHARED_VOLUME_PATH)
from reana_workflow_controller.errors import (REANAWorkflowControllerError,
UploadPathError,
WorkflowInexistentError,
WorkflowNameError)
from reana_workflow_controller.factory import db
Expand Down Expand Up @@ -416,7 +417,6 @@ def seed_workflow_workspace(workflow_id_or_name):
try:
user_uuid = request.args['user']
file_ = request.files['file_content']
# file_name = secure_filename(request.args['file_name'])
full_file_name = request.args['file_name']
if not full_file_name:
raise ValueError('The file transferred needs to have name.')
Expand All @@ -428,10 +428,15 @@ def seed_workflow_workspace(workflow_id_or_name):
user_uuid)

filename = full_file_name.split("/")[-1]

# Remove starting '/' in path
if full_file_name[0] == '/':
full_file_name = full_file_name[1:]
elif '..' in full_file_name.split("/"):
raise UploadPathError('Path cannot contain "..".')
path = get_analysis_files_dir(workflow, file_type,
'seed')
if len(full_file_name.split("/")) > 1 and not \
os.path.isabs(full_file_name):
if len(full_file_name.split("/")) > 1:
dirs = full_file_name.split("/")[:-1]
path = os.path.join(path, "/".join(dirs))
if not os.path.exists(path):
Expand Down

0 comments on commit 5dc9d80

Please sign in to comment.