s365b.modules.entra.module

The Entra ID backup module.

Attributes

Classes

EntraModule

Backs up Entra ID (Azure AD) directory objects and policies.

Functions

normalise(item) → bytes

Serialise an object so unchanged objects produce identical bytes.

unavailable(exc) → bool

Whether an error means "this tenant does not have the feature".

display_name(item, role_names) → str

Choose a readable name for an item.

Module Contents

s365b.modules.entra.module.READ_PERMISSIONS[source]
s365b.modules.entra.module.CHANGE_EVENTS: dict[str, str][source]
s365b.modules.entra.module.normalise(item: s365b.modules.entra.sources.Item) → bytes[source]

Serialise an object so unchanged objects produce identical bytes.

Drops OData annotations other than @odata.type (they carry request context, not data), sorts keys, and sorts lists (see _canonical()).

Parameters:

item – A Graph object.

Returns:

UTF-8 JSON.

s365b.modules.entra.module.unavailable(exc: s365b.graph.client.GraphError) → bool[source]

Whether an error means “this tenant does not have the feature”.

Conditional Access and PIM need Entra ID P1/P2; tenants without them get an error, which is not a backup failure.

Parameters:

exc – The Graph error.

Returns:

True for licence / feature-not-available errors.

s365b.modules.entra.module.display_name(item: s365b.modules.entra.sources.Item, role_names: dict[str, str]) → str[source]

Choose a readable name for an item.

Parameters:
  • item – A Graph object.

  • role_names – Role definition names by ID (for role assignments).

Returns:

A name for the browse view.

class s365b.modules.entra.module.EntraModule[source]

Bases: s365b.modules.sdk.BackupModule

Backs up Entra ID (Azure AD) directory objects and policies.

id: ClassVar[str] = 'entra'[source]
display_name: ClassVar[str] = 'Entra ID'[source]
description: ClassVar[str] = 'Users, groups, apps, roles, Conditional Access and tenant policies.'[source]
version: ClassVar[str] = '0.2.0'[source]
config_model: ClassVar[type[pydantic.BaseModel]][source]
object_noun: ClassVar[tuple[str, str]] = ('category', 'categories')[source]
required_permissions(config: pydantic.BaseModel, *, restore: bool) → set[str][source]

Return the Graph application permissions needed.

Parameters:
  • config – Module settings (none).

  • restore – Restore is not implemented yet, so it needs nothing.

Returns:

Read permissions for backup; nothing for restore.

event_types() → list[s365b.modules.sdk.EventType][source]

Alerts for security-relevant directory changes.

Returns:

The event types.

change_event(item_type: str, change: str, version: s365b.modules.sdk.ItemVersion) → str | None[source]

Map a change to an alert (see CHANGE_EVENTS).

Parameters:
  • item_type – The item’s type.

  • change – new, changed or deleted.

  • version – The new version.

Returns:

The event ID, or None for changes that do not alert.

item_types() → list[s365b.modules.sdk.ItemTypeInfo][source]

Describe the item types.

Returns:

One entry per Graph object type.

async discover(ctx: s365b.modules.sdk.ModuleContext) → collections.abc.AsyncIterator[s365b.modules.sdk.ProtectedObject][source]

Yield one protected object per category.

Parameters:

ctx – Module context.

Yields:

The categories.

state_for_new_repository(state: s365b.modules.sdk.SyncState) → s365b.modules.sdk.SyncState[source]

Keep the state: every run reads everything, and it finds deletions.

Parameters:

state – The state saved by the backup into the other repository.

Returns:

The same state.

async backup(ctx: s365b.modules.sdk.ModuleContext, obj: s365b.modules.sdk.ProtectedObject, state: s365b.modules.sdk.SyncState) → collections.abc.AsyncIterator[s365b.modules.sdk.ItemVersion | s365b.modules.sdk.Checkpoint][source]

Snapshot one category.

Every object is yielded each run (the catalog keeps only changed ones); objects seen last time but not now are yielded as deleted. A checkpoint follows each source.

Parameters:
  • ctx – Module context.

  • obj – The category.

  • state – {"seen": {source key: [item keys]}} from the last run.

Yields:

Item versions and checkpoints.

Raises:

ModuleError – For an unknown category or missing permissions.