new: [build] Validate also feed metadata rules and settings JSON contents

pull/6378/head
Jakub Onderka 2020-10-02 15:37:07 +02:00
parent 20a098217d
commit 2f31fd36c3
2 changed files with 32 additions and 3 deletions

View File

@ -162,9 +162,7 @@ script:
- pushd PyMISP/examples/events/
- poetry run python ./create_massive_dummy_events.py -l 5 -a 30
- popd
- pushd app/files/feed-metadata
- jsonschema -i defaults.json schema.json
- popd
- python3 tools/misp-feed/validate.py
after_failure:
- ls -aRl `pwd`

View File

@ -0,0 +1,31 @@
import os
import sys
import json
import jsonschema
script_path = os.path.dirname(os.path.realpath(__file__))
default_feed_path = script_path + '/../../app/files/feed-metadata/defaults.json'
schema_path = script_path + '/../../app/files/feed-metadata/schema.json'
with open(default_feed_path) as feed_file:
feedlist = json.load(feed_file)
with open(schema_path) as schema_file:
schema = json.load(schema_file)
jsonschema.validate(instance=feedlist, schema=schema)
valid = True
for feed in feedlist:
for json_field in ("rules", "settings"):
if len(feed['Feed'][json_field]) == 0:
continue
try:
json.loads(feed['Feed'][json_field])
except ValueError:
valid = False
print("Invalid JSON for field `{}` for feed `{}`".format(json_field, feed['Feed']['name']))
if not valid:
sys.exit(1)