Skip to content

Commit

Permalink
Merge pull request #1284 from TheHive-Project/utils/improvements
Browse files Browse the repository at this point in the history
utils improvements
  • Loading branch information
nusantara-self authored Oct 22, 2024
2 parents bffc7ee + 63c399a commit 37973d7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
19 changes: 9 additions & 10 deletions utils/flavors/check_json_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
"""

import json
import jsonschema
from jsonschema import validate
from jsonschema import Draft7Validator, FormatChecker
import sys
import os
import argparse
Expand Down Expand Up @@ -62,23 +61,23 @@ def fixJsonFlavorFile(jsonfile:dict) -> dict:
jsonfile["screenshots"] = screenshots
return jsonfile

def validateFlavorFormat(flavorfile:str, schemafile:str, fix:bool) -> str:
def validateFlavorFormat(flavorfile: str, schemafile: str, fix: bool) -> str:
flavorSchema = openJsonFile(schemafile)
fjson = openJsonFile(flavorfile)
validator = jsonschema.Draft7Validator(flavorSchema, format_checker=jsonschema.draft7_format_checker)
errors = sorted(validator.iter_errors(fjson),key=lambda e: e.path)
if not errors:
formatchecker = FormatChecker()
validator = Draft7Validator(flavorSchema, format_checker=formatchecker)
errors = sorted(validator.iter_errors(fjson), key=lambda e: e.path)
if not errors:
printSuccess(True, flavorfile)
else:
printSuccess(False, flavorfile)
for error in errors:
print("{}: {}".format(error.path,error.message))
print("{}: {}".format(error.path, error.message))
if fix:
print("Fixing {}".format(flavorfile))
j = fixJsonFlavorFile(fjson)
with open(flavorfile, 'w+') as fj:
fj.write(json.dumps(j,indent=4))
fj.write(json.dumps(j, indent=4))
fj.close()


Expand Down Expand Up @@ -118,4 +117,4 @@ def run():
print(e)

if __name__ == '__main__':
run()
run()
4 changes: 4 additions & 0 deletions utils/flavors/flavor_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@
"description": {
"type": "string"
},
"type": {
"type": "string"
},
"multi": {
"type": "boolean"
},
Expand All @@ -109,6 +112,7 @@
"name",
"description",
"multi",
"type",
"required"
]
},
Expand Down
1 change: 1 addition & 0 deletions utils/test_doc/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ mkdocs-git-revision-date-localized-plugin
mkdocs-material
mkdocs-material-extensions
mkdocs-pymdownx-material-extras
mdutils

0 comments on commit 37973d7

Please sign in to comment.