-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
workspaces: add default workspace and validate user workspace choice
Add default workspace as an environmental variable coming from the cluster deployment choice. The validation is done centralized in the validate_workspace function Closes reanahub/reana-client#546
- Loading branch information
1 parent
134e943
commit 2fbbac4
Showing
3 changed files
with
90 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
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,30 @@ | ||
# -*- 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.abspath(path)) | ||
for path in available_paths | ||
) | ||
if not available: | ||
raise REANAValidationError( | ||
'==> ERROR: Workspace "{0}" not valid.'.format(workspace_option) | ||
) | ||
return workspace_option |