From 208089fa95e63d6e29e7a1d86726bfec804de211 Mon Sep 17 00:00:00 2001 From: Kristofer Hallin Date: Thu, 7 Apr 2022 14:12:35 +0200 Subject: Moved everything database related to db/. --- src/db/schema.py | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 src/db/schema.py (limited to 'src/db/schema.py') diff --git a/src/db/schema.py b/src/db/schema.py new file mode 100644 index 0000000..37da5aa --- /dev/null +++ b/src/db/schema.py @@ -0,0 +1,75 @@ +import json + +import jsonschema + +schema = { + "$schema": "http://json-schema.org/schema#", + "type": "object", + "properties": { + "document_version": { + "type": "integer" + }, + "ip": { + "type": "string" + }, + "port": { + "type": "integer" + }, + "whois_description": { + "type": "string" + }, + "asn": { + "type": "string" + }, + "asn_country_code": { + "type": "string" + }, + "ptr": { + "type": "string" + }, + "abuse_mail": { + "type": "string" + }, + "domain": { + "type": "string" + }, + "timestamp_in_utc": { + "type": "string" + }, + "user_presentation": { + "type": "object", + "properties": { + "description": { + "type": "string" + }, + "data": { + "type": "object" + } + } + } + }, + "required": [ + "document_version", + "ip", + "port", + "timestamp_in_utc", + "user_presentation" + ] +} + + +def validate_collector_data(json_blob): + try: + jsonschema.validate(json_blob, schema) + except jsonschema.exceptions.ValidationError as e: + print(f'Validation failed with error: {e}') + return False + + return True + + +if __name__ == '__main__': + with open('example_data.json') as fd: + json_data = json.loads(fd.read()) + + validate_collector_data(json_data) -- cgit v1.1