From 2fcd75c3d94de68de5679c4b5c4b5de1638a0e64 Mon Sep 17 00:00:00 2001 From: Matteo Campinoti Date: Fri, 3 Nov 2023 07:52:33 +0100 Subject: [PATCH 1/6] custom_signatures.schema - add schema for custom signatures --- custom_signatures.schema.json | 51 +++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 custom_signatures.schema.json diff --git a/custom_signatures.schema.json b/custom_signatures.schema.json new file mode 100644 index 0000000..b9a2c4d --- /dev/null +++ b/custom_signatures.schema.json @@ -0,0 +1,51 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "actions", + "type": "array", + "items": { + "type": "object", + "additionalProperties": false, + "dependencies": { + "operator": [ + "bof", + "eof" + ] + }, + "if": { + "required": [ + "bof", + "eof" + ] + }, + "then": { + "required": [ + "operator" + ] + }, + "properties": { + "bof": { + "type": "string" + }, + "eof": { + "type": "string" + }, + "operator": { + "type": "string", + "enum": [ + "AND", + "OR", + "XOR" + ] + }, + "puid": { + "type": "string" + }, + "signature": { + "type": "string" + }, + "extension": { + "type": "string" + } + } + } +} \ No newline at end of file From 9604b237b9e1714a9c42f29f1bc524c85561b6a8 Mon Sep 17 00:00:00 2001 From: Matteo Campinoti Date: Fri, 3 Nov 2023 08:13:31 +0100 Subject: [PATCH 2/6] fileformats.schema - require property for each action type --- fileformats.schema.json | 62 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/fileformats.schema.json b/fileformats.schema.json index b7d8aad..6c234cf 100644 --- a/fileformats.schema.json +++ b/fileformats.schema.json @@ -9,6 +9,68 @@ "name", "action" ], + "oneOf": [ + { + "properties": { + "action": { + "const": "convert" + } + }, + "required": [ + "convert" + ] + }, + { + "properties": { + "action": { + "const": "extract" + } + }, + "required": [ + "extract" + ] + }, + { + "properties": { + "action": { + "const": "manual" + } + }, + "required": [ + "manual" + ] + }, + { + "properties": { + "action": { + "const": "rename" + } + }, + "required": [ + "rename" + ] + }, + { + "properties": { + "action": { + "const": "ignore" + } + }, + "required": [ + "ignore" + ] + }, + { + "properties": { + "action": { + "const": "reidentify" + } + }, + "required": [ + "reidentify" + ] + } + ], "properties": { "name": { "type": "string" From eca4cc1d2fb1def1d29eb5f62e9ae23d0c336607 Mon Sep 17 00:00:00 2001 From: Matteo Campinoti Date: Fri, 3 Nov 2023 08:14:46 +0100 Subject: [PATCH 3/6] fileformats.schema - disallow empty PUID keys --- fileformats.schema.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fileformats.schema.json b/fileformats.schema.json index 6c234cf..c84a4c7 100644 --- a/fileformats.schema.json +++ b/fileformats.schema.json @@ -2,8 +2,9 @@ "$schema": "https://json-schema.org/draft/2020-12/schema", "$id": "actions", "type": "object", + "additionalProperties": false, "patternProperties": { - ".*": { + ".+": { "type": "object", "required": [ "name", From 1713ed6deaae623ecdaeeb0d4e15822e22c8ebc1 Mon Sep 17 00:00:00 2001 From: Matteo Campinoti Date: Fri, 3 Nov 2023 08:16:54 +0100 Subject: [PATCH 4/6] fileformats.schema - stricter pattern matching of PUID keys --- fileformats.schema.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fileformats.schema.json b/fileformats.schema.json index c84a4c7..e30373f 100644 --- a/fileformats.schema.json +++ b/fileformats.schema.json @@ -4,7 +4,7 @@ "type": "object", "additionalProperties": false, "patternProperties": { - ".+": { + "^[a-zA-Z0-9_/-]+$": { "type": "object", "required": [ "name", From 077459aa557903cf8a50c1b52662de824aea68c4 Mon Sep 17 00:00:00 2001 From: Matteo Campinoti Date: Fri, 3 Nov 2023 09:25:13 +0100 Subject: [PATCH 5/6] workflows:check-json - check schemata dynamically --- .github/workflows/check-json.yml | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/.github/workflows/check-json.yml b/.github/workflows/check-json.yml index ccd8e55..1f966c8 100644 --- a/.github/workflows/check-json.yml +++ b/.github/workflows/check-json.yml @@ -25,5 +25,15 @@ jobs: uses: limitusus/json-syntax-check@v2 with: pattern: "\\.json$" - - name: Check Actions Schema - run: python -c 'import yaml,json,jsonschema,sys;jsonschema.validate(yaml.load(open(sys.argv[1]), yaml.Loader), json.load(open(sys.argv[2])))' fileformats.yml fileformats.schema.json \ No newline at end of file + - name: Check JSON Schemata + run: | + for schema in *.schema.json; do + [[ -f "${schema%.schema.json}.json" ]] && python3 -c 'import json,jsonschema,sys;jsonschema.validate(json.load(open(sys.argv[1])), json.load(open(sys.argv[2])))' "${schema%.schema.json}.json" "$schema"; + done + - name: Check YAML Schemata + run: | + for schema in *.schema.json; do + for ext in "yaml" "yml"; do + [[ -f "${schema%.schema.json}.$ext" ]] && python3 -c 'import yaml,json,jsonschema,sys;jsonschema.validate(yaml.load(open(sys.argv[1]), yaml.Loader), json.load(open(sys.argv[2])))' "${schema%.schema.json}.$ext" "$schema"; + done + done \ No newline at end of file From 525709b65444e5dc9fa92afa816540b3aef997ab Mon Sep 17 00:00:00 2001 From: Matteo Campinoti Date: Fri, 3 Nov 2023 09:30:00 +0100 Subject: [PATCH 6/6] workflows:check-json - fix return code of file tests --- .github/workflows/check-json.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/check-json.yml b/.github/workflows/check-json.yml index 1f966c8..ecea4be 100644 --- a/.github/workflows/check-json.yml +++ b/.github/workflows/check-json.yml @@ -28,12 +28,16 @@ jobs: - name: Check JSON Schemata run: | for schema in *.schema.json; do - [[ -f "${schema%.schema.json}.json" ]] && python3 -c 'import json,jsonschema,sys;jsonschema.validate(json.load(open(sys.argv[1])), json.load(open(sys.argv[2])))' "${schema%.schema.json}.json" "$schema"; + if [[ -f "${schema%.schema.json}.json" ]]; then + python3 -c 'import json,jsonschema,sys;jsonschema.validate(json.load(open(sys.argv[1])), json.load(open(sys.argv[2])))' "${schema%.schema.json}.json" "$schema"; + fi; done - name: Check YAML Schemata run: | for schema in *.schema.json; do for ext in "yaml" "yml"; do - [[ -f "${schema%.schema.json}.$ext" ]] && python3 -c 'import yaml,json,jsonschema,sys;jsonschema.validate(yaml.load(open(sys.argv[1]), yaml.Loader), json.load(open(sys.argv[2])))' "${schema%.schema.json}.$ext" "$schema"; + if [[ -f "${schema%.schema.json}.$ext" ]]; then + python3 -c 'import yaml,json,jsonschema,sys;jsonschema.validate(yaml.load(open(sys.argv[1]), yaml.Loader), json.load(open(sys.argv[2])))' "${schema%.schema.json}.$ext" "$schema"; + fi; done done \ No newline at end of file