From 4777f7d1c065f8e30b5126e3e0fd52b657efee06 Mon Sep 17 00:00:00 2001 From: Xiang Yan Date: Tue, 10 Sep 2019 16:51:32 -0700 Subject: [PATCH] fix etag issues and update generated code --- .../_generated/models/_models.py | 27 +++++++++++------ .../_generated/models/_models_py3.py | 29 ++++++++++++------- .../aio/azure_configuration_client_async.py | 21 ++++++-------- .../azure_appconfiguration_client.py | 21 ++++++-------- .../azure/appconfiguration/utils.py | 28 ------------------ 5 files changed, 55 insertions(+), 71 deletions(-) diff --git a/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/_generated/models/_models.py b/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/_generated/models/_models.py index f5ba3239509b..d8a1b39810f5 100644 --- a/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/_generated/models/_models.py +++ b/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/_generated/models/_models.py @@ -104,6 +104,9 @@ def __init__(self, **kwargs): class KeyValue(Model): """KeyValue. + Variables are only populated by the server, and will be ignored when + sending a request. + :param key: :type key: str :param label: @@ -112,16 +115,22 @@ class KeyValue(Model): :type content_type: str :param value: :type value: str - :param last_modified: - :type last_modified: datetime + :ivar last_modified: + :vartype last_modified: datetime :param tags: :type tags: dict[str, str] - :param locked: - :type locked: bool - :param etag: - :type etag: str + :ivar locked: + :vartype locked: bool + :ivar etag: + :vartype etag: str """ + _validation = { + 'last_modified': {'readonly': True}, + 'locked': {'readonly': True}, + 'etag': {'readonly': True}, + } + _attribute_map = { 'key': {'key': 'key', 'type': 'str'}, 'label': {'key': 'label', 'type': 'str'}, @@ -139,10 +148,10 @@ def __init__(self, **kwargs): self.label = kwargs.get('label', None) self.content_type = kwargs.get('content_type', None) self.value = kwargs.get('value', None) - self.last_modified = kwargs.get('last_modified', None) + self.last_modified = None self.tags = kwargs.get('tags', None) - self.locked = kwargs.get('locked', None) - self.etag = kwargs.get('etag', None) + self.locked = None + self.etag = None class KeyValueListResult(Model): diff --git a/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/_generated/models/_models_py3.py b/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/_generated/models/_models_py3.py index f5a097fa4801..9fec867ee843 100644 --- a/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/_generated/models/_models_py3.py +++ b/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/_generated/models/_models_py3.py @@ -104,6 +104,9 @@ def __init__(self, *, items=None, next_link: str=None, **kwargs) -> None: class KeyValue(Model): """KeyValue. + Variables are only populated by the server, and will be ignored when + sending a request. + :param key: :type key: str :param label: @@ -112,16 +115,22 @@ class KeyValue(Model): :type content_type: str :param value: :type value: str - :param last_modified: - :type last_modified: datetime + :ivar last_modified: + :vartype last_modified: datetime :param tags: :type tags: dict[str, str] - :param locked: - :type locked: bool - :param etag: - :type etag: str + :ivar locked: + :vartype locked: bool + :ivar etag: + :vartype etag: str """ + _validation = { + 'last_modified': {'readonly': True}, + 'locked': {'readonly': True}, + 'etag': {'readonly': True}, + } + _attribute_map = { 'key': {'key': 'key', 'type': 'str'}, 'label': {'key': 'label', 'type': 'str'}, @@ -133,16 +142,16 @@ class KeyValue(Model): 'etag': {'key': 'etag', 'type': 'str'}, } - def __init__(self, *, key: str=None, label: str=None, content_type: str=None, value: str=None, last_modified=None, tags=None, locked: bool=None, etag: str=None, **kwargs) -> None: + def __init__(self, *, key: str=None, label: str=None, content_type: str=None, value: str=None, tags=None, **kwargs) -> None: super(KeyValue, self).__init__(**kwargs) self.key = key self.label = label self.content_type = content_type self.value = value - self.last_modified = last_modified + self.last_modified = None self.tags = tags - self.locked = locked - self.etag = etag + self.locked = None + self.etag = None class KeyValueListResult(Model): diff --git a/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/aio/azure_configuration_client_async.py b/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/aio/azure_configuration_client_async.py index 325daeef90b6..c1c3634aa7a2 100644 --- a/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/aio/azure_configuration_client_async.py +++ b/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/aio/azure_configuration_client_async.py @@ -17,7 +17,6 @@ ) from ..utils import ( get_endpoint_from_connection_string, - escape_and_tolist, prep_update_configuration_setting, quote_etag, ) @@ -126,8 +125,8 @@ def list_configuration_settings( :type keys: list[str] :param accept_date_time: filter out ConfigurationSetting created after this datetime :type accept_date_time: datetime - :param fields: specify which fields to include in the results. Leave None to include all fields - :type fields: list[str] + :param select: specify which fields to include in the results. Leave None to include all fields + :type select: list[str] :param dict kwargs: if "headers" exists, its value (a dict) will be added to the http request header :return: An iterator of :class:`ConfigurationSetting` :rtype: :class:`azure.core.paging.ItemPaged[ConfigurationSetting]` @@ -151,8 +150,6 @@ def list_configuration_settings( async for item in filtered_listed: pass # do something """ - labels = escape_and_tolist(labels) - keys = escape_and_tolist(keys) return self._impl.get_key_values( label=labels, key=keys, @@ -279,13 +276,14 @@ async def update_configuration_setting( ) if key_value is None: - return None + raise ResourceNotFoundError() if value is not None: key_value.value = value content_type = kwargs.get("content_type") if content_type is not None: key_value.content_type = content_type + if_match = quote_etag(etag) if etag else None tags = kwargs.get("tags") if tags is not None: key_value.tags = tags @@ -293,7 +291,7 @@ async def update_configuration_setting( entity=key_value, key=key, label=label, - if_match=etag, + if_match=if_match, headers=custom_headers, error_map={404: ResourceNotFoundError, 412: ResourceModifiedError}, ) @@ -340,11 +338,12 @@ async def set_configuration_setting( ) custom_headers = CaseInsensitiveDict(kwargs.get("headers")) etag = configuration_setting.etag + if_match = quote_etag(etag) if etag else None key_value_set = await self._impl.put_key_value( entity=key_value, key=key_value.key, label=key_value.label, - if_match=etag, + if_match=if_match, headers=custom_headers, error_map={412: ResourceModifiedError}, ) @@ -408,8 +407,8 @@ def list_revisions( :type keys: list[str] :param accept_date_time: filter out ConfigurationSetting created after this datetime :type accept_date_time: datetime - :param fields: specify which fields to include in the results. Leave None to include all fields - :type fields: list[str] + :param select: specify which fields to include in the results. Leave None to include all fields + :type select: list[str] :param dict kwargs: if "headers" exists, its value (a dict) will be added to the http request header :return: An iterator of :class:`ConfigurationSetting` :rtype: :class:`azure.core.paging.ItemPaged[ConfigurationSetting]` @@ -434,8 +433,6 @@ def list_revisions( async for item in filtered_revisions: pass # do something """ - labels = escape_and_tolist(labels) - keys = escape_and_tolist(keys) return self._impl.get_revisions( label=labels, key=keys, diff --git a/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/azure_appconfiguration_client.py b/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/azure_appconfiguration_client.py index dbddcc1bc93a..447edeff9d33 100644 --- a/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/azure_appconfiguration_client.py +++ b/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/azure_appconfiguration_client.py @@ -22,7 +22,6 @@ from .azure_appconfiguration_credential import AppConfigConnectionStringCredential from .utils import ( get_endpoint_from_connection_string, - escape_and_tolist, prep_update_configuration_setting, quote_etag, ) @@ -117,8 +116,8 @@ def list_configuration_settings( :type keys: list[str] :param accept_date_time: filter out ConfigurationSetting created after this datetime :type accept_date_time: datetime - :param fields: specify which fields to include in the results. Leave None to include all fields - :type fields: list[str] + :param select: specify which fields to include in the results. Leave None to include all fields + :type select: list[str] :param dict kwargs: if "headers" exists, its value (a dict) will be added to the http request header :return: An iterator of :class:`ConfigurationSetting` :rtype: :class:`azure.core.paging.ItemPaged[ConfigurationSetting]` @@ -142,8 +141,6 @@ def list_configuration_settings( for item in filtered_listed: pass # do something """ - labels = escape_and_tolist(labels) - keys = escape_and_tolist(keys) return self._impl.get_key_values( label=labels, key=keys, @@ -268,13 +265,14 @@ def update_configuration_setting( ) if key_value is None: - return None + raise ResourceNotFoundError() if value is not None: key_value.value = value content_type = kwargs.get("content_type") if content_type is not None: key_value.content_type = content_type + if_match = quote_etag(etag) if etag else None tags = kwargs.get("tags") if tags is not None: key_value.tags = tags @@ -282,7 +280,7 @@ def update_configuration_setting( entity=key_value, key=key, label=label, - if_match=etag, + if_match=if_match, headers=custom_headers, error_map={404: ResourceNotFoundError, 412: ResourceModifiedError}, ) @@ -328,11 +326,12 @@ def set_configuration_setting( ) custom_headers = CaseInsensitiveDict(kwargs.get("headers")) etag = configuration_setting.etag + if_match = quote_etag(etag) if etag else None key_value_set = self._impl.put_key_value( entity=key_value, key=key_value.key, label=key_value.label, - if_match=etag, + if_match=if_match, headers=custom_headers, error_map={412: ResourceModifiedError}, ) @@ -395,8 +394,8 @@ def list_revisions( :type keys: list[str] :param accept_date_time: filter out ConfigurationSetting created after this datetime :type accept_date_time: datetime - :param fields: specify which fields to include in the results. Leave None to include all fields - :type fields: list[str] + :param select: specify which fields to include in the results. Leave None to include all fields + :type select: list[str] :param dict kwargs: if "headers" exists, its value (a dict) will be added to the http request header :return: An iterator of :class:`ConfigurationSetting` :rtype: :class:`azure.core.paging.ItemPaged[ConfigurationSetting]` @@ -420,8 +419,6 @@ def list_revisions( for item in filtered_revisions: pass # do something """ - labels = escape_and_tolist(labels) - keys = escape_and_tolist(keys) return self._impl.get_revisions( label=labels, key=keys, diff --git a/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/utils.py b/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/utils.py index 8f38c4b3a43f..23c16a51b828 100644 --- a/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/utils.py +++ b/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/utils.py @@ -8,34 +8,6 @@ import re from requests.structures import CaseInsensitiveDict - -def escape_reserved(value): - """ - Reserved characters are star(*), comma(,) and backslash(\\) - If a reserved character is part of the value, then it must be escaped using \\{Reserved Character}. - Non-reserved characters can also be escaped. - - """ - if value is None: - return None - if value == "": - return "\0" # '\0' will be encoded to %00 in the url. - if isinstance(value, list): - return [escape_reserved(s) for s in value] - value = str(value) # value is unicode for Python 2.7 - # precede all reserved characters with a backslash. - # But if a * is at the beginning or the end, don't add the backslash - return re.sub(r"((?!^)\*(?!$)|\\|,)", r"\\\1", value) - - -def escape_and_tolist(value): - if value is not None: - if isinstance(value, str): - value = [value] - value = escape_reserved(value) - return value - - def quote_etag(etag): if etag != "*" and etag is not None: return '"' + etag + '"'