MicrosoftGraphConnector¶
Generic Microsoft Graph source connector.
- class scamander.sources.microsoft_graph_connector.MicrosoftGraphConnector(config: Config, *args, **kwargs)¶
Basisklassen:
SourceSource connector that reads any Microsoft Graph v1.0 resource into a Spark DataFrame.
A single reusable connector for Microsoft Graph, driven entirely by
MicrosoftGraphSourceOptions— Users, Groups, Enterprise Applications (service principals), directory role assignments, or any other Graph endpoint are all just differentoptions.endpointvalues, rather than one connector class per resource type.Authenticates via the AAD v2.0 client-credentials (app-only) flow and paginates with
fetch_all_odata_pages(), which follows@odata.nextLinkand surfaces a final@odata.deltaLinkfor delta-capable endpoints.Expects the
Configobject to carry aMicrosoftGraphSourceOptionsinstance underconfig.source.options.- Parameters:
config (Config) – Validated configuration object containing Microsoft Graph connection details under
config.source.options.spark (SparkSession) – An active Spark session used to build the result DataFrame.
- Veroorzaakt:
ValueError – If
config.source.optionsis not aMicrosoftGraphSourceOptionsinstance.
Example:
from scamander.sources.microsoft_graph_connector import MicrosoftGraphConnector from scamander.models.source_config.microsoft_graph import MicrosoftGraphSourceOptions from scamander.models.source_config.source import SourceConfig from scamander.models.config import Config config = Config( source=SourceConfig( type="microsoft_graph", options=MicrosoftGraphSourceOptions( tenant_id=tenant_id, client_id=client_id, client_secret=client_secret, endpoint="/users/delta", select=["id", "displayName", "userPrincipalName", "accountEnabled"], ), ), ) connector = MicrosoftGraphConnector(config, spark) df = connector.connect() new_delta_link = connector.delta_link # persist for the next incremental run
- connect() DataFrame¶
Fetches every page of the configured Graph resource and returns a Spark DataFrame.
When
options.delta_linkis set, the first request is issued directly against it (ignoringendpoint/select/filter/expand), resuming an incremental sync. Otherwise a fresh request is built fromoptions.endpointand its query parameters. After a successful fetch,self.delta_linkholds the new@odata.deltaLinkfor the caller to persist (Nonewhen the endpoint isn’t delta-capable). Records marked@removedby a delta query are kept and flagged via an addedis_deletedcolumn rather than being dropped, so removed-principal history is retained for governance/audit purposes.- Returns:
- A Spark DataFrame containing every record returned by the
configured Graph resource. When the resource returns no records, an empty, zero-column DataFrame is returned rather than raising (Spark cannot infer a schema from an empty list of dicts).
- Return type:
DataFrame