Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

workspaces: add validation function for the workflows #286

Merged
merged 2 commits into from
Sep 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions reana_commons/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,19 @@ def kubernetes_node_label_to_dict(node_label):
SHARED_VOLUME_PATH = os.getenv("SHARED_VOLUME_PATH", "/var/reana")
"""Default shared volume path."""

DEFAULT_WORKSPACE_PATH = os.getenv("DEFAULT_WORKSPACE_PATH", SHARED_VOLUME_PATH)
"""Default workspace path defined by the admin."""


def workspaces(workspaces_list):
"""Load the available workspaces as list."""
workspaces_list = workspaces_list.split(",") if workspaces_list else []
return workspaces_list


WORKSPACE_PATHS = workspaces(os.getenv("WORKSPACE_PATHS"))
"""List of allowed workspace paths."""

K8S_CERN_EOS_MOUNT_CONFIGURATION = {
"volume": {"name": "eos", "hostPath": {"path": "/var/eos"}},
"volumeMounts": {
Expand Down
46 changes: 46 additions & 0 deletions reana_commons/openapi_specifications/reana_server.json
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,52 @@
"summary": "Ping the server (healthcheck)"
}
},
"/api/workspaces": {
"get":{
"consumes": [
"application/json"
],
"description": "Get the list of available workspaces.",
"operationId": "workspaces",
"produces": [
"application/json"
],
"responses": {
"200": {
"description": "This resource reports the available workspaces in the cluster.",
"examples": {
"application/json": {
"workspaces_available": ["/usr/share","/eos/home","/var/reana"],
"default": "/usr/share"
}
},
"schema": {
"properties": {
"workspaces_available": {
"type": "array",
"items": {
"type":"string"
}
},
"default": {
"type": "string"
}
},
"type": "object"
}
},
"500": {
"description": "Request failed. Internal server error.",
"examples": {
"application/json": {
"message": "Internal server error."
}
}
}
},
"summary": "Get the list of available workspaces."
}
},
"/api/secrets": {
"get": {
"description": "Get user secrets.",
Expand Down
2 changes: 1 addition & 1 deletion reana_commons/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@

from __future__ import absolute_import, print_function

__version__ = "0.8.0a24"
__version__ = "0.8.0a25"
34 changes: 34 additions & 0 deletions reana_commons/workspaces.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# -*- coding: utf-8 -*-
#
# This file is part of REANA.
# Copyright (C) 2021 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 WORKSPACE_PATHS
import os


def validate_workspace(workspace_option, available_paths=WORKSPACE_PATHS):
"""Validate and return workspace.

:param workspace_option: A string of the workspace.
:returns: A string of the validated workspace.
"""
if workspace_option:
available = any(
os.path.abspath(workspace_option).startswith(
os.path.join(os.path.abspath(path), "")
)
for path in available_paths
)
if not available:
raise REANAValidationError(
'==> ERROR: Desired workspace "{0}" not valid.\nPlease run reana-client workspaces to see the list of allowed prefix values.'.format(
workspace_option
)
)
return workspace_option