diff --git a/sdk/appconfiguration/azure-appconfiguration/samples/README.md b/sdk/appconfiguration/azure-appconfiguration/samples/README.md index f9bac00f7c60..e4c303db0648 100644 --- a/sdk/appconfiguration/azure-appconfiguration/samples/README.md +++ b/sdk/appconfiguration/azure-appconfiguration/samples/README.md @@ -36,6 +36,7 @@ pip install azure-appconfiguration | conditional_operation_sample.py / conditional_operation_async_sample.py | demos conditional set/get/delete operations | | read_only_sample.py / read_only_async_sample.py | demos set_read_only operations | | list_revision_sample.py / list_revision_async_sample.py | demos list revision operations | +| sync_token_samples.py / sync_token_async_samples.py | demos the `update_sync_token` method | [azure_sub]: https://azure.microsoft.com/free/ diff --git a/sdk/appconfiguration/azure-appconfiguration/samples/sync_token_async_samples.py b/sdk/appconfiguration/azure-appconfiguration/samples/sync_token_async_samples.py new file mode 100644 index 000000000000..61993a05469a --- /dev/null +++ b/sdk/appconfiguration/azure-appconfiguration/samples/sync_token_async_samples.py @@ -0,0 +1,41 @@ +# coding: utf-8 + +# ------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- + +""" +FILE: sync_token_async_samples.py +DESCRIPTION: + This sample demos update_sync_token for the AzureAppConfigurationClient +USAGE: python sync_token_async_samples.py +""" + +import asyncio +from azure.appconfiguration.aio import AzureAppConfigurationClient +from util import print_configuration_setting, get_connection_string + + +async def handle_event_grid_notifications(event_grid_events): + # type: (List[dict[str, Any]]) -> None + CONNECTION_STRING = get_connection_string() + + all_keys = [] + + async with AzureAppConfigurationClient.from_connection_string(CONNECTION_STRING) as client: + + for event_grid_event in event_grid_events: + if event_grid_event["eventType"] == 'Microsoft.KeyValueModified': + sync_token = event['data']['syncToken'] + client.update_sync_token(sync_token) + + new_key = await client.get_configuration_setting(key=event['data']['key'], label=event['data']['label']) + + all_keys.append(new_key) + + +if __name__ == "__main__": + loop = asyncio.get_event_loop() + loop.run_until_complete(handle_event_grid_notifications([])) diff --git a/sdk/appconfiguration/azure-appconfiguration/samples/sync_token_samples.py b/sdk/appconfiguration/azure-appconfiguration/samples/sync_token_samples.py new file mode 100644 index 000000000000..6ef3d65c302f --- /dev/null +++ b/sdk/appconfiguration/azure-appconfiguration/samples/sync_token_samples.py @@ -0,0 +1,39 @@ +# coding: utf-8 + +# ------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- + +""" +FILE: sync_token_samples.py +DESCRIPTION: + This sample demos update_sync_token for the AzureAppConfigurationClient +USAGE: python sync_token_samples.py +""" + +from azure.appconfiguration import AzureAppConfigurationClient +from util import print_configuration_setting, get_connection_string + + +def handle_event_grid_notifications(event_grid_events): + # type: (List[dict[str, Any]]) -> None + CONNECTION_STRING = get_connection_string() + + all_keys = [] + + with AzureAppConfigurationClient.from_connection_string(CONNECTION_STRING) as client: + + for event_grid_event in event_grid_events: + if event_grid_event["eventType"] == 'Microsoft.KeyValueModified': + sync_token = event['data']['syncToken'] + client.update_sync_token(sync_token) + + new_key = client.get_configuration_setting(key=event['data']['key'], label=event['data']['label']) + + all_keys.append(new_key) + + +if __name__ == "__main__": + handle_event_grid_notifications([])