summaryrefslogtreecommitdiff
path: root/src/db/schema.py
diff options
context:
space:
mode:
authorKristofer Hallin <kristofer@sunet.se>2022-04-07 14:12:35 +0200
committerKristofer Hallin <kristofer@sunet.se>2022-04-07 14:12:35 +0200
commit208089fa95e63d6e29e7a1d86726bfec804de211 (patch)
treed5ed8e7de790940ade6b46dcb48e126d7357733d /src/db/schema.py
parent9d72acbb816c6040b608c63f18b8dbb169ceb2c3 (diff)
Moved everything database related to db/.
Diffstat (limited to 'src/db/schema.py')
-rw-r--r--src/db/schema.py75
1 files changed, 75 insertions, 0 deletions
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)