diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 45c758c..61b6b84 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -18,9 +18,15 @@ jobs: python -m pip install --upgrade pip pip install wheel pip install -r requirements/dev . + npm install -g pajv - name: Launch tests run: | nosetests ./tests - name: Lint config files run: | yamllint -c .yamllint.yml config/organise_configs/*.yml + - name: Validate config files + run: > + pajv + -s config/organise_configs/schema.json + -d config/organise_configs/*.yml diff --git a/config/organise_configs/schema.json b/config/organise_configs/schema.json new file mode 100644 index 0000000..289ff9d --- /dev/null +++ b/config/organise_configs/schema.json @@ -0,0 +1,34 @@ +{ + "type": "object", + "required": ["variables", "files_to_organise"], + "properties": { + "variables": { + "type": "object", + "additionalProperties": {"type": "string"} + }, + "files_to_organise": { + "type": "array", + "items": { + "type": "object", + "required": ["source", "destination", "options"], + "properties": { + "source": {"type": "string"}, + "destination": {"type": "string"}, + "options": { + "type": "object", + "properties": { + "required": {"type": "boolean"}, + "link_type": { + "type": "string", + "enum": ["softlink", "hardlink", "copy"] + }, + "filter": {"type": "string"} + }, + "additionalProperties": false + } + } + } + } + }, + "additionalProperties": false +} diff --git a/delivery/handlers/organise_handlers.py b/delivery/handlers/organise_handlers.py index c651fb3..89eb743 100644 --- a/delivery/handlers/organise_handlers.py +++ b/delivery/handlers/organise_handlers.py @@ -12,41 +12,6 @@ log = logging.getLogger(__name__) -ORGANISE_CONFIG_SCHEMA = { - "type": "object", - "required": ["variables", "files_to_organise"], - "properties": { - "variables": { - "type": "object", - "additionalProperties": {"type": "string"}, - }, - "files_to_organise": { - "type": "array", - "items": { - "type": "object", - "required": ["source", "destination", "options"], - "properties": { - "source": {"type": "string"}, - "destination": {"type": "string"}, - "options": { - "type": "object", - "properties": { - "required": {"type": "boolean"}, - "link_type": { - "type": "string", - "enum": ["softlink", "hardlink", "copy"], - }, - "filter": {"type": "string"}, - }, - "additionalProperties": False, - } - } - } - } - }, - "additionalProperties": False, -} - class BaseOrganiseHandler(BaseRestHandler): pass @@ -145,7 +110,9 @@ def post(self, analysis_pipeline, project): f"Config file not found at {organise_config_path}") with open(organise_config_path, 'r') as organise_config_file: config = yaml.load(organise_config_file, Loader=yaml.CLoader) - jsonschema.validate(config, ORGANISE_CONFIG_SCHEMA) + with open(organise_config_dir / "schema.json", 'r') as organise_config_schema: + schema = json.load(organise_config_schema) + jsonschema.validate(config, schema) if not project_path.is_dir(): raise FileNotFoundError( @@ -176,7 +143,9 @@ def post(self, project): f"Config file not found at {organise_config_path}") with open(organise_config_path, 'r') as organise_config_file: config = yaml.load(organise_config_file, Loader=yaml.CLoader) - jsonschema.validate(config, ORGANISE_CONFIG_SCHEMA) + with open(pathlib.Path(self.config["organise_config_dir"]) / "schema.json", 'r') as organise_config_schema: + schema = json.load(organise_config_schema) + jsonschema.validate(config, schema) if not project_path.is_dir(): raise FileNotFoundError( @@ -211,7 +180,9 @@ def post(self, runfolder): f"Config file not found at {organise_config_path}") with open(organise_config_path, 'r') as organise_config_file: config = yaml.load(organise_config_file, Loader=yaml.CLoader) - jsonschema.validate(config, ORGANISE_CONFIG_SCHEMA) + with open(organise_config_dir / "schema.json", 'r') as organise_config_schema: + schema = json.load(organise_config_schema) + jsonschema.validate(config, schema) if not runfolder_path.is_dir(): raise FileNotFoundError(