forked from reanahub/reana-commons
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
workspaces: add validation function for the workflows
Goes on top of reanahub/reana-client#545 PR set, and reanahub/reana#532 PR set Closes reanahub/reana-client#546
- Loading branch information
1 parent
76f8f62
commit 6463552
Showing
2 changed files
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# This file is part of REANA. | ||
# Copyright (C) 2020 CERN. | ||
# | ||
# REANA is free software; you can redistribute it and/or modify it | ||
# under the terms of the MIT License; see LICENSE file for more details. | ||
"""REANA-Commons workspaces util.""" | ||
|
||
from reana_commons.errors import REANAValidationError | ||
from reana_commons.config import ADMIN_ALLOWED_WORKSPACES, SHARED_VOLUME_PATH | ||
|
||
|
||
def validate_workspace(workspace_option): | ||
"""Validate and return workspace. | ||
:param workspace_option: A string of the workspace. | ||
:returns: A string of the validated workspace. | ||
""" | ||
if ADMIN_ALLOWED_WORKSPACES: | ||
allowed_workspaces = ADMIN_ALLOWED_WORKSPACES.split(",") | ||
allowed_workspaces.append(SHARED_VOLUME_PATH) | ||
else: | ||
allowed_workspaces = [SHARED_VOLUME_PATH] | ||
|
||
if workspace_option: | ||
if workspace_option not in allowed_workspaces: | ||
raise REANAValidationError( | ||
'==> ERROR: Workspace "{0}" not valid.'.format(workspace_option) | ||
) | ||
return workspace_option |