s365b.core.services =================== .. py:module:: s365b.core.services .. autoapi-nested-parse:: Process-wide services, built once at startup. The API and the worker both create a :class:`Services` object and pass it where needed, instead of using module-level globals. Tests build one with fakes. Attributes ---------- .. autoapisummary:: s365b.core.services.GraphFactory Classes ------- .. autoapisummary:: s365b.core.services.AppPurpose s365b.core.services.Services Functions --------- .. autoapisummary:: s365b.core.services.app_key_context s365b.core.services.repo_passphrase_context Module Contents --------------- .. py:class:: AppPurpose Bases: :py:obj:`enum.StrEnum` What an app registration is used for. .. py:attribute:: BACKUP :value: 'backup' .. py:attribute:: RESTORE :value: 'restore' .. py:attribute:: NOTIFICATIONS :value: 'notifications' .. py:attribute:: SIGNIN :value: 'signin' .. py:function:: app_key_context(app: s365b.db.models.AppRegistration) -> str Associated-data string for an app registration's encrypted private key. :param app: The app registration row. :returns: Context string passed to :class:`SecretBox`. .. py:function:: repo_passphrase_context(repo: s365b.db.models.RepositoryConfig) -> str Associated-data string for a repository's encrypted passphrase. :param repo: The repository row. :returns: Context string passed to :class:`SecretBox`. .. py:data:: GraphFactory .. py:class:: Services Shared services for one process. :ivar settings: Process settings. :ivar db: Database access. :ivar registry: Allowed modules. :ivar secrets: Encrypts/decrypts secrets stored in the database. :ivar graph_factory: Builds a Graph client for an app registration; replaced in tests. :ivar msal_app_factory: MSAL app class for Entra sign-in; replaced in tests. :ivar device_code_factory: Builds the setup wizard's device code client from a public client ID; replaced in tests. :ivar credential_factory: Builds the app-only token provider for an app registration; replaced in tests. .. py:attribute:: settings :type: s365b.core.config.Settings .. py:attribute:: db :type: s365b.db.session.Database .. py:attribute:: registry :type: s365b.modules.registry.ModuleRegistry .. py:attribute:: secrets :type: s365b.core.secrets.SecretBox .. py:attribute:: graph_factory :type: GraphFactory | None :value: None .. py:attribute:: msal_app_factory :type: Any :value: None .. py:attribute:: device_code_factory :type: collections.abc.Callable[[str], Any] | None :value: None .. py:attribute:: credential_factory :type: collections.abc.Callable[[s365b.db.models.Tenant, s365b.db.models.AppRegistration], s365b.graph.auth.TokenProvider] | None :value: None .. py:attribute:: enqueue_factory :type: collections.abc.Callable[[int, str], collections.abc.Awaitable[None]] | None :value: None .. py:attribute:: retention_factory :type: collections.abc.Callable[[int, str], collections.abc.Awaitable[None]] | None :value: None .. py:attribute:: restore_factory :type: collections.abc.Callable[[int], collections.abc.Awaitable[None]] | None :value: None .. py:attribute:: notifier_factory :type: collections.abc.Callable[[str], Any] | None :value: None .. py:method:: from_settings(settings: s365b.core.config.Settings) -> Services :classmethod: Build the real services from settings. :param settings: Process settings. :returns: The services. .. py:method:: graph_for(tenant: s365b.db.models.Tenant, app: s365b.db.models.AppRegistration) -> s365b.graph.client.GraphClient Return a Graph client authenticated as an app registration. :param tenant: The tenant. :param app: The Backup, Restore or Notifications app. :returns: A new Graph client; close it with ``aclose()``. .. py:method:: enqueue_backup(job_id: int, requested_by: str) -> None :async: Queue a backup job for the worker. Uses the same queueing lock as the scheduler, so a job that is already waiting is not queued twice. :param job_id: Backup job ID. :param requested_by: Username shown on the run. :raises procrastinate.exceptions.AlreadyEnqueued: If the job is already waiting to run. .. py:method:: enqueue_retention(repository_id: int, requested_by: str) -> None :async: Queue a retention run for a repository. :param repository_id: Repository row ID. :param requested_by: Username shown on the run. :raises procrastinate.exceptions.AlreadyEnqueued: If one is already waiting. .. py:method:: enqueue_restore(run_id: int) -> None :async: Hand a queued restore run to a worker. :param run_id: The job run, already recorded as queued. .. py:method:: aclose() -> None :async: Close the job queue connection and the database pool. .. py:method:: credential_for(tenant: s365b.db.models.Tenant, app: s365b.db.models.AppRegistration) -> s365b.graph.auth.TokenProvider Return the app-only token provider (certificate credential) for an app. :param tenant: The tenant. :param app: The app registration. :returns: A token provider. .. py:method:: backend_for(repo: s365b.db.models.RepositoryConfig) -> s365b.storage.backends.StorageBackend Return the storage backend of a repository. :param repo: The repository row. :returns: The backend. :raises ValueError: For backends not implemented yet. .. py:method:: open_repository(repo: s365b.db.models.RepositoryConfig) -> s365b.storage.repository.Repository :async: Open (or reuse) a repository, refreshing its index. :param repo: The repository row. :returns: The open repository.