Skip to content

Commit

Permalink
schema: update validate schema
Browse files Browse the repository at this point in the history
Update validate schema to restrict the directives allowed and to be consisten with the documentation

Closes #562, Closes #404
  • Loading branch information
marcdiazsan committed Sep 29, 2021
1 parent 40fc775 commit f55d656
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 91 deletions.
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ The list of contributors in alphabetical order:
- `Adelina Lintuluoto <https://orcid.org/0000-0002-0726-1452>`_
- `Audrius Mecionis <https://orcid.org/0000-0002-3759-1663>`_
- `Anton Khodak <https://orcid.org/0000-0003-3263-4553>`_
- `Camila Diaz <https://orcid.org/0000-0001-5543-797X>`_
- `Daniel Prelipcean <https://orcid.org/0000-0002-4855-194X>`_
- `Diego Rodriguez <https://orcid.org/0000-0003-0649-2002>`_
- `Dinos Kousidis <https://orcid.org/0000-0002-4914-4289>`_
Expand Down
142 changes: 62 additions & 80 deletions reana_client/schemas/reana_analysis_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,91 +6,19 @@
"title": "REANA analysis specification",
"description": "Full analysis specification including data, sofware, environment and workflow enabling reproducibility on a REANA cluster.",
"required": ["workflow"],
"additionalProperties": false,
"properties": {
"environments": {
"id": "/properties/environments",
"type": "array",
"title": "Set of analysis' environments.",
"description": "All container images needed to reproduce the analysis.",
"items": {
"id": "/properties/environments/items",
"type": "object",
"optional": true,
"title": "Analysis environments.",
"description": "Analysis environments represented by container technology and image name.",
"properties": {
"image": {
"id": "/properties/environments/items/properties/image",
"type": "string",
"title": "Environment image id.",
"description": "String which represents an image used as environment for one or more steps of an analysis.",
"default": "busybox"
},
"type": {
"id": "/properties/environments/items/properties/type",
"type": "string",
"title": "Container technology.",
"description": "Name which represents a supported container technology to provide as a REANA environment.",
"default": "docker"
}
}
}
},
"metadata": {
"id": "/properties/metadata",
"type": "object",
"title": "Analysis metadata.",
"properties": {
"author": {
"id": "/properties/metadata/properties/author",
"type": "string",
"title": "Analysis author.",
"description": "User or group who created the analysis.",
"default": "@reanahub/developers"
},
"title": {
"id": "/properties/metadata/properties/title",
"type": "string",
"title": "Analysis title",
"default": "REANA analysis example"
}
}
},
"outputs": {
"id": "/properties/outputs",
"type": "object",
"title": "Analysis outputs.",
"properties": {
"files": {
"id": "/properties/outputs/properties/files",
"type": "array",
"title": "Analysis result files.",
"description": "Expected output from analysis represented by a set of files.",
"optional": true,
"items": {
"id": "/properties/outputs/properties/files/items",
"type": "string",
"title": "Relative path to the file."
}
},
"directories": {
"id": "/properties/outputs/properties/directories",
"type": "array",
"title": "Analysis result directories.",
"description": "Expected output from analysis represented by a set of directories.",
"optional": true,
"items": {
"id": "/properties/outputs/properties/directories/items",
"type": "string",
"title": "Relative path to the directory."
}
}
}
"version": {
"id": "/properties/version",
"type": "string",
"title": "REANA version.",
"description": "REANA platform version to which the analysis was written for."
},
"inputs": {
"id": "/properties/inputs",
"type": "object",
"title": "Analysis inputs.",
"additionalProperties": false,
"properties": {
"files": {
"id": "/properties/inputs/properties/files",
Expand Down Expand Up @@ -136,6 +64,7 @@
"type": "object",
"title": "Analysis workflow.",
"description": "Workflow which represents the steps that need to be run to reproduce an analysis.",
"additionalProperties": false,
"properties": {
"specification": {
"id": "/properties/workflow/properties/specification",
Expand Down Expand Up @@ -171,7 +100,60 @@
}
}
},
"required": ["type"]
"oneOf": [
{
"required": ["type","file"]
},
{
"required": ["type","specification"]
}
]
},
"outputs": {
"id": "/properties/outputs",
"type": "object",
"title": "Analysis outputs.",
"additionalProperties": false,
"properties": {
"files": {
"id": "/properties/outputs/properties/files",
"type": "array",
"title": "Analysis result files.",
"description": "Expected output from analysis represented by a set of files.",
"optional": true,
"items": {
"id": "/properties/outputs/properties/files/items",
"type": "string",
"title": "Relative path to the file."
}
},
"directories": {
"id": "/properties/outputs/properties/directories",
"type": "array",
"title": "Analysis result directories.",
"description": "Expected output from analysis represented by a set of directories.",
"optional": true,
"items": {
"id": "/properties/outputs/properties/directories/items",
"type": "string",
"title": "Relative path to the directory."
}
}
}
},
"workspace": {
"id": "/properties/workspace",
"type": "object",
"title": "Workflow workspace.",
"description": "Full workspace path in which the workflow will run.",
"additionalProperties": false,
"properties": {
"root_path": {
"id": "/properties/workspace/properties/root_path",
"type": "string",
"title": "Workspace root path."
}
}
}
}
}
22 changes: 11 additions & 11 deletions reana_client/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,14 @@ def _prepare_kwargs(reana_yaml):
try:
with open(filepath) as f:
reana_yaml = yaml.load(f.read(), Loader=yaml.FullLoader)

if not skip_validation:
display_message(
"Verifying REANA specification file... {filepath}".format(
filepath=filepath
),
msg_type="info",
)
_validate_reana_yaml(reana_yaml)
workflow_type = reana_yaml["workflow"]["type"]
reana_yaml["workflow"]["specification"] = load_workflow_spec(
workflow_type,
Expand All @@ -140,13 +147,6 @@ def _prepare_kwargs(reana_yaml):
)

if not skip_validation:
display_message(
"Verifying REANA specification file... {filepath}".format(
filepath=filepath
),
msg_type="info",
)
_validate_reana_yaml(reana_yaml)
validate_parameters(workflow_type, reana_yaml)

if not skip_validate_environments:
Expand Down Expand Up @@ -191,12 +191,10 @@ def _validate_reana_yaml(reana_yaml):
try:
with open(reana_yaml_schema_file_path, "r") as f:
reana_yaml_schema = json.loads(f.read())

validate(reana_yaml, reana_yaml_schema)
display_message(
"Valid REANA specification file.", msg_type="success", indented=True,
)

except IOError as e:
logging.info(
"Something went wrong when reading REANA validation schema from "
Expand All @@ -206,7 +204,9 @@ def _validate_reana_yaml(reana_yaml):
raise e
except ValidationError as e:
logging.info("Invalid REANA specification: {error}".format(error=e.message))
raise e
raise REANAValidationError(
'==> ERROR: The `reana.yaml` is not valid: "{0}".'.format(e.message)
)


def is_uuid_v4(uuid_or_name):
Expand Down

0 comments on commit f55d656

Please sign in to comment.