async def _greet_invitation(config, device, token): async with backend_authenticated_cmds_factory( addr=device.organization_addr, device_id=device.device_id, signing_key=device.signing_key, keepalive=config.backend_connection_keepalive, ) as cmds: async with spinner("Retrieving invitation info"): rep = await cmds.invite_list() if rep["status"] != "ok": raise RuntimeError(f"Backend error: {rep}") for invitation in rep["invitations"]: if invitation["token"] == token: break else: raise RuntimeError(f"Invitation not found") if invitation["type"] == InvitationType.USER: initial_ctx = UserGreetInitialCtx(cmds=cmds, token=token) do_greet = partial(_do_greet_user, device, initial_ctx) else: assert invitation["type"] == InvitationType.DEVICE initial_ctx = DeviceGreetInitialCtx(cmds=cmds, token=token) do_greet = partial(_do_greet_device, device, initial_ctx) while True: try: greet_done = await do_greet() if greet_done: break except InviteError as exc: click.secho(str(exc), fg="red") click.secho("Restarting the invitation process", fg="red")
async def _reset_greeter(self): async with trio.open_nursery() as nursery: greeter_initial_ctx = DeviceGreetInitialCtx( cmds=alice2_backend_cmds, token=self.invitation_addr.token) nursery.start_soon(greeter_initial_ctx.do_wait_peer) yield nursery.cancel_scope.cancel()
async def _run_greeter(): initial_ctx = DeviceGreetInitialCtx(cmds=alice_backend_cmds, token=invitation_addr.token) in_progress_ctx = await initial_ctx.do_wait_peer() await oob_send.send(in_progress_ctx.greeter_sas) in_progress_ctx = await in_progress_ctx.do_wait_peer_trust() choices = in_progress_ctx.generate_claimer_sas_choices(size=5) assert len(choices) == 5 assert in_progress_ctx.claimer_sas in choices claimer_sas = await oob_recv.receive() assert claimer_sas == in_progress_ctx.claimer_sas in_progress_ctx = await in_progress_ctx.do_signify_trust() in_progress_ctx = await in_progress_ctx.do_get_claim_requests() assert in_progress_ctx.requested_device_label == requested_device_label await in_progress_ctx.do_create_new_device( author=alice, device_label=granted_device_label)
async def start_greeting_device(self, token: UUID) -> DeviceGreetInProgress1Ctx: """ Raises: BackendConnectionError InviteError """ initial_ctx = DeviceGreetInitialCtx(cmds=self._backend_conn.cmds, token=token) return await initial_ctx.do_wait_peer()
async def _invite_device_task(cmds, device, device_label, token): initial_ctx = DeviceGreetInitialCtx(cmds=cmds, token=token) in_progress_ctx = await initial_ctx.do_wait_peer() in_progress_ctx = await in_progress_ctx.do_wait_peer_trust() in_progress_ctx = await in_progress_ctx.do_signify_trust() in_progress_ctx = await in_progress_ctx.do_get_claim_requests() await in_progress_ctx.do_create_new_device( author=device, device_label=in_progress_ctx.requested_device_label)
async def step_2_start_greeter(self): cdi_w = self.claim_device_instructions_widget self.greeter_initial_ctx = DeviceGreetInitialCtx( cmds=self.cmds, token=self.invitation_addr.token) self.greeter_in_progress_ctx = await self.greeter_initial_ctx.do_wait_peer( ) cdce_w = await catch_claim_device_widget() assert isinstance(cdce_w, ClaimDeviceCodeExchangeWidget) def _greeter_sas_code_choices_displayed(): assert not cdi_w.isVisible() assert cdce_w.isVisible() assert cdce_w.widget_greeter_code.isVisible() assert cdce_w.code_input_widget.isVisible() assert cdce_w.code_input_widget.code_layout.count() == 4 # TODO: better check on codes await aqtbot.wait_until(_greeter_sas_code_choices_displayed) self.claim_device_code_exchange_widget = cdce_w return "step_3_exchange_greeter_sas"