s365b.setup.connect =================== .. py:module:: s365b.setup.connect .. autoapi-nested-parse:: The "Connect tenant" step of the setup wizard. State lives in the ``setting`` table (``setup.connect``; the device code itself in the encrypted part), so the UI can poll and an API restart does not lose track. Flow: 1. :func:`start` requests a device code and shows the user code. 2. The UI calls :func:`poll` every few seconds. Once the admin has signed in, provisioning starts in the background and :func:`poll` reports its steps. 3. The result (tenant, app registrations, encrypted private keys) is stored and Microsoft sign-in is switched on. The delegated token is then dropped; nothing that could refresh it was ever requested. Attributes ---------- .. autoapisummary:: s365b.setup.connect.log s365b.setup.connect.STEP_LABELS s365b.setup.connect.Status s365b.setup.connect.INTERRUPTED Classes ------- .. autoapisummary:: s365b.setup.connect.Step s365b.setup.connect.SetupOptions s365b.setup.connect.ConnectState Functions --------- .. autoapisummary:: s365b.setup.connect.plans s365b.setup.connect.current_certificates s365b.setup.connect.enabled_modules s365b.setup.connect.load_state s365b.setup.connect.start s365b.setup.connect.cancel s365b.setup.connect.poll s365b.setup.connect.recover_interrupted s365b.setup.connect.wait_for_provisioning Module Contents --------------- .. py:data:: log .. py:data:: STEP_LABELS .. py:data:: Status .. py:class:: Step Bases: :py:obj:`pydantic.BaseModel` One line of the progress list. .. py:attribute:: key :type: str .. py:attribute:: label :type: str .. py:attribute:: status :type: Literal['pending', 'running', 'done', 'failed', 'skipped'] :value: 'pending' .. py:attribute:: detail :type: str :value: '' .. py:class:: SetupOptions Bases: :py:obj:`s365b.core.settings_store.SettingsGroup` Advanced wizard options. :ivar public_client_id: Public client used for the device code sign-in. Default: Microsoft Graph Command Line Tools. .. py:attribute:: key :value: 'setup.options' .. py:attribute:: public_client_id :type: str :value: '14d82eec-204b-4c2f-b7e8-296a70dab67e' .. py:class:: ConnectState Bases: :py:obj:`s365b.core.settings_store.SettingsGroup` Progress of the "Connect tenant" step, as shown in the wizard. .. py:attribute:: key :value: 'setup.connect' .. py:attribute:: status :type: Status :value: 'idle' .. py:attribute:: user_code :type: str :value: '' .. py:attribute:: verification_uri :type: str :value: '' .. py:attribute:: expires_at :type: datetime.datetime | None :value: None .. py:attribute:: interval :type: int :value: 5 .. py:attribute:: next_poll_at :type: datetime.datetime | None :value: None .. py:attribute:: message :type: str :value: '' .. py:attribute:: started_by :type: str :value: '' .. py:attribute:: admin_upn :type: str :value: '' .. py:attribute:: steps :type: list[Step] .. py:function:: plans(services: s365b.core.services.Services, enabled: dict[str, object], base_url: str, current_certs: dict[s365b.db.models.AppPurpose, str] | None = None) -> list[s365b.setup.provision.AppPlan] Work out which apps to create and what each may do. :param services: Process services (module registry). :param enabled: Parsed configs of the enabled modules, by module ID. :param base_url: Public URL of this server. :param current_certs: Base64 DER of each app's certificate in use now, kept registered during rotation. :returns: Plans for the Backup, Restore and Sign-in apps. .. py:function:: current_certificates(services: s365b.core.services.Services) -> dict[s365b.db.models.AppPurpose, str] :async: Return the stored, unexpired app certificates as base64 DER. :param services: Process services. :returns: Certificate by app purpose. .. py:function:: enabled_modules(services: s365b.core.services.Services) -> dict[str, object] :async: Return parsed configs of the enabled, installed modules. :param services: Process services. :returns: Config by module ID. .. py:function:: load_state(services: s365b.core.services.Services) -> ConnectState :async: Return the current wizard state. :param services: Process services. :returns: The state. .. py:function:: start(services: s365b.core.services.Services, actor: str) -> ConnectState :async: Request a device code for a tenant administrator. :param services: Process services. :param actor: Username starting the connection (for the audit log). :returns: The new state, with the user code to show. :raises DeviceCodeError: If Entra refuses to start the flow. :raises RuntimeError: If provisioning is already running. .. py:function:: cancel(services: s365b.core.services.Services) -> ConnectState :async: Abandon a pending sign-in (not a running provisioning). :param services: Process services. :returns: The reset state. .. py:function:: poll(services: s365b.core.services.Services) -> ConnectState :async: Advance the flow: check the sign-in, or report provisioning progress. :param services: Process services. :returns: The current state. .. py:data:: INTERRUPTED :value: 'Interrupted: the server restarted while setting up. Start again: apps already created in... .. py:function:: recover_interrupted(services: s365b.core.services.Services) -> bool :async: At startup: end a provisioning the previous server process was running. Provisioning runs inside the API process; after a restart nothing is working on it any more, and the wizard would wait forever. :param services: Process services. :returns: Whether a provisioning was marked interrupted. .. py:function:: wait_for_provisioning() -> None :async: Wait for background provisioning to finish (tests, shutdown).