Repository navigation
feat: add top connector SDK binding types #192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hallvictoria
wants to merge
8
commits into
dev
Choose a base branch
from
hallvictoria/connector-sdk-type-bindings
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4f456cb
feat: improve Connector SDK bindings support (#184)
hallvictoria 2e57d38
feat: Add Sharepoint, OneDrive, Teams, CDS, Planner, and Salesforce c…
hallvictoria ea695a3
Add Azure DevOps, Dataflows
hallvictoria 330fcc6
Merge branch 'dev' of https://github.com/Azure/azure-functions-python…
hallvictoria 7cc87b4
Reject malformed calendar batches and refresh connector samples
hallvictoria c6618a9
Reject malformed calendar collection envelopes
hallvictoria b821d48
Merge branch 'dev' of https://github.com/Azure/azure-functions-python…
hallvictoria 0e12d57
update dependencies, host.json
hallvictoria File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
...-extensions-connectors/azurefunctions/extensions/connectors/commondataservice/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. | ||
|
|
||
| """SDK payload bindings for the Dataverse commondataservice connector.""" | ||
|
|
||
| from ..connectorConverter import ConnectorConverter | ||
| from .actionEventNotification import ActionEventNotification | ||
| from .item import Item | ||
| from .rowChangeNotification import RowChangeNotification | ||
|
|
||
| __all__ = [ | ||
| "ActionEventNotification", "ConnectorConverter", "Item", "RowChangeNotification", | ||
| ] |
82 changes: 82 additions & 0 deletions
82
...ons-connectors/azurefunctions/extensions/connectors/commondataservice/_deserialization.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. | ||
|
|
||
| """Preserve dynamic Dataverse records without treating schema metadata as data.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import json | ||
| from typing import Any | ||
|
|
||
| from azure.connectors.commondataservice import Item, ObjectEntity | ||
| from azurefunctions.extensions.base import Datum | ||
|
|
||
|
|
||
| def _parse_payload(data: Datum, *, unwrap_value: bool) -> list[dict[str, Any]]: | ||
| """Extract polling batches, but keep webhook value fields as record data.""" | ||
| if data.type in ("collection_string", "collection_bytes"): | ||
| return [ | ||
| item | ||
| for event in data.python_value | ||
| for item in _parse_payload( | ||
| Datum(value=event, type="json"), unwrap_value=unwrap_value, | ||
| ) | ||
| ] | ||
|
|
||
| payload: Any = data.value | ||
| if isinstance(payload, (str, bytes, bytearray)): | ||
| try: | ||
| payload = json.loads(payload) | ||
| except (json.JSONDecodeError, UnicodeDecodeError) as error: | ||
| raise ValueError(f"Invalid JSON payload: {error}.") from error | ||
|
|
||
| if isinstance(payload, dict) and set(payload) == {"body"}: | ||
| payload = payload["body"] | ||
| if payload is None: | ||
| return [] | ||
|
|
||
| if isinstance(payload, dict): | ||
| if unwrap_value and "value" in payload and all( | ||
| name == "value" or name.startswith(("@odata.", "odata.")) | ||
| for name in payload | ||
| ): | ||
| payload = payload["value"] | ||
| if payload is None: | ||
| return [] | ||
| if not isinstance(payload, list): | ||
| raise ValueError("CDS polling batch value must contain a JSON array.") | ||
| else: | ||
| payload = [payload] | ||
|
|
||
| if not isinstance(payload, list): | ||
| raise ValueError("CDS payload must contain a JSON object or array.") | ||
| if any(not isinstance(item, dict) for item in payload): | ||
| raise ValueError("Each CDS payload item must contain a JSON object.") | ||
|
|
||
| return payload | ||
|
|
||
|
|
||
| def deserialize_items(data: Datum) -> list[Item]: | ||
| """Store legacy polling columns in the generated SDK dynamic property bag.""" | ||
| result = [] | ||
| for record in _parse_payload(data, unwrap_value=True): | ||
| if set(record) in ({"dynamicProperties"}, {"dynamic_properties"}): | ||
| properties = next(iter(record.values())) | ||
| if properties is not None and not isinstance(properties, dict): | ||
| raise ValueError("CDS dynamicProperties must be an object or null.") | ||
| else: | ||
| properties = record | ||
|
|
||
| result.append(Item( | ||
| dynamic_properties=dict(properties) if properties is not None else None, | ||
| )) | ||
|
|
||
| return result | ||
|
|
||
|
|
||
| def deserialize_notifications(data: Datum) -> list[ObjectEntity]: | ||
| """Keep complete webhook records in SDK ObjectEntity additional_properties.""" | ||
| return [ | ||
| ObjectEntity(additional_properties=dict(record)) | ||
| for record in _parse_payload(data, unwrap_value=False) | ||
| ] |
15 changes: 15 additions & 0 deletions
15
...nectors/azurefunctions/extensions/connectors/commondataservice/actionEventNotification.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. | ||
|
|
||
| """Bind dynamic BusinessEventsTrigger action-event notifications.""" | ||
|
|
||
| from azure.connectors.commondataservice import ObjectEntity | ||
|
|
||
| from .._sdk_type import ConnectorSdkType | ||
| from ._deserialization import deserialize_notifications | ||
|
|
||
|
|
||
| class ActionEventNotification(ConnectorSdkType[list[ObjectEntity]], ObjectEntity): | ||
| """Return SDK ObjectEntity records with action fields in additional_properties.""" | ||
|
|
||
| _deserialize = staticmethod(deserialize_notifications) |
15 changes: 15 additions & 0 deletions
15
...ions-extensions-connectors/azurefunctions/extensions/connectors/commondataservice/item.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. | ||
|
|
||
| """Bind legacy CDS polling records using the generated SDK item model.""" | ||
|
|
||
| from azure.connectors.commondataservice import Item as AzureItem | ||
|
|
||
| from .._sdk_type import ConnectorSdkType | ||
| from ._deserialization import deserialize_items | ||
|
|
||
|
|
||
| class Item(ConnectorSdkType[list[AzureItem]], AzureItem): | ||
| """Return legacy polling items with raw JSON in dynamic_properties.""" | ||
|
|
||
| _deserialize = staticmethod(deserialize_items) |
15 changes: 15 additions & 0 deletions
15
...onnectors/azurefunctions/extensions/connectors/commondataservice/rowChangeNotification.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. | ||
|
|
||
| """Bind dynamic SubscribeWebhookTrigger row-change notifications.""" | ||
|
|
||
| from azure.connectors.commondataservice import ObjectEntity | ||
|
|
||
| from .._sdk_type import ConnectorSdkType | ||
| from ._deserialization import deserialize_notifications | ||
|
|
||
|
|
||
| class RowChangeNotification(ConnectorSdkType[list[ObjectEntity]], ObjectEntity): | ||
| """Return SDK ObjectEntity records with row fields in additional_properties.""" | ||
|
|
||
| _deserialize = staticmethod(deserialize_notifications) |
9 changes: 9 additions & 0 deletions
9
...unctions-extensions-connectors/azurefunctions/extensions/connectors/dataflows/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. | ||
|
|
||
| """SDK refresh bindings for Power Query Dataflows connector triggers.""" | ||
|
|
||
| from ..connectorConverter import ConnectorConverter | ||
| from .refreshModel import RefreshModel | ||
|
|
||
| __all__ = ["ConnectorConverter", "RefreshModel"] |
57 changes: 57 additions & 0 deletions
57
...-extensions-connectors/azurefunctions/extensions/connectors/dataflows/_deserialization.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. | ||
|
|
||
| """Normalize Dataflows refresh records without inventing a source collection.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import json | ||
| from typing import Any | ||
|
|
||
| from azure.connectors.dataflows import RefreshModel | ||
| from azurefunctions.extensions.base import Datum | ||
|
|
||
| from .._deserialization import deserialize_model | ||
|
|
||
|
|
||
| def _parse_payload(data: Datum) -> list[dict[str, Any]]: | ||
| """Read single refresh callbacks and optional transport-level aggregates.""" | ||
| if data.type in ("collection_string", "collection_bytes"): | ||
| return [ | ||
| item | ||
| for event in data.python_value | ||
| for item in _parse_payload(Datum(value=event, type="json")) | ||
| ] | ||
|
|
||
| payload: Any = data.value | ||
| if isinstance(payload, (str, bytes, bytearray)): | ||
| try: | ||
| payload = json.loads(payload) | ||
| except (json.JSONDecodeError, UnicodeDecodeError) as error: | ||
| raise ValueError(f"Invalid JSON payload: {error}.") from error | ||
|
|
||
| if isinstance(payload, dict) and set(payload) == {"body"}: | ||
| payload = payload["body"] | ||
| if payload is None: | ||
| return [] | ||
|
|
||
| if isinstance(payload, dict): | ||
| payload = [payload] | ||
| if not isinstance(payload, list): | ||
| raise ValueError("Dataflows payload must contain a JSON object or array.") | ||
| if any(not isinstance(item, dict) for item in payload): | ||
| raise ValueError("Each Dataflows transport item must contain a JSON object.") | ||
| if any("value" in item and all( | ||
| name == "value" or name.startswith(("@odata.", "odata.")) for name in item | ||
| ) for item in payload): | ||
| raise ValueError( | ||
| "Dataflows OnRefreshComplete returns a refresh record, " | ||
| "not a value collection." | ||
| ) | ||
|
|
||
| return payload | ||
|
|
||
|
|
||
| def deserialize_refreshes(data: Datum) -> list[RefreshModel]: | ||
| """Map the six nullable SDK string fields without changing their values.""" | ||
| return [deserialize_model(RefreshModel, item) for item in _parse_payload(data)] |
15 changes: 15 additions & 0 deletions
15
...ions-extensions-connectors/azurefunctions/extensions/connectors/dataflows/refreshModel.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. | ||
|
|
||
| """Bind Dataflows refresh callbacks using the generated SDK refresh model.""" | ||
|
|
||
| from azure.connectors.dataflows import RefreshModel as AzureRefreshModel | ||
|
|
||
| from .._sdk_type import ConnectorSdkType | ||
| from ._deserialization import deserialize_refreshes | ||
|
|
||
|
|
||
| class RefreshModel(ConnectorSdkType[list[AzureRefreshModel]], AzureRefreshModel): | ||
| """Return SDK refresh items for OnRefreshComplete polling callbacks.""" | ||
|
|
||
| _deserialize = staticmethod(deserialize_refreshes) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.