Skip to content

Commit

Permalink
make schema validation optional
Browse files Browse the repository at this point in the history
  • Loading branch information
jschlyter committed Jun 17, 2024
1 parent 3762bda commit 086a202
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
7 changes: 4 additions & 3 deletions evrec/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,10 @@ async def run(self):
jws = JWS()
jws.deserialize(message.payload)
key = verify_jws_with_keys(jws, self.clients_keys)
self.message_validator.validate_message(
str(message.topic), jws.objects["payload"]
)
if self.settings.schema_validation:
self.message_validator.validate_message(
str(message.topic), jws.objects["payload"]
)
if self.settings.mqtt_topic_write:
await self.handle_payload(client, message, jws, key)
else:
Expand Down
2 changes: 2 additions & 0 deletions evrec/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Settings(BaseSettings):
mqtt_topic_read: str
mqtt_topic_write: str | None
mqtt_reconnect_interval: int = DEFAULT_MQTT_RECONNECT_INTERVAL
schema_validation: bool = False

@classmethod
def from_file(cls, filename: str):
Expand All @@ -25,4 +26,5 @@ def from_file(cls, filename: str):
mqtt_reconnect_interval=data.get(
"MQTT_RECONNECT_INTERVAL", DEFAULT_MQTT_RECONNECT_INTERVAL
),
schema_validation=data.get("SCHEMA_VALIDATION", False),
)
2 changes: 2 additions & 0 deletions example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ CLIENTS_DATABASE = "clients"
MQTT_BROKER = "localhost"
MQTT_TOPIC_READ = "events/up/#"
#MQTT_TOPIC_WRITE = "verified"

SCHEMA_VALIDATION = true

0 comments on commit 086a202

Please sign in to comment.