diff options
author | Matt Turner <mattst88@gmail.com> | 2020-10-03 21:42:52 -0700 |
---|---|---|
committer | Matt Turner <mattst88@gmail.com> | 2020-10-03 23:46:52 -0700 |
commit | 4731c2addfef06909f88f9cc551546b278fa40ca (patch) | |
tree | d0a8a05af71b90b03b734b3977b93de8fe54e615 | |
parent | 8c46cda25d68fb414484314e036d27c7e53e23d9 (diff) |
mqtt-notify.py: Use asynchronous Secret.password_lookup()
-rwxr-xr-x | mqtt-notify.py | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/mqtt-notify.py b/mqtt-notify.py index cc4aa6c..bf24538 100755 --- a/mqtt-notify.py +++ b/mqtt-notify.py @@ -89,7 +89,7 @@ def on_message(client, userdata, msg): def on_disconnect(client, userdata, rc): print("Disconnected") -def password(user, host): +def password(loop, user, host): # Insert password with secret-tool(1). E.g., # secret-tool store --label="mqtts://example.com" user myuser service mqtt host example.com @@ -101,14 +101,24 @@ def password(user, host): "host": Secret.SchemaAttributeType.STRING, } ) + attributes = { + "user": user, + "service": "mqtt", + "host": host, + } - return Secret.password_lookup_sync(schema, - { - "user": user, - "service": "mqtt", - "host": host, - }, - None) + pw = None + def on_password_lookup(source, result, unused): + loop.quit() + + nonlocal pw + pw = Secret.password_lookup_finish(result) + + while pw is None: + Secret.password_lookup(schema, attributes, None, on_password_lookup, None) + + loop.run() + return pw def config(filename): try: @@ -145,7 +155,7 @@ def main(argv): client = mqtt.Client(userdata=topic) client.tls_set() - client.username_pw_set(user, password(user, broker)) + client.username_pw_set(user, password(loop, user, broker)) client.on_connect = on_connect client.on_message = on_message client.on_disconnect = on_disconnect |