Skip to content

Commit

Permalink
validate: add validate-sections to validate misspelled directives or …
Browse files Browse the repository at this point in the history
…directives in reana.yaml

Closes reanahub#562
  • Loading branch information
marcdiazsan committed Sep 27, 2021
1 parent 40fc775 commit 1bcaed0
Showing 1 changed file with 47 additions and 1 deletion.
48 changes: 47 additions & 1 deletion reana_client/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,11 @@ def _prepare_kwargs(reana_yaml):
try:
with open(filepath) as f:
reana_yaml = yaml.load(f.read(), Loader=yaml.FullLoader)

try:
_validate_sections(reana_yaml)
except REANAValidationError as e:
display_message(e.message, msg_type="error")
sys.exit(1)
workflow_type = reana_yaml["workflow"]["type"]
reana_yaml["workflow"]["specification"] = load_workflow_spec(
workflow_type,
Expand Down Expand Up @@ -435,3 +439,45 @@ def _validate_workspace(workspace, access_token):
except REANAValidationError as e:
display_message(e.message, msg_type="error")
sys.exit(1)


def _validate_sections(reana_yaml):
"""Validate sections of the REANA specification file.
:param reana_yaml: Dictionary which represents REANA specifications file.
:raises ValidationError: Given sections in REANA spec file do not validate.
"""
inputs_sections = ["directories", "files", "parameters", "options"]
workflow_sections = ["type", "file", "specification"]
outputs_sections = ["directories", "files"]
workspace_sections = ["root_path"]
sections = {
"version": None,
"inputs": inputs_sections,
"workflow": workflow_sections,
"outputs": outputs_sections,
"workspace": workspace_sections,
}
incorrect_sections = [
section for section in reana_yaml.keys() if section not in sections.keys()
]
if len(incorrect_sections) != 0:
raise REANAValidationError(
'The `reana.yaml` directive "{0}" not valid.'.format(
", ".join(incorrect_sections)
)
)
incorrect_subsections = []
for section in reana_yaml.keys():
if isinstance(reana_yaml[section], dict):
incorrect_subsections = incorrect_subsections + [
".".join((section, subsection))
for subsection in reana_yaml[section].keys()
if subsection not in sections[section]
]
if len(incorrect_subsections) != 0:
raise REANAValidationError(
'The `reana.yaml` directive "{0}" not valid.'.format(
", ".join(incorrect_subsections)
)
)

0 comments on commit 1bcaed0

Please sign in to comment.