Skip to content

Commit

Permalink
rename keys/labels to key_filter/label_filter
Browse files Browse the repository at this point in the history
  • Loading branch information
xiangyan99 committed Dec 11, 2019
1 parent e05d09a commit c7e9764
Show file tree
Hide file tree
Showing 8 changed files with 188 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,18 +144,18 @@ def _create_appconfig_pipeline(self, credential, base_url=None, aad_mode=False,

@distributed_trace
def list_configuration_settings(
self, keys=None, labels=None, **kwargs
self, key_filter=None, label_filter=None, **kwargs
): # type: (Optional[str], Optional[str], dict) -> azure.core.paging.ItemPaged[ConfigurationSetting]

"""List the configuration settings stored in the configuration service, optionally filtered by
label and accept_datetime
:param keys: filter results based on their keys. '*' can be
:param key_filter: filter results based on their keys. '*' can be
used as wildcard in the beginning or end of the filter
:type keys: str
:param labels: filter results based on their label. '*' can be
:type key_filter: str
:param label_filter: filter results based on their label. '*' can be
used as wildcard in the beginning or end of the filter
:type labels: str
:type label_filter: str
:keyword datetime accept_datetime: filter out ConfigurationSetting created after this datetime
:keyword list[str] fields: specify which fields to include in the results. Leave None to include all fields
:keyword dict headers: if "headers" exists, its value (a dict) will be added to the http request header
Expand All @@ -176,7 +176,7 @@ def list_configuration_settings(
pass # do something
filtered_listed = client.list_configuration_settings(
labels="*Labe*", keys="*Ke*", accept_datetime=accept_datetime
label_filter="*Labe*", key_filter="*Ke*", accept_datetime=accept_datetime
)
for item in filtered_listed:
pass # do something
Expand All @@ -190,8 +190,8 @@ def list_configuration_settings(

try:
return self._impl.get_key_values(
label=labels,
key=keys,
label=label_filter,
key=key_filter,
select=select,
cls=lambda objs: [ConfigurationSetting._from_key_value(x) for x in objs],
error_map=error_map,
Expand Down Expand Up @@ -434,18 +434,18 @@ def delete_configuration_setting(

@distributed_trace
def list_revisions(
self, keys=None, labels=None, **kwargs
self, key_filter=None, label_filter=None, **kwargs
): # type: (Optional[str], Optional[str], dict) -> azure.core.paging.ItemPaged[ConfigurationSetting]

"""
Find the ConfigurationSetting revision history.
:param keys: filter results based on their keys. '*' can be
:param key_filter: filter results based on their keys. '*' can be
used as wildcard in the beginning or end of the filter
:type keys: str
:param labels: filter results based on their label. '*' can be
:type key_filter: str
:param label_filter: filter results based on their label. '*' can be
used as wildcard in the beginning or end of the filter
:type labels: str
:type label_filter: str
:keyword datetime accept_datetime: filter out ConfigurationSetting created after this datetime
:keyword list[str] fields: specify which fields to include in the results. Leave None to include all fields
:keyword dict headers: if "headers" exists, its value (a dict) will be added to the http request header
Expand All @@ -466,7 +466,7 @@ def list_revisions(
pass # do something
filtered_revisions = client.list_revisions(
labels="*Labe*", keys="*Ke*", accept_datetime=accept_datetime
label_filter="*Labe*", key_filter="*Ke*", accept_datetime=accept_datetime
)
for item in filtered_revisions:
pass # do something
Expand All @@ -480,8 +480,8 @@ def list_revisions(

try:
return self._impl.get_revisions(
label=labels,
key=keys,
label=label_filter,
key=key_filter,
select=select,
cls=lambda objs: [ConfigurationSetting._from_key_value(x) for x in objs],
error_map=error_map,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,18 +154,18 @@ def _create_appconfig_pipeline(self, credential, base_url=None, aad_mode=False,

@distributed_trace
def list_configuration_settings(
self, keys=None, labels=None, **kwargs
self, key_filter=None, label_filter=None, **kwargs
): # type: (Optional[str], Optional[str], dict) -> azure.core.paging.ItemPaged[ConfigurationSetting]

"""List the configuration settings stored in the configuration service, optionally filtered by
label and accept_datetime
:param keys: filter results based on their keys. '*' can be
:param key_filter: filter results based on their keys. '*' can be
used as wildcard in the beginning or end of the filter
:type keys: str
:param labels: filter results based on their label. '*' can be
:type key_filter: str
:param label_filter: filter results based on their label. '*' can be
used as wildcard in the beginning or end of the filter
:type labels: str
:type label_filter: str
:keyword datetime accept_datetime: filter out ConfigurationSetting created after this datetime
:keyword list[str] fields: specify which fields to include in the results. Leave None to include all fields
:keyword dict headers: if "headers" exists, its value (a dict) will be added to the http request header
Expand All @@ -186,7 +186,7 @@ def list_configuration_settings(
pass # do something
filtered_listed = async_client.list_configuration_settings(
labels="*Labe*", keys="*Ke*", accept_datetime=accept_datetime
label_filter="*Labe*", key_filter="*Ke*", accept_datetime=accept_datetime
)
async for item in filtered_listed:
pass # do something
Expand All @@ -200,8 +200,8 @@ def list_configuration_settings(

try:
return self._impl.get_key_values(
label=labels,
key=keys,
label=label_filter,
key=key_filter,
select=select,
cls=lambda objs: [ConfigurationSetting._from_key_value(x) for x in objs],
error_map=error_map,
Expand Down Expand Up @@ -450,18 +450,18 @@ async def delete_configuration_setting(

@distributed_trace
def list_revisions(
self, keys=None, labels=None, **kwargs
self, key_filter=None, label_filter=None, **kwargs
): # type: (Optional[str], Optional[str], dict) -> azure.core.paging.AsyncItemPaged[ConfigurationSetting]

"""
Find the ConfigurationSetting revision history.
:param keys: filter results based on their keys. '*' can be
:param key_filter: filter results based on their keys. '*' can be
used as wildcard in the beginning or end of the filter
:type keys: str
:param labels: filter results based on their label. '*' can be
:type key_filter: str
:param label_filter: filter results based on their label. '*' can be
used as wildcard in the beginning or end of the filter
:type labels: str
:type label_filter: str
:keyword datetime accept_datetime: filter out ConfigurationSetting created after this datetime
:keyword list[str] fields: specify which fields to include in the results. Leave None to include all fields
:keyword dict headers: if "headers" exists, its value (a dict) will be added to the http request header
Expand All @@ -483,7 +483,7 @@ def list_revisions(
pass # do something
filtered_revisions = async_client.list_revisions(
labels="*Labe*", keys="*Ke*", accept_datetime=accept_datetime
label_filter="*Labe*", key_filter="*Ke*", accept_datetime=accept_datetime
)
async for item in filtered_revisions:
pass # do something
Expand All @@ -497,8 +497,8 @@ def list_revisions(

try:
return self._impl.get_revisions(
label=labels,
key=keys,
label=label_filter,
key=key_filter,
select=select,
cls=lambda objs: [ConfigurationSetting._from_key_value(x) for x in objs],
error_map=error_map,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# ------------------------------------
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------

import azure.mgmt.appconfiguration
import time
import os
from devtools_testutils import AzureMgmtPreparer, ResourceGroupPreparer
from devtools_testutils.resource_testcase import RESOURCE_GROUP_PARAM
from azure_devtools.scenario_tests.exceptions import AzureTestError
from azure.appconfiguration import AzureAppConfigurationClient
try:
from unittest.mock import Mock
except ImportError: # python < 3.3
from mock import Mock
from azure.core.credentials import AccessToken

class AppConfigurationPreparer(AzureMgmtPreparer):
def __init__(self,
name_prefix="appconfig",
parameter_name="app_config_client",
aad_mode=False,
resource_group_parameter_name=RESOURCE_GROUP_PARAM,
disable_recording=True,
playback_fake_resource=None,
client_kwargs=None):
super(AppConfigurationPreparer, self).__init__(
name_prefix,
24,
disable_recording=disable_recording,
playback_fake_resource=playback_fake_resource,
client_kwargs=client_kwargs,
)
self.resource_group_parameter_name = resource_group_parameter_name
self.parameter_name = parameter_name
self.aad_mode = aad_mode

def _get_resource_group(self, **kwargs):
try:
return kwargs[self.resource_group_parameter_name]
except KeyError:
template = (
"To create a key vault a resource group is required. Please add "
"decorator @{} in front of this storage account preparer."
)
raise AzureTestError(template.format(ResourceGroupPreparer.__name__))

def create_resource(self, name, **kwargs):
#self.client_oid = self.test_class_instance.set_value_to_scrub("CLIENT_OID", CLIENT_OID)
if self.is_live:
BODY = {
"location": "westus",
"sku": {
"name": "Free"
}
}
group = self._get_resource_group(**kwargs).name
self.mgmt_client = self.create_mgmt_client(
azure.mgmt.appconfiguration.AppConfigurationManagementClient
)
result = self.mgmt_client.configuration_stores.create(group, name, BODY)

# ARM may return not found at first even though the resource group has been created
retries = 4
for i in range(retries):
try:
result = result.result()
if result.provisioning_state == "Succeeded":
break
except Exception as ex:
if i == retries - 1:
raise
time.sleep(3)
result = self.mgmt_client.configuration_stores.get(group, name)
result = list(self.mgmt_client.configuration_stores.list_keys(group, name))
if len(result) > 0:
connection_str = result[0].connection_string
if self.aad_mode:
base_url = "https://fake_app_config.azconfig-test.io"
credential = Mock(get_token=lambda _: AccessToken("fake-token", 0))
app_config_client = AzureAppConfigurationClient(base_url=base_url, credential=credential)
else:
app_config_client = AzureAppConfigurationClient.from_connection_string(connection_str)
pass
else:
# playback => we need only the uri used in the recording
vault_uri = "https://{}.vault.azure.net/".format(name)

return {self.parameter_name: app_config_client}
12 changes: 6 additions & 6 deletions sdk/appconfiguration/azure-appconfiguration/tests/async_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,23 @@ def delete_configuration_setting(self, key, label=None, etag=None, **kwargs):
)

def list_configuration_settings(
self, labels=None, keys=None, accept_datetime=None, fields=None, **kwargs
self, label_filter=None, key_filter=None, accept_datetime=None, fields=None, **kwargs
):
paged = self.obj.list_configuration_settings(
labels=labels,
keys=keys,
label_filter=label_filter,
key_filter=key_filter,
accept_datetime=accept_datetime,
fields=fields,
**kwargs
)
return _to_list(paged)

def list_revisions(
self, labels=None, keys=None, accept_datetime=None, fields=None, **kwargs
self, label_filter=None, key_filter=None, accept_datetime=None, fields=None, **kwargs
):
paged = self.obj.list_revisions(
labels=labels,
keys=keys,
label_filter=label_filter,
key_filter=key_filter,
accept_datetime=accept_datetime,
fields=fields,
**kwargs
Expand Down
Loading

0 comments on commit c7e9764

Please sign in to comment.