Skip to content

Commit

Permalink
fix etag issues and update generated code
Browse files Browse the repository at this point in the history
  • Loading branch information
xiangyan99 committed Sep 10, 2019
1 parent 30c63ac commit 4777f7d
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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'},
Expand All @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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'},
Expand All @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
)
from ..utils import (
get_endpoint_from_connection_string,
escape_and_tolist,
prep_update_configuration_setting,
quote_etag,
)
Expand Down Expand Up @@ -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]`
Expand All @@ -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,
Expand Down Expand Up @@ -279,21 +276,22 @@ 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
key_value_updated = await self._impl.put_key_value(
entity=key_value,
key=key,
label=label,
if_match=etag,
if_match=if_match,
headers=custom_headers,
error_map={404: ResourceNotFoundError, 412: ResourceModifiedError},
)
Expand Down Expand Up @@ -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},
)
Expand Down Expand Up @@ -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]`
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down Expand Up @@ -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]`
Expand All @@ -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,
Expand Down Expand Up @@ -268,21 +265,22 @@ 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
key_value_updated = self._impl.put_key_value(
entity=key_value,
key=key,
label=label,
if_match=etag,
if_match=if_match,
headers=custom_headers,
error_map={404: ResourceNotFoundError, 412: ResourceModifiedError},
)
Expand Down Expand Up @@ -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},
)
Expand Down Expand Up @@ -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]`
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 + '"'
Expand Down

0 comments on commit 4777f7d

Please sign in to comment.