Skip to content

Commit 8e6bcf9

Browse files
committed
Make password a template
1 parent 80cc029 commit 8e6bcf9

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ available context is limited however to `device_attrs`.
8383

8484
### `password`
8585

86-
Indicates a password to supply for authentication.
86+
Indicates a password to supply for authentication. The value is in fact a template that can be customized following the
87+
rules described in [Template Notifications](https://github.com/qtoggle/qtoggleserver/wiki/Template-Notifications). The
88+
available context is limited however to `device_attrs`.
8789

8890
* type: `string`
8991
* default: `null`

qtoggleserver/mqtt/mqtteventhandler.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ def __init__(
8484
self._client_id_template: Template = self.make_template(self.client_id)
8585
if self.username:
8686
self._username_template = self.make_template(self.username)
87+
if self.password:
88+
self._password_template = self.make_template(self.password)
8789

8890
self.client_logger: logging.Logger = self.logger.getChild('client')
8991
if not self.client_logging:
@@ -109,12 +111,15 @@ async def _client_loop(self) -> None:
109111
username = None
110112
if self._username_template:
111113
username = await self._username_template.render_async(template_context)
114+
password = None
115+
if self._password_template:
116+
password = await self._password_template.render_async(template_context)
112117
async with aiomqtt.Client(
113118
hostname=self.server,
114119
port=self.port,
115120
tls_context=tls_context,
116121
username=username,
117-
password=self.password,
122+
password=password,
118123
client_id=client_id,
119124
logger=self.client_logger,
120125
) as client:

0 commit comments

Comments
 (0)