Skip to content

Commit

Permalink
workspaces: add validation function for the workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
marcdiazsan committed Sep 5, 2021
1 parent 76f8f62 commit 6463552
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
2 changes: 2 additions & 0 deletions reana_commons/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,8 @@ def kubernetes_node_label_to_dict(node_label):
DEFAULT_WORKSPACE_PATH = os.getenv("DEFAULT_WORKSPACE_PATH", "/var/reana")
"""Default workspace path defined by the admin."""

ADMIN_ALLOWED_WORKSPACES = os.getenv("ADMIN_ALLOWED_WORKSPACES", None)

K8S_CERN_EOS_MOUNT_CONFIGURATION = {
"volume": {"name": "eos", "hostPath": {"path": "/var/eos"}},
"volumeMounts": {
Expand Down
31 changes: 31 additions & 0 deletions reana_commons/workspaces.py
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

0 comments on commit 6463552

Please sign in to comment.