mirror of
https://github.com/EDCD/EDDN.git
synced 2025-04-26 21:22:14 +03:00
Gateway: Start adding types/checking
This commit is contained in:
parent
a41650865b
commit
2a2017ed51
@ -11,6 +11,7 @@ import hashlib
|
|||||||
import logging
|
import logging
|
||||||
import zlib
|
import zlib
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from typing import Dict
|
||||||
from urllib.parse import parse_qs
|
from urllib.parse import parse_qs
|
||||||
|
|
||||||
import gevent
|
import gevent
|
||||||
@ -23,9 +24,6 @@ from pkg_resources import resource_string
|
|||||||
from eddn.conf.Settings import Settings, loadConfig
|
from eddn.conf.Settings import Settings, loadConfig
|
||||||
from eddn.core.Validator import ValidationSeverity, Validator
|
from eddn.core.Validator import ValidationSeverity, Validator
|
||||||
|
|
||||||
# import os
|
|
||||||
|
|
||||||
|
|
||||||
monkey.patch_all()
|
monkey.patch_all()
|
||||||
import bottle
|
import bottle
|
||||||
from bottle import Bottle, request, response
|
from bottle import Bottle, request, response
|
||||||
@ -111,7 +109,7 @@ def extract_message_details(parsed_message):
|
|||||||
|
|
||||||
return uploader_id, software_name, software_version, schema_ref, journal_event
|
return uploader_id, software_name, software_version, schema_ref, journal_event
|
||||||
|
|
||||||
def configure():
|
def configure() -> None:
|
||||||
"""
|
"""
|
||||||
Get the list of transports to bind from settings.
|
Get the list of transports to bind from settings.
|
||||||
|
|
||||||
@ -125,7 +123,7 @@ def configure():
|
|||||||
validator.addSchemaResource(schema_ref, resource_string('eddn.Gateway', schema_file))
|
validator.addSchemaResource(schema_ref, resource_string('eddn.Gateway', schema_file))
|
||||||
|
|
||||||
|
|
||||||
def push_message(parsed_message, topic):
|
def push_message(parsed_message: Dict, topic: str) -> None:
|
||||||
"""
|
"""
|
||||||
Push a message our to subscribed listeners.
|
Push a message our to subscribed listeners.
|
||||||
|
|
||||||
@ -139,7 +137,7 @@ def push_message(parsed_message, topic):
|
|||||||
# announcers with schema as topic
|
# announcers with schema as topic
|
||||||
compressed_msg = zlib.compress(string_message)
|
compressed_msg = zlib.compress(string_message)
|
||||||
|
|
||||||
send_message = f"{str(topic)} |-| {compressed_msg}"
|
send_message = f"{str(topic)!r} |-| {compressed_msg!r}"
|
||||||
|
|
||||||
sender.send(send_message)
|
sender.send(send_message)
|
||||||
stats_collector.tally("outbound")
|
stats_collector.tally("outbound")
|
||||||
@ -231,9 +229,8 @@ def parse_and_error_handle(data):
|
|||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
parsed_message = simplejson.loads(data)
|
parsed_message = simplejson.loads(data)
|
||||||
except (
|
|
||||||
TypeError, ValueError
|
except (MalformedUploadError, TypeError, ValueError) as exc:
|
||||||
) as exc:
|
|
||||||
# Something bad happened. We know this will return at least a
|
# Something bad happened. We know this will return at least a
|
||||||
# semi-useful error message, so do so.
|
# semi-useful error message, so do so.
|
||||||
try:
|
try:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user