ui: Allow devices to be unverified over the dbus API.

This commit is contained in:
Damir Jelić 2019-04-18 14:01:57 +02:00
parent 2ae5e181bc
commit daacd340f9
2 changed files with 69 additions and 30 deletions

View File

@ -25,7 +25,12 @@ from nio import EncryptionError, GroupEncryptionError, LoginResponse
from pantalaimon.client import PanClient
from pantalaimon.log import logger
from pantalaimon.store import ClientInfo, PanStore
from pantalaimon.ui import glib_loop, shutdown_glib_loop, DeviceVerifyMessage
from pantalaimon.ui import (
glib_loop,
shutdown_glib_loop,
DeviceVerifyMessage,
DeviceUnverifyMessage
)
@attr.s
@ -89,32 +94,53 @@ class ProxyDaemon:
loop = asyncio.get_event_loop()
self.queue_task = loop.create_task(self.queue_loop())
def _verify_device(self, client, device):
ret = client.verify_device(device)
if ret:
logger.info(f"Device {device.id} of user "
f"{device.user_id} succesfully verified")
else:
logger.info(f"Device {device.id} of user "
f"{device.user_id} already verified")
pass
def _unverify_device(self, client, device):
ret = client.unverify_device(device)
if ret:
logger.info(f"Device {device.id} of user "
f"{device.user_id} succesfully unverified")
else:
logger.info(f"Device {device.id} of user "
f"{device.user_id} already unverified")
async def queue_loop(self):
message = await self.recv_queue.get()
logger.debug(f"Daemon got message {message}")
while True:
message = await self.recv_queue.get()
logger.debug(f"Daemon got message {message}")
if isinstance(message, DeviceVerifyMessage):
client = self.pan_clients.get(message.pan_user, None)
if isinstance(
message,
(DeviceVerifyMessage, DeviceUnverifyMessage)
):
client = self.pan_clients.get(message.pan_user, None)
if not client:
return
if not client:
return
device = client.device_store[message.user_id].get(
message.device_id,
None
)
device = client.device_store[message.user_id].get(
message.device_id,
None
)
if not device:
return
if not device:
return
ret = client.verify_device(device)
if ret:
logger.info(f"Device {message.device_id} of user "
f"{message.user_id} succesfully verified")
else:
logger.info(f"Device {message.device_id} of user "
f"{message.user_id} already verified")
if isinstance(message, DeviceVerifyMessage):
self._verify_device(client, device)
else:
self._unverify_device(client, device)
def get_access_token(self, request):
# type: (aiohttp.web.BaseRequest) -> str

View File

@ -31,12 +31,22 @@ class DevicesMessage(Message):
@attr.s
class DeviceVerifyMessage(Message):
class _VerificationMessage(Message):
pan_user = attr.ib()
user_id = attr.ib()
device_id = attr.ib()
@attr.s
class DeviceVerifyMessage(_VerificationMessage):
pass
@attr.s
class DeviceUnverifyMessage(_VerificationMessage):
pass
class Devices(dbus.service.Object):
def __init__(self, bus_name, queue, device_list):
super().__init__(bus_name, "/org/pantalaimon/Devices")
@ -51,14 +61,6 @@ class Devices(dbus.service.Object):
@dbus.service.method("org.pantalaimon.devices.verify",
in_signature="sss")
def verify(self, pan_user, user_id, device_id):
device_store = self.device_list.get(pan_user)
if not device_store:
logger.debug(f"Not verifying device, no store found for user "
f"{pan_user}")
return
logger.debug(f"Verifying device {user_id} {device_id}")
message = DeviceVerifyMessage(
pan_user,
user_id,
@ -67,6 +69,17 @@ class Devices(dbus.service.Object):
self.queue.put(message)
return
@dbus.service.method("org.pantalaimon.devices.unverify",
in_signature="sss")
def unverify(self, pan_user, user_id, device_id):
message = DeviceUnverifyMessage(
pan_user,
user_id,
device_id
)
self.queue.put(message)
return
@dbus.service.method("org.pantalaimon.devices.start_verification",
in_signature="sss")
def start_verify(self, pan_user, user_id, device_id):