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

Conversation

marcdiazsan
Copy link
Contributor

@marcdiazsan marcdiazsan self-assigned this Aug 26, 2021
@marcdiazsan marcdiazsan marked this pull request as draft August 26, 2021 03:51
@codecov-commenter
Copy link

codecov-commenter commented Aug 26, 2021

Codecov Report

Merging #286 (6e3a64d) into master (134e943) will decrease coverage by 0.54%.
The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #286      +/-   ##
==========================================
- Coverage   33.03%   32.48%   -0.55%     
==========================================
  Files          19       20       +1     
  Lines         890      905      +15     
==========================================
  Hits          294      294              
- Misses        596      611      +15     
Impacted Files Coverage Δ
reana_commons/config.py 0.00% <0.00%> (ø)
reana_commons/version.py 0.00% <0.00%> (ø)
reana_commons/workspaces.py 0.00% <0.00%> (ø)

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: docstring is missing.

Perhaps we could split the string and append SHARED_VOLUME_PATH here to have the final list. In that case code will be simplified reana_commons/workspaces.py and this operation will be done only once

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, good change, as I wont have to make that operation in the validation or showing the workspaces

Copy link
Member

@audrium audrium left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few minor comments, it all works fine!

reana_commons/config.py Outdated Show resolved Hide resolved
:param workspace_option: A string of the workspace.
:returns: A string of the validated workspace.
"""
if ADMIN_ALLOWED_WORKSPACES:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see my comment, I think this part could be simplified if we would store the final list in reana-commons

reana_commons/workspaces.py Outdated Show resolved Hide resolved
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, please see my comment about the name

workspaces_list = workspaces_list.split(",")
workspaces_list.append(SHARED_VOLUME_PATH)
else:
workspaces_list = [SHARED_VOLUME_PATH]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very minor: could be simplified like this

workspaces_list = workspaces_list.split(",") if workspaces_list else []
workspaces_list.append(SHARED_VOLUME_PATH)

:returns: A string of the validated workspace.
"""
if workspace_option:
if workspace_option not in WORKSPACE_PATHS:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to take into account that one of the WORKSPACE_PATHS could be for example /eos,
but the user defined workspace would be /eos/user/a/amecioni/workflows/my_super_workflow. So direct comparison would not allow this workspace definition even though it's perfectly valid. I guess for now we could iterate through the WORKSPACE_PATHS list and check if workspace_option startswith() at least one path?

Later some more complex validation could be done (better in a separate PR in the future) to catch all the possible ways to abuse the system, like to catch "../", etc. (thanks @mvidalgarcia for noticing this possibility)

Copy link
Member

@audrium audrium left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nicely done!

@audrium audrium marked this pull request as ready for review September 13, 2021 08:34
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
@audrium audrium merged commit 6e3a64d into reanahub:master Sep 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

validate: check desired workspace value
3 participants