s365b.setup.provision ===================== .. py:module:: s365b.setup.provision .. autoapi-nested-parse:: Create or update the app registrations with a delegated admin token. Idempotent: apps are found again by their ``s365b:`` tag and updated in place, so the wizard can be re-run (to add permissions for a newly enabled module, renew certificates, or repair a half-finished run). Entra replicates new objects between regions for a few seconds; calls that depend on a just-created object are retried. Attributes ---------- .. autoapisummary:: s365b.setup.provision.GRAPH_APP_ID s365b.setup.provision.SIGNIN_SCOPES s365b.setup.provision.DISPLAY_NAMES s365b.setup.provision.StepStatus s365b.setup.provision.Report Exceptions ---------- .. autoapisummary:: s365b.setup.provision.ProvisionError Classes ------- .. autoapisummary:: s365b.setup.provision.AppPlan s365b.setup.provision.AppResult s365b.setup.provision.ProvisionResult s365b.setup.provision.Provisioner Functions --------- .. autoapisummary:: s365b.setup.provision.role_id Module Contents --------------- .. py:data:: GRAPH_APP_ID :value: '00000003-0000-0000-c000-000000000000' .. py:data:: SIGNIN_SCOPES :value: ('openid', 'profile', 'email', 'User.Read') .. py:data:: DISPLAY_NAMES .. py:data:: StepStatus .. py:data:: Report .. py:exception:: ProvisionError Bases: :py:obj:`Exception` Provisioning cannot continue. The message is safe to show. .. py:function:: role_id(value: str) -> str Stable ID for one of the sign-in app's roles (same in every tenant). :param value: App role value such as ``S365B.Admin``. :returns: The role's GUID. .. py:class:: AppPlan What one app registration should look like. :ivar purpose: Which app. :ivar app_permissions: Microsoft Graph application permissions to grant. :ivar delegated_scopes: Graph delegated scopes to consent for all users. :ivar redirect_uri: Web redirect URI (sign-in app only). :ivar previous_certificate: Base64 DER of the certificate in use now. It stays registered next to the new one, so running jobs and not-yet-replicated Entra servers keep working during rotation; the next rotation drops it. .. py:attribute:: purpose :type: s365b.db.models.AppPurpose .. py:attribute:: app_permissions :type: frozenset[str] .. py:attribute:: delegated_scopes :type: tuple[str, ...] :value: () .. py:attribute:: redirect_uri :type: str | None :value: None .. py:attribute:: previous_certificate :type: str | None :value: None .. py:class:: AppResult An app registration after provisioning. :ivar purpose: Which app. :ivar client_id: Application (client) ID. :ivar object_id: Application object ID. :ivar service_principal_id: Enterprise application object ID. :ivar certificate: New credential (private key to be stored encrypted). :ivar permissions: Graph application permissions now granted. .. py:attribute:: purpose :type: s365b.db.models.AppPurpose .. py:attribute:: client_id :type: str .. py:attribute:: object_id :type: str .. py:attribute:: service_principal_id :type: str .. py:attribute:: certificate :type: s365b.setup.certs.AppCertificate .. py:attribute:: permissions :type: list[str] .. py:class:: ProvisionResult Everything the wizard needs to store. :ivar tenant_id: Directory ID. :ivar tenant_name: Organisation display name. :ivar default_domain: Default verified domain. :ivar admin_upn: The admin who signed in. :ivar apps: Provisioned apps by purpose. .. py:attribute:: tenant_id :type: str .. py:attribute:: tenant_name :type: str .. py:attribute:: default_domain :type: str .. py:attribute:: admin_upn :type: str .. py:attribute:: apps :type: dict[s365b.db.models.AppPurpose, AppResult] .. py:class:: Provisioner(graph: s365b.graph.client.GraphClient, report: Report, *, sleep: collections.abc.Callable[[float], collections.abc.Awaitable[None]] = asyncio.sleep) Creates and updates app registrations in one tenant. :param graph: Graph client authenticated with the admin's delegated token. :param report: Async callback ``(step, status, detail)`` for progress. :param sleep: Sleep function (replaced in tests). .. py:attribute:: graph .. py:attribute:: report .. py:attribute:: sleep .. py:method:: run(plans: collections.abc.Iterable[AppPlan]) -> ProvisionResult :async: Provision every planned app. :param plans: The apps to create or update. :returns: Tenant details and the provisioned apps. :raises ProvisionError: If a permission is unknown or the admin lacks rights. :raises s365b.graph.client.GraphError: For other Graph failures.