Skip to content

Commit

Permalink
[AppConfig] Add Snapshot samples (Azure#31039)
Browse files Browse the repository at this point in the history
  • Loading branch information
YalinLi0312 authored Jul 10, 2023
1 parent dacbe4b commit 48bce03
Show file tree
Hide file tree
Showing 20 changed files with 431 additions and 73 deletions.
4 changes: 1 addition & 3 deletions sdk/appconfiguration/azure-appconfiguration/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# Release History

## 1.4.1 (Unreleased)
## 1.5.0b1 (2023-07-11)

### Features Added
- Added support for `Snapshot` CRUD operations.

### Breaking Changes

### Bugs Fixed
- Fixed async `update_sync_token` to use async/await keywords

Expand Down
143 changes: 141 additions & 2 deletions sdk/appconfiguration/azure-appconfiguration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ client = AzureAppConfigurationClient(base_url="your_endpoint_url", credential=cr

A Configuration Setting is the fundamental resource within a Configuration Store. In its simplest form it is a key and a value. However, there are additional properties such as the modifiable content type and tags fields that allow the value to be interpreted or associated in different ways.

The Label property of a Configuration Setting provides a way to separate Configuration Settings into different dimensions. These dimensions are user defined and can take any form. Some common examples of dimensions to use for a label include regions, semantic versions, or environments. Many applications have a required set of configuration keys that have varying values as the application exists across different dimensions.
The [Label][label_concept] property of a Configuration Setting provides a way to separate Configuration Settings into different dimensions. These dimensions are user defined and can take any form. Some common examples of dimensions to use for a label include regions, semantic versions, or environments. Many applications have a required set of configuration keys that have varying values as the application exists across different dimensions.

For example, MaxRequests may be 100 in "NorthAmerica", and 200 in "WestEurope". By creating a Configuration Setting named MaxRequests with a label of "NorthAmerica" and another, only with a different value, in the "WestEurope" label, an application can seamlessly retrieve Configuration Settings as it runs in these two dimensions.

Properties of a Configuration Setting:
Expand All @@ -156,6 +157,10 @@ tags : dict
etag : str
```

### Snapshot

Azure App Configuration allows users to create a point-in-time snapshot of their configuration store, providing them with the ability to treat settings as one consistent version. This feature enables applications to hold a consistent view of configuration, ensuring that there are no version mismatches to individual settings due to reading as updates were made. Snapshots are immutable, ensuring that configuration can confidently be rolled back to a last-known-good configuration in the event of a problem.

## Examples

The following sections provide several code snippets covering some of the most common Configuration Service tasks, including:
Expand All @@ -164,6 +169,12 @@ The following sections provide several code snippets covering some of the most c
* [Get a Configuration Setting](#get-a-configuration-setting)
* [Delete a Configuration Setting](#delete-a-configuration-setting)
* [List Configuration Settings](#list-configuration-settings)
* [Create a Snapshot](#create-a-snapshot)
* [Get a Snapshot](#get-a-snapshot)
* [Archive a Snapshot](#archive-a-snapshot)
* [Recover a Snapshot](#recover-a-snapshot)
* [List Snapshots](#list-snapshots)
* [List Configuration Settings of a Snapshot](#list-configuration-settings-of-a-snapshot)
* [Async APIs](#async-apis)

### Create a Configuration Setting
Expand Down Expand Up @@ -237,6 +248,75 @@ for item in config_settings:

<!-- END SNIPPET -->

### Create a Snapshot

<!-- SNIPPET:snapshot_samples.create_snapshot -->

```python
from azure.appconfiguration import ConfigurationSettingFilter

filters = [ConfigurationSettingFilter(key="my_key1", label="my_label1")]
response = client.begin_create_snapshot(name="my_snapshot_name", filters=filters)
created_snapshot = response.result()
print_snapshot(created_snapshot)
```

<!-- END SNIPPET -->

### Get a Snapshot

<!-- SNIPPET:snapshot_samples.get_snapshot -->

```python
received_snapshot = client.get_snapshot(name="my_snapshot_name")
```

<!-- END SNIPPET -->

### Archive a Snapshot

<!-- SNIPPET:snapshot_samples.archive_snapshot -->

```python
archived_snapshot = client.archive_snapshot(name="my_snapshot_name")
print_snapshot(archived_snapshot)
```

<!-- END SNIPPET -->

### Recover a Snapshot

<!-- SNIPPET:snapshot_samples.recover_snapshot -->

```python
recovered_snapshot = client.recover_snapshot(name="my_snapshot_name")
print_snapshot(recovered_snapshot)
```

<!-- END SNIPPET -->

### List Snapshots

<!-- SNIPPET:snapshot_samples.list_snapshots -->

```python
for snapshot in client.list_snapshots():
print_snapshot(snapshot)
```

<!-- END SNIPPET -->

### List Configuration Settings of a Snapshot

<!-- SNIPPET:snapshot_samples.list_snapshot_configuration_settings -->

```python
for config_setting in client.list_snapshot_configuration_settings(name="my_snapshot_name"):
print_configuration_setting(config_setting)
```

<!-- END SNIPPET -->

### Async APIs

Async client is supported.
Expand Down Expand Up @@ -279,6 +359,63 @@ async for item in config_settings:

<!-- END SNIPPET -->

<!-- SNIPPET:snapshot_samples_async.create_snapshot -->

```python
from azure.appconfiguration import ConfigurationSettingFilter

filters = [ConfigurationSettingFilter(key="my_key1", label="my_label1")]
response = await client.begin_create_snapshot(name="my_snapshot_name", filters=filters)
created_snapshot = await response.result()
print_snapshot(created_snapshot)
```

<!-- END SNIPPET -->

<!-- SNIPPET:snapshot_samples_async.get_snapshot -->

```python
received_snapshot = await client.get_snapshot(name="my_snapshot_name")
```

<!-- END SNIPPET -->

<!-- SNIPPET:snapshot_samples_async.archive_snapshot -->

```python
archived_snapshot = await client.archive_snapshot(name="my_snapshot_name")
print_snapshot(archived_snapshot)
```

<!-- END SNIPPET -->

<!-- SNIPPET:snapshot_samples_async.recover_snapshot -->

```python
recovered_snapshot = await client.recover_snapshot(name="my_snapshot_name")
print_snapshot(recovered_snapshot)
```

<!-- END SNIPPET -->

<!-- SNIPPET:snapshot_samples_async.list_snapshots -->

```python
async for snapshot in client.list_snapshots():
print_snapshot(snapshot)
```

<!-- END SNIPPET -->

<!-- SNIPPET:snapshot_samples_async.list_snapshot_configuration_settings -->

```python
async for config_setting in client.list_snapshot_configuration_settings(name="my_snapshot_name"):
print_configuration_setting(config_setting)
```

<!-- END SNIPPET -->

## Troubleshooting

See the [troubleshooting guide][troubleshooting_guide] for details on how to diagnose various failure scenarios.
Expand All @@ -293,6 +430,7 @@ Several App Configuration client library samples are available to you in this Gi
- [Make a configuration setting readonly](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/appconfiguration/azure-appconfiguration/samples/read_only_sample.py) / [Async version](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/appconfiguration/azure-appconfiguration/samples/hello_world_sample_async.py)
- [Read revision history](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/appconfiguration/azure-appconfiguration/samples/list_revision_sample.py) / [Async version](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/appconfiguration/azure-appconfiguration/samples/list_revision_sample_async.py)
- [Get a setting if changed](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/appconfiguration/azure-appconfiguration/samples/conditional_operation_sample.py) / [Async version](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/appconfiguration/azure-appconfiguration/samples/conditional_operation_sample_async.py)
- [Create, retrieve and update status of a configuration settings snapshot](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/appconfiguration/azure-appconfiguration/samples/snapshot_samples.py) / [Async version](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/appconfiguration/azure-appconfiguration/samples/snapshot_samples_async.py)

For more details see the [samples README](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/appconfiguration/azure-appconfiguration/samples/README.md).

Expand All @@ -310,7 +448,7 @@ need to do this once across all repos using our CLA.

This project has adopted the
[Microsoft Open Source Code of Conduct][code_of_conduct]. For more information,
see the Code of Conduct FAQ or contact opencode@microsoft.com with any
see the [Code of Conduct FAQ][coc_faq] or contact [opencode@microsoft.com][coc_contact] with any
additional questions or comments.

<!-- LINKS -->
Expand All @@ -328,3 +466,4 @@ additional questions or comments.
[coc_faq]: https://opensource.microsoft.com/codeofconduct/faq/
[coc_contact]: mailto:opencode@microsoft.com
[troubleshooting_guide]: https://aka.ms/azsdk/python/appconfiguration/troubleshoot
[label_concept]: https://docs.microsoft.com/azure/azure-app-configuration/concept-key-value#label-keys
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
# Licensed under the MIT License.
# ------------------------------------

VERSION = "1.4.1"
VERSION = "1.5.0b1"
27 changes: 21 additions & 6 deletions sdk/appconfiguration/azure-appconfiguration/samples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,29 @@ pip install azure-appconfiguration

| File | Description |
|-------------|-------------|
| hello_world_sample.py / hello_world_sample_async.py | demos set/get/delete operations |
| hello_world_advanced_sample.py / hello_world_advanced_sample_async.py | demos add/set with label/list operations |
| conditional_operation_sample.py / conditional_operation_sample_async.py | demos conditional set/get/delete operations |
| read_only_sample.py / read_only_sample_async.py | demos set_read_only operations |
| list_revision_sample.py / list_revision_sample_async.py | demos list revision operations |
| sync_token_samples.py / sync_token_sample_asyncs.py | demos the `update_sync_token` method |
| [hello_world_sample.py][hello_world_sample] / [hello_world_sample_async.py][hello_world_sample_async] | demos set/get/delete operations |
| [hello_world_advanced_sample.py][hello_world_advanced_sample] / [hello_world_advanced_sample_async.py][hello_world_advanced_sample_async] | demos add/set with label/list operations |
| [conditional_operation_sample.py][conditional_operation_sample] / [conditional_operation_sample_async.py][conditional_operation_sample_async] | demos conditional set/get/delete operations |
| [read_only_sample.py][read_only_sample] / [read_only_sample_async.py][read_only_sample_async] | demos set_read_only operations |
| [list_revision_sample.py][list_revision_sample] / [list_revision_sample_async.py][list_revision_sample_async] | demos list revision operations |
| [sync_token_samples.py][sync_token_samples] / [sync_token_sample_async.py][sync_token_sample_async] | demos the `update_sync_token` method |
| [snapshot_samples.py][snapshot_samples] / [snapshot_samples_async.py][snapshot_samples_async] | demos create/get/archive/recover/list operations on configuration setting snapshot |

<!-- LINKS -->
[azure_sub]: https://azure.microsoft.com/free/
[azure_cli]: https://docs.microsoft.com/cli/azure
[configuration_store]: https://azure.microsoft.com/services/app-configuration/
[hello_world_sample]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/appconfiguration/azure-appconfiguration/samples/hello_world_sample.py
[hello_world_sample_async]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/appconfiguration/azure-appconfiguration/samples/hello_world_sample_async.py
[hello_world_advanced_sample]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/appconfiguration/azure-appconfiguration/samples/hello_world_advanced_sample.py
[hello_world_advanced_sample_async]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/appconfiguration/azure-appconfiguration/samples/hello_world_advanced_sample_async.py
[conditional_operation_sample]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/appconfiguration/azure-appconfiguration/samples/conditional_operation_sample.py
[conditional_operation_sample_async]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/appconfiguration/azure-appconfiguration/samples/conditional_operation_sample_async.py
[read_only_sample]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/appconfiguration/azure-appconfiguration/samples/read_only_sample.py
[read_only_sample_async]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/appconfiguration/azure-appconfiguration/samples/read_only_sample_async.py
[list_revision_sample]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/appconfiguration/azure-appconfiguration/samples/list_revision_sample.py
[list_revision_sample_async]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/appconfiguration/azure-appconfiguration/samples/list_revision_sample_async.py
[sync_token_samples]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/appconfiguration/azure-appconfiguration/samples/sync_token_samples.py
[sync_token_sample_async]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/appconfiguration/azure-appconfiguration/samples/sync_token_samples_async.py
[snapshot_samples]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/appconfiguration/azure-appconfiguration/samples/snapshot_samples.py
[snapshot_samples_async]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/appconfiguration/azure-appconfiguration/samples/snapshot_samples_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,24 @@

"""
FILE: conditional_operation_sample.py
DESCRIPTION:
This sample demos conditional set/get/delete operations for app configuration
USAGE: python conditional_operation_sample.py
"""
Set the environment variables with your own values before running the sample:
1) APPCONFIGURATION_CONNECTION_STRING: Connection String used to access the Azure App Configuration.
"""
import os
from azure.core import MatchConditions
from azure.core.exceptions import ResourceModifiedError
from azure.appconfiguration import AzureAppConfigurationClient, ConfigurationSetting
from util import print_configuration_setting, get_connection_string
from util import print_configuration_setting


def main():
CONNECTION_STRING = get_connection_string()
CONNECTION_STRING = os.environ["APPCONFIGURATION_CONNECTION_STRING"]

# Create app config client
client = AzureAppConfigurationClient.from_connection_string(CONNECTION_STRING)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,26 @@

"""
FILE: conditional_operation_async_sample.py
DESCRIPTION:
This sample demos conditional set/get/delete operations for app configuration
USAGE: python conditional_operation_async_sample.py
"""
Set the environment variables with your own values before running the sample:
1) APPCONFIGURATION_CONNECTION_STRING: Connection String used to access the Azure App Configuration.
"""
import asyncio
import os
from azure.core import MatchConditions
from azure.core.exceptions import ResourceModifiedError
import asyncio
from azure.appconfiguration import ConfigurationSetting
from azure.appconfiguration.aio import AzureAppConfigurationClient
from util import print_configuration_setting, get_connection_string
from util import print_configuration_setting


async def main():
CONNECTION_STRING = get_connection_string()
CONNECTION_STRING = os.environ["APPCONFIGURATION_CONNECTION_STRING"]

# Create app config client
client = AzureAppConfigurationClient.from_connection_string(CONNECTION_STRING)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,22 @@

"""
FILE: hello_world_advanced_sample.py
DESCRIPTION:
This sample demos more advanced scenarios including add/set with label/list operations for app configuration
USAGE: python hello_world_advanced_sample.py
"""
Set the environment variables with your own values before running the sample:
1) APPCONFIGURATION_CONNECTION_STRING: Connection String used to access the Azure App Configuration.
"""
import os
from azure.appconfiguration import AzureAppConfigurationClient, ConfigurationSetting
from util import print_configuration_setting, get_connection_string
from util import print_configuration_setting


def main():
CONNECTION_STRING = get_connection_string()
CONNECTION_STRING = os.environ["APPCONFIGURATION_CONNECTION_STRING"]

# Create app config client
client = AzureAppConfigurationClient.from_connection_string(CONNECTION_STRING)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,24 @@

"""
FILE: hello_world_advanced_async_sample.py
DESCRIPTION:
This sample demos more advanced scenarios including add/set with label/list operations for app configuration
USAGE: python hello_world_advanced_async_sample.py
"""
Set the environment variables with your own values before running the sample:
1) APPCONFIGURATION_CONNECTION_STRING: Connection String used to access the Azure App Configuration.
"""
import asyncio
import os
from azure.appconfiguration import ConfigurationSetting
from azure.appconfiguration.aio import AzureAppConfigurationClient
from util import print_configuration_setting, get_connection_string
from util import print_configuration_setting


async def main():
CONNECTION_STRING = get_connection_string()
CONNECTION_STRING = os.environ["APPCONFIGURATION_CONNECTION_STRING"]

# Create app config client
client = AzureAppConfigurationClient.from_connection_string(CONNECTION_STRING)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@

"""
FILE: hello_world_sample.py
DESCRIPTION:
This sample demos set/get/delete operations for app configuration
USAGE: python hello_world_sample.py
"""
Set the environment variables with your own values before running the sample:
1) APPCONFIGURATION_CONNECTION_STRING: Connection String used to access the Azure App Configuration.
"""
from azure.appconfiguration import ConfigurationSetting
from util import print_configuration_setting

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@

"""
FILE: hello_world_async_sample.py
DESCRIPTION:
This sample demos set/get/delete operations for app configuration
USAGE: python hello_world_async_sample.py
"""
Set the environment variables with your own values before running the sample:
1) APPCONFIGURATION_CONNECTION_STRING: Connection String used to access the Azure App Configuration.
"""
import asyncio
from azure.appconfiguration import ConfigurationSetting
from util import print_configuration_setting
Expand Down
Loading

0 comments on commit 48bce03

Please sign in to comment.