Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions sdk/appconfiguration/azure-appconfiguration/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## 1.2.0b2 (2021-05-11)

### Features
- Adds context manager functionality to the sync and async `AzureAppConfigurationClient`s.

### Fixes
- Fixes a deserialization bug for `FeatureFlagConfigurationSetting` and `SecretReferenceConfigurationSetting`.

Expand Down
20 changes: 10 additions & 10 deletions sdk/appconfiguration/azure-appconfiguration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ az appconfig create --name <config-store-name> --resource-group <resource-group-

### Authenticate the client

In order to interact with the App Configuration service, you'll need to create an instance of the
[AzureAppConfigurationClient][configuration_client_class] class. To make this possible,
In order to interact with the App Configuration service, you'll need to create an instance of the
[AzureAppConfigurationClient][configuration_client_class] class. To make this possible,
you can either use the connection string of the Configuration Store or use an AAD token.

#### Use connection string
Expand Down Expand Up @@ -217,7 +217,7 @@ for item in filtered_listed:

### Async APIs

Async client is supported for python 3.5+.
Async client is supported for python 3.5+.
To use the async client library, import the AzureAppConfigurationClient from package azure.appconfiguration.aio instead of azure.appconfiguration

```python
Expand All @@ -236,7 +236,7 @@ fetched_config_setting = await async_client.get_configuration_setting(
)
```

To use list_configuration_settings, call it synchronously and iterate over the returned async iterator asynchronously
To use list_configuration_settings, call it synchronously and iterate over the returned async iterator asynchronously

```python

Expand Down Expand Up @@ -267,12 +267,12 @@ Http request and response details are printed to stdout with this logging config

### More sample code

Several App Configuration client library samples are available to you in this GitHub repository. These include:
- [Hello world](https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/appconfiguration/azure-appconfiguration/samples/hello_world_sample.py) / [Async version](https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/appconfiguration/azure-appconfiguration/samples/hello_world_async_sample.py)
- [Hello world with labels](https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/appconfiguration/azure-appconfiguration/samples/hello_world_advanced_sample.py) / [Async version](https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/appconfiguration/azure-appconfiguration/samples/hello_world_advanced_async_sample.py)
- [Make a configuration setting readonly](https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/appconfiguration/azure-appconfiguration/samples/read_only_sample.py) / [Async version](https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/appconfiguration/azure-appconfiguration/samples/hello_world_async_sample.py)
- [Read revision history](https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/appconfiguration/azure-appconfiguration/samples/list_revision_sample.py) / [Async version](https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/appconfiguration/azure-appconfiguration/samples/list_revision_async_sample.py)
- [Get a setting if changed](https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/appconfiguration/azure-appconfiguration/samples/conditional_operation_sample.py) / [Async version](https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/appconfiguration/azure-appconfiguration/samples/conditional_operation_async_sample.py)
Several App Configuration client library samples are available to you in this GitHub repository. These include:
- [Hello world](https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/appconfiguration/azure-appconfiguration/samples/hello_world_sample.py) / [Async version](https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/appconfiguration/azure-appconfiguration/samples/hello_world_sample_async.py)
- [Hello world with labels](https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/appconfiguration/azure-appconfiguration/samples/hello_world_advanced_sample.py) / [Async version](https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/appconfiguration/azure-appconfiguration/samples/hello_world_advanced_sample_async.py)
- [Make a configuration setting readonly](https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/appconfiguration/azure-appconfiguration/samples/read_only_sample.py) / [Async version](https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/appconfiguration/azure-appconfiguration/samples/hello_world_sample_async.py)
- [Read revision history](https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/appconfiguration/azure-appconfiguration/samples/list_revision_sample.py) / [Async version](https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/appconfiguration/azure-appconfiguration/samples/list_revision_sample_async.py)
- [Get a setting if changed](https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/appconfiguration/azure-appconfiguration/samples/conditional_operation_sample.py) / [Async version](https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/appconfiguration/azure-appconfiguration/samples/conditional_operation_sample_async.py)

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# license information.
# -------------------------------------------------------------------------
import binascii
from typing import Dict, Optional, Any
from typing import Optional, Any
from requests.structures import CaseInsensitiveDict
from azure.core import MatchConditions
from azure.core.pipeline import Pipeline
Expand Down Expand Up @@ -600,3 +600,10 @@ def close(self):

"""Close all connections made by the client"""
self._impl._client.close()

def __enter__(self):
self._impl.__enter__()
return self

def __exit__(self, *args):
self._impl.__exit__(*args)
Original file line number Diff line number Diff line change
Expand Up @@ -616,3 +616,10 @@ async def close(self) -> None:

"""Close all connections made by the client"""
await self._impl._client.close()

async def __aenter__(self):
await self._impl.__aenter__()
return self

async def __aexit__(self, *args):
await self._impl.__aexit__(*args)
12 changes: 6 additions & 6 deletions sdk/appconfiguration/azure-appconfiguration/samples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ pip install azure-appconfiguration

| File | Description |
|-------------|-------------|
| hello_world_sample.py / hello_world_async_sample.py | demos set/get/delete operations |
| hello_world_advanced_sample.py / hello_world_advanced_async_sample.py | demos add/set with label/list operations |
| 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 |
| 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 |

<!-- LINKS -->
[azure_sub]: https://azure.microsoft.com/free/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ def handle_event_grid_notifications(event_grid_events):
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']
sync_token = event_grid_event['data']['syncToken']
client.update_sync_token(sync_token)

new_key = client.get_configuration_setting(key=event['data']['key'], label=event['data']['label'])
new_key = client.get_configuration_setting(
key=event_grid_event['data']['key'], label=event_grid_event['data']['label']
)

all_keys.append(new_key)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@ async def handle_event_grid_notifications(event_grid_events):
all_keys = []

async with AzureAppConfigurationClient.from_connection_string(CONNECTION_STRING) as client:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will cause connection unclose.

We recommend users to use context manager to close client.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no __enter__ (or __aenter__ in async) on the clients. Adding this now.


for event_grid_event in event_grid_events:
if event_grid_event["eventType"] == 'Microsoft.KeyValueModified':
sync_token = event['data']['syncToken']
sync_token = event_grid_event['data']['syncToken']
client.update_sync_token(sync_token)

new_key = await client.get_configuration_setting(key=event['data']['key'], label=event['data']['label'])
new_key = await client.get_configuration_setting(
key=event_grid_event['data']['key'], label=event_grid_event['data']['label']
)

all_keys.append(new_key)

Expand Down
4 changes: 2 additions & 2 deletions sdk/appconfiguration/azure-appconfiguration/samples/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ def print_configuration_setting(config_setting):

def get_connection_string():
try:
CONNECTION_STRING = os.environ['AZURE_APPCONFIG_CONNECTION_STRING']
CONNECTION_STRING = os.environ['APPCONFIGURATION_CONNECTION_STRING']
return CONNECTION_STRING

except KeyError:
print("AZURE_APPCONFIG_CONNECTION_STRING must be set.")
print("APPCONFIGURATION_CONNECTION_STRING must be set.")
sys.exit(1)