Skip to content
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

App Configuration Provider - Refresh Async #31516

Merged
merged 25 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
0904ab9
Updating with Async
mrm9084 Aug 8, 2023
6638b32
Fixing key vault references
mrm9084 Aug 8, 2023
f684488
Update _azureappconfigurationproviderasync.py
mrm9084 Aug 8, 2023
dbc2779
Update _azureappconfigurationproviderasync.py
mrm9084 Aug 8, 2023
2e0a107
Merge branch 'main' into RefreshAsync
mrm9084 Aug 25, 2023
5941f3d
Updating Tests
mrm9084 Aug 28, 2023
ed61c8f
Fixing Tests
mrm9084 Aug 28, 2023
45f2098
Fixing api-version in recordings
mrm9084 Aug 28, 2023
8763529
Review comments
mrm9084 Sep 6, 2023
1464bd8
Merge branch 'RefreshAsync' of https://github.com/mrm9084/azure-sdk-f…
mrm9084 Sep 6, 2023
a7d9c79
Fixing import and formatting
mrm9084 Sep 6, 2023
3355561
Update _azureappconfigurationproviderasync.py
mrm9084 Sep 6, 2023
d83ff11
Update _azureappconfigurationproviderasync.py
mrm9084 Sep 6, 2023
4da7903
Update _azureappconfigurationproviderasync.py
mrm9084 Sep 7, 2023
5fa6a10
Update _azureappconfigurationproviderasync.py
mrm9084 Sep 7, 2023
3fadddf
Updated change log, user_agent support, integration test user agent, …
mrm9084 Sep 11, 2023
275c37f
Added Accept to ignore header list
mrm9084 Sep 12, 2023
3919afe
Spelling
mrm9084 Sep 12, 2023
ebcf98b
Review comments
mrm9084 Sep 12, 2023
157e5a9
process key value needs await now
mrm9084 Sep 12, 2023
e14c062
Updating feature test because of 1.4.0 to 1.5.0b3 breaking change
mrm9084 Sep 12, 2023
70af0ea
Formatting
mrm9084 Sep 12, 2023
be19ade
Fixing extra check
mrm9084 Sep 12, 2023
0504c34
Update assets.json
mrm9084 Sep 12, 2023
a79a016
Update test_async_provider_aad.py
mrm9084 Sep 12, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "python",
"TagPrefix": "python/appconfiguration/azure-appconfiguration-provider",
"Tag": "python/appconfiguration/azure-appconfiguration-provider_7138010c10"
"Tag": "python/appconfiguration/azure-appconfiguration-provider_39244029c7"
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,20 @@ async def create_aad_client(
trim_prefixes=[],
selects={SettingSelector(key_filter="*", label_filter="\0")},
keyvault_secret_url=None,
refresh_on=None,
refresh_interval=30,
):
cred = self.get_credential(AzureAppConfigurationClient, is_async=True)

client = AzureAppConfigurationClient(appconfiguration_endpoint_string, cred)
await setup_configs(client, keyvault_secret_url)
return await load(
credential=cred, endpoint=appconfiguration_endpoint_string, trim_prefixes=trim_prefixes, selects=selects
credential=cred,
endpoint=appconfiguration_endpoint_string,
trim_prefixes=trim_prefixes,
selects=selects,
refresh_on=refresh_on,
refresh_interval=refresh_interval,
)

async def create_client(
Expand All @@ -36,11 +44,17 @@ async def create_client(
trim_prefixes=[],
selects={SettingSelector(key_filter="*", label_filter="\0")},
keyvault_secret_url=None,
refresh_on=None,
refresh_interval=30,
):
client = AzureAppConfigurationClient.from_connection_string(appconfiguration_connection_string)
await setup_configs(client, keyvault_secret_url)
return await load(
connection_string=appconfiguration_connection_string, trim_prefixes=trim_prefixes, selects=selects
connection_string=appconfiguration_connection_string,
trim_prefixes=trim_prefixes,
selects=selects,
refresh_on=refresh_on,
refresh_interval=refresh_interval,
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,7 @@ def add_sanitizers(test_proxy):
value="https://fake-key-vault.vault.azure.net/",
target=os.environ.get("APPCONFIGURATION_KEY_VAULT_REFERENCE", "https://fake-key-vault.vault.azure.net/"),
)

add_general_regex_sanitizer(value="api-version=1970-01-01", regex="api-version=.+")
set_custom_default_matcher(ignored_headers="x-ms-content-sha256")
add_oauth_response_sanitizer()
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ async def test_provider_creation(self, appconfiguration_connection_string, appco
assert client["my_json"]["key"] == "value"
assert (
client["FeatureManagementFeatureFlags"]["Alpha"]
== '{"enabled": false, "conditions": {"client_filters": []}}'
== '{"id": "Alpha", "enabled": false, "conditions": {"client_filters": []}}'
)

# method: provider_trim_prefixes
Expand All @@ -43,7 +43,7 @@ async def test_provider_trim_prefixes(
assert "test.trimmed" not in client
assert (
client["FeatureManagementFeatureFlags"]["Alpha"]
== '{"enabled": false, "conditions": {"client_filters": []}}'
== '{"id": "Alpha", "enabled": false, "conditions": {"client_filters": []}}'
)

# method: provider_selectors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async def test_provider_creation_aad(self, appconfiguration_endpoint_string, app
assert client["my_json"]["key"] == "value"
assert (
client["FeatureManagementFeatureFlags"]["Alpha"]
== '{"enabled": false, "conditions": {"client_filters": []}}'
== '{"id": "Alpha", "enabled": false, "conditions": {"client_filters": []}}'
mrm9084 marked this conversation as resolved.
Show resolved Hide resolved
)

# method: provider_trim_prefixes
Expand All @@ -42,7 +42,7 @@ async def test_provider_trim_prefixes(self, appconfiguration_endpoint_string, ap
assert "test.trimmed" not in client
assert (
client["FeatureManagementFeatureFlags"]["Alpha"]
== '{"enabled": false, "conditions": {"client_filters": []}}'
== '{"id": "Alpha", "enabled": false, "conditions": {"client_filters": []}}'
)

# method: provider_selectors
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
import time
import unittest
from azure.appconfiguration.provider import SettingSelector, SentinelKey
from azure.appconfiguration.provider.aio import load
from devtools_testutils.aio import recorded_by_proxy_async
from azure.appconfiguration.aio import AzureAppConfigurationClient
from async_preparers import app_config_decorator_async
from asynctestcase import AppConfigTestCase


class TestAppConfigurationProvider(AppConfigTestCase, unittest.TestCase):
# method: refresh
@app_config_decorator_async
@recorded_by_proxy_async
async def test_refresh(self, appconfiguration_endpoint_string, appconfiguration_keyvault_secret_url):
async with await self.create_aad_client(
appconfiguration_endpoint_string,
keyvault_secret_url=appconfiguration_keyvault_secret_url,
refresh_on=[SentinelKey("refresh_message")],
refresh_interval=1,
) as client:
assert client["refresh_message"] == "original value"
assert client["my_json"]["key"] == "value"
assert (
client["FeatureManagementFeatureFlags"]["Alpha"]
== '{"id": "Alpha", "enabled": false, "conditions": {"client_filters": []}}'
)
setting = await client._client.get_configuration_setting(key="refresh_message")
setting.value = "updated value"
await client._client.set_configuration_setting(setting)

# Waiting for the refresh interval to pass
time.sleep(2)

await client.refresh()
assert client["refresh_message"] == "updated value"

setting.value = "original value"
await client._client.set_configuration_setting(setting)

# Waiting for the refresh interval to pass
time.sleep(2)

await client.refresh()
assert client["refresh_message"] == "original value"

setting.value = "updated value 2"
await client._client.set_configuration_setting(setting)

# Not waiting for the refresh interval to pass
await client.refresh()
assert client["refresh_message"] == "original value"

setting.value = "original value"
await client._client.set_configuration_setting(setting)

await client.refresh()
assert client["refresh_message"] == "original value"
mrm9084 marked this conversation as resolved.
Show resolved Hide resolved

# method: refresh
@app_config_decorator_async
@recorded_by_proxy_async
async def test_empty_refresh(self, appconfiguration_endpoint_string, appconfiguration_keyvault_secret_url):
async with await self.create_aad_client(
appconfiguration_endpoint_string, keyvault_secret_url=appconfiguration_keyvault_secret_url
) as client:
assert client["refresh_message"] == "original value"
assert client["non_refreshed_message"] == "Static"
assert client["my_json"]["key"] == "value"
assert (
client["FeatureManagementFeatureFlags"]["Alpha"]
== '{"id": "Alpha", "enabled": false, "conditions": {"client_filters": []}}'
)
setting = await client._client.get_configuration_setting(key="refresh_message")
setting.value = "updated value"
await client._client.set_configuration_setting(setting)
static_setting = await client._client.get_configuration_setting(key="non_refreshed_message")
static_setting.value = "updated static"
await client._client.set_configuration_setting(static_setting)

# Waiting for the refresh interval to pass
time.sleep(2)

await client.refresh()
assert client["refresh_message"] == "original value"
assert client["non_refreshed_message"] == "Static"

setting.value = "original value"
await client._client.set_configuration_setting(setting)
static_setting.value = "Static"
await client._client.set_configuration_setting(static_setting)

def my_callback(self):
assert True

def my_callback_on_fail(self):
assert False
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def test_provider_creation(self, appconfiguration_connection_string, appconfigur
assert client["my_json"]["key"] == "value"
assert (
client["FeatureManagementFeatureFlags"]["Alpha"]
== '{"enabled": false, "conditions": {"client_filters": []}}'
== '{"id": "Alpha", "enabled": false, "conditions": {"client_filters": []}}'
)

# method: provider_trim_prefixes
Expand All @@ -40,7 +40,7 @@ def test_provider_trim_prefixes(self, appconfiguration_connection_string, appcon
assert "test.trimmed" not in client
assert (
client["FeatureManagementFeatureFlags"]["Alpha"]
== '{"enabled": false, "conditions": {"client_filters": []}}'
== '{"id": "Alpha", "enabled": false, "conditions": {"client_filters": []}}'
)

# method: provider_selectors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def test_provider_creation_aad(self, appconfiguration_endpoint_string, appconfig
assert client["my_json"]["key"] == "value"
assert (
client["FeatureManagementFeatureFlags"]["Alpha"]
== '{"enabled": false, "conditions": {"client_filters": []}}'
== '{"id": "Alpha", "enabled": false, "conditions": {"client_filters": []}}'
)

# method: provider_trim_prefixes
Expand All @@ -40,7 +40,7 @@ def test_provider_trim_prefixes(self, appconfiguration_endpoint_string, appconfi
assert "test.trimmed" not in client
assert (
client["FeatureManagementFeatureFlags"]["Alpha"]
== '{"enabled": false, "conditions": {"client_filters": []}}'
== '{"id": "Alpha", "enabled": false, "conditions": {"client_filters": []}}'
)

# method: provider_selectors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def test_refresh(self, appconfiguration_endpoint_string, appconfiguration_keyvau
assert client["my_json"]["key"] == "value"
assert (
client["FeatureManagementFeatureFlags"]["Alpha"]
== '{"enabled": false, "conditions": {"client_filters": []}}'
== '{"id": "Alpha", "enabled": false, "conditions": {"client_filters": []}}'
)
setting = client._client.get_configuration_setting(key="refresh_message")
setting.value = "updated value"
Expand Down Expand Up @@ -73,7 +73,7 @@ def test_empty_refresh(self, appconfiguration_endpoint_string, appconfiguration_
assert client["my_json"]["key"] == "value"
assert (
client["FeatureManagementFeatureFlags"]["Alpha"]
== '{"enabled": false, "conditions": {"client_filters": []}}'
== '{"id": "Alpha", "enabled": false, "conditions": {"client_filters": []}}'
)
setting = client._client.get_configuration_setting(key="refresh_message")
setting.value = "updated value"
Expand Down
Loading