Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move domain_prefix from MQTT to root in config. #59

Merged
merged 1 commit into from
Sep 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions wgkex/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class MQTT:
broker_url: The broker URL for MQTT to connect to.
username: The username to use for MQTT.
password: The password to use for MQTT.
domain_prefix: The prefix to pre-pend to a given domain.
tls: If TLS is used or not.
broker_port: The port for MQTT to connect on.
keepalive: The keepalive in seconds to use.
Expand All @@ -42,7 +41,6 @@ class MQTT:
broker_url: str
username: str
password: str
domain_prefix: str
tls: bool = False
broker_port: int = 1883
keepalive: int = 5
Expand All @@ -58,7 +56,6 @@ def from_dict(cls, mqtt_cfg: Dict[str, str]) -> "MQTT":
if mqtt_cfg["broker_port"]
else None,
keepalive=int(mqtt_cfg["keepalive"]) if mqtt_cfg["keepalive"] else None,
domain_prefix=mqtt_cfg["domain_prefix"],
)


Expand All @@ -69,10 +66,12 @@ class Config:
Attributes:
domains: The list of domains to listen for.
mqtt: The MQTT configuration.
domain_prefix: The prefix to pre-pend to a given domain.
"""

domains: List[str]
mqtt: MQTT
domain_prefix: str

@classmethod
def from_dict(cls, cfg: Dict[str, str]) -> "Config":
Expand All @@ -83,7 +82,9 @@ def from_dict(cls, cfg: Dict[str, str]) -> "Config":
A Config object.
"""
mqtt_cfg = MQTT.from_dict(cfg["mqtt"])
return cls(domains=cfg["domains"], mqtt=mqtt_cfg)
return cls(
domains=cfg["domains"], mqtt=mqtt_cfg, domain_prefix=cfg["domain_prefix"]
)


@lru_cache(maxsize=10)
Expand Down
4 changes: 2 additions & 2 deletions wgkex/config/config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import config
import yaml

_VALID_CFG = "domains:\n- a\n- b\nmqtt:\n broker_port: 1883\n broker_url: mqtt://broker\n keepalive: 5\n password: pass\n tls: true\n username: user\n domain_prefix: ffmuc_\n"
_INVALID_LINT = "derpmains:\n- a\n- b\nmqtt:\n broker_port: 1883\n broker_url: mqtt://broker\n keepalive: 5\n password: pass\n tls: true\n username: user\n domain_prefix: ffmuc_\n"
_VALID_CFG = "domain_prefix: ffmuc_\ndomains:\n- a\n- b\nmqtt:\n broker_port: 1883\n broker_url: mqtt://broker\n keepalive: 5\n password: pass\n tls: true\n username: user\n"
_INVALID_LINT = "domain_prefix: ffmuc_\nBAD_KEY_FOR_DOMAIN:\n- a\n- b\nmqtt:\n broker_port: 1883\n broker_url: mqtt://broker\n keepalive: 5\n password: pass\n tls: true\n username: user\n"
_INVALID_CFG = "asdasdasdasd"


Expand Down