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
6 changes: 6 additions & 0 deletions sdk/appconfiguration/azure-appconfiguration/HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@

-------------------

## 2019-12-xx Version 1.0.0b6

### Breaking changes

- Combine set_read_only & clear_read_only to be set_read_only(True/False) #8453

## 2019-10-30 Version 1.0.0b5

### Breaking changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,13 +471,15 @@ def list_revisions(

@distributed_trace
def set_read_only(
self, configuration_setting, **kwargs
): # type: (ConfigurationSetting, dict) -> ConfigurationSetting
self, configuration_setting, read_only=True, **kwargs
): # type: (ConfigurationSetting, Optional[bool], dict) -> ConfigurationSetting

"""Set a configuration setting read only

:param configuration_setting: the ConfigurationSetting to be set read only
:type configuration_setting: :class:`ConfigurationSetting`
:param read_only: set the read only setting if true, else clear the read only setting
:type read_only: bool
:keyword dict headers: if "headers" exists, its value (a dict) will be added to the http request header
:return: The ConfigurationSetting returned from the service
:rtype: :class:`ConfigurationSetting`
Expand All @@ -492,59 +494,28 @@ def set_read_only(
)

read_only_config_setting = client.set_read_only(config_setting)
read_only_config_setting = client.set_read_only(config_setting, read_only=False)
"""
error_map = {
401: ClientAuthenticationError,
404: ResourceNotFoundError
}

try:
key_value = self._impl.put_lock(
key=configuration_setting.key,
label=configuration_setting.label,
error_map=error_map,
**kwargs
)
return ConfigurationSetting._from_key_value(key_value)
except ErrorException as error:
raise HttpResponseError(message=error.message, response=error.response)

@distributed_trace
def clear_read_only(
self, configuration_setting, **kwargs
): # type: (ConfigurationSetting, dict) -> ConfigurationSetting

"""Clear read only flag for a configuration setting

:param configuration_setting: the ConfigurationSetting to be read only clear
:type configuration_setting: :class:`ConfigurationSetting`
:keyword dict headers: if "headers" exists, its value (a dict) will be added to the http request header
:return: The ConfigurationSetting returned from the service
:rtype: :class:`ConfigurationSetting`
:raises: :class:`HttpResponseError`, :class:`ClientAuthenticationError`, :class:`ResourceNotFoundError`

Example

.. code-block:: python

config_setting = client.get_configuration_setting(
key="MyKey", label="MyLabel"
)

read_only_config_setting = client.clear_read_only(config_setting)
"""
error_map = {
401: ClientAuthenticationError,
404: ResourceNotFoundError
}

try:
key_value = self._impl.delete_lock(
key=configuration_setting.key,
label=configuration_setting.label,
error_map=error_map,
**kwargs
)
if read_only:
key_value = self._impl.put_lock(
key=configuration_setting.key,
label=configuration_setting.label,
error_map=error_map,
**kwargs
)
else:
key_value = self._impl.delete_lock(
key=configuration_setting.key,
label=configuration_setting.label,
error_map=error_map,
**kwargs
)
return ConfigurationSetting._from_key_value(key_value)
except ErrorException as error:
raise HttpResponseError(message=error.message, response=error.response)
Original file line number Diff line number Diff line change
Expand Up @@ -487,13 +487,15 @@ def list_revisions(

@distributed_trace
async def set_read_only(
self, configuration_setting, **kwargs
): # type: (ConfigurationSetting, dict) -> ConfigurationSetting
self, configuration_setting, read_only=True, **kwargs
): # type: (ConfigurationSetting, Optional[bool], dict) -> ConfigurationSetting

"""Set a configuration setting read only

:param configuration_setting: the ConfigurationSetting to be set read only
:type configuration_setting: :class:`ConfigurationSetting`
:param read_only: set the read only setting if true, else clear the read only setting
:type read_only: bool
:keyword dict headers: if "headers" exists, its value (a dict) will be added to the http request header
:return: The ConfigurationSetting returned from the service
:rtype: :class:`ConfigurationSetting`
Expand All @@ -508,59 +510,28 @@ async def set_read_only(
)

read_only_config_setting = await async_client.set_read_only(config_setting)
read_only_config_setting = await client.set_read_only(config_setting, read_only=False)
"""
error_map = {
401: ClientAuthenticationError,
404: ResourceNotFoundError
}

try:
key_value = await self._impl.put_lock(
key=configuration_setting.key,
label=configuration_setting.label,
error_map=error_map,
**kwargs
)
return ConfigurationSetting._from_key_value(key_value)
except ErrorException as error:
raise HttpResponseError(message=error.message, response=error.response)

@distributed_trace
async def clear_read_only(
self, configuration_setting, **kwargs
): # type: (ConfigurationSetting, dict) -> ConfigurationSetting

"""Clear read only flag for a configuration setting

:param configuration_setting: the ConfigurationSetting to be read only clear
:type configuration_setting: :class:`ConfigurationSetting`
:keyword dict headers: if "headers" exists, its value (a dict) will be added to the http request header
:return: The ConfigurationSetting returned from the service
:rtype: :class:`ConfigurationSetting`
:raises: :class:`HttpResponseError`, :class:`ClientAuthenticationError`, :class:`ResourceNotFoundError`

Example

.. code-block:: python

config_setting = await async_client.get_configuration_setting(
key="MyKey", label="MyLabel"
)

read_only_config_setting = await async_client.clear_read_only(config_setting)
"""
error_map = {
401: ClientAuthenticationError,
404: ResourceNotFoundError
}

try:
key_value = await self._impl.delete_lock(
key=configuration_setting.key,
label=configuration_setting.label,
error_map=error_map,
**kwargs
)
if read_only:
key_value = await self._impl.put_lock(
key=configuration_setting.key,
label=configuration_setting.label,
error_map=error_map,
**kwargs
)
else:
key_value = await self._impl.delete_lock(
key=configuration_setting.key,
label=configuration_setting.label,
error_map=error_map,
**kwargs
)
return ConfigurationSetting._from_key_value(key_value)
except ErrorException as error:
raise HttpResponseError(message=error.message, response=error.response)
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pip install azure-appconfiguration
| 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/clear_read_only 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 |

<!-- LINKS -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"""
FILE: read_only_async_sample.py
DESCRIPTION:
This sample demos set_read_only/clear_read_only operations for app configuration
This sample demos set_read_only operations for app configuration
USAGE: python read_only_async_sample.py
"""

Expand Down Expand Up @@ -44,8 +44,8 @@ async def main():
print("")

print("Clear read only configuration setting:")
read_write_config_setting = await client.clear_read_only(
returned_config_setting
read_write_config_setting = await client.set_read_only(
returned_config_setting, False
)
print_configuration_setting(read_write_config_setting)
print("")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"""
FILE: read_only_sample.py
DESCRIPTION:
This sample demos set_read_only/clear_read_only operations for app configuration
This sample demos set_read_only operations for app configuration
USAGE: python read_only_sample.py
"""

Expand Down Expand Up @@ -42,8 +42,8 @@ def main():
print("")

print("Clear read only configuration setting:")
read_write_config_setting = client.clear_read_only(
returned_config_setting
read_write_config_setting = client.set_read_only(
returned_config_setting, False
)
print_configuration_setting(read_write_config_setting)
print("")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,7 @@ def set_configuration_setting(self, configuration_setting, **kwargs):
self.obj.set_configuration_setting(configuration_setting, **kwargs)
)

def set_read_only(self, configuration_setting, **kwargs):
def set_read_only(self, configuration_setting, read_only=True, **kwargs):
return get_event_loop().run_until_complete(
self.obj.set_read_only(configuration_setting, **kwargs)
)

def clear_read_only(self, configuration_setting, **kwargs):
return get_event_loop().run_until_complete(
self.obj.clear_read_only(configuration_setting, **kwargs)
self.obj.set_read_only(configuration_setting, read_only, **kwargs)
)
Original file line number Diff line number Diff line change
Expand Up @@ -348,15 +348,15 @@ def test_read_only(self):
kv = self.test_config_setting_no_label
read_only_kv = self.get_config_client().set_read_only(kv)
assert read_only_kv.read_only
readable_kv = self.get_config_client().clear_read_only(read_only_kv)
readable_kv = self.get_config_client().set_read_only(read_only_kv, False)
assert not readable_kv.read_only

def test_delete_read_only(self):
to_delete_kv = self.test_config_setting_no_label
read_only_kv = self.get_config_client().set_read_only(to_delete_kv)
with pytest.raises(ResourceReadOnlyError):
self.get_config_client().delete_configuration_setting(to_delete_kv.key)
self.get_config_client().clear_read_only(read_only_kv)
self.get_config_client().set_read_only(read_only_kv, False)
self.get_config_client().delete_configuration_setting(to_delete_kv.key)
self.to_delete.remove(to_delete_kv)
with pytest.raises(ResourceNotFoundError):
Expand All @@ -369,7 +369,7 @@ def test_set_read_only(self):
read_only_kv = self.get_config_client().set_read_only(to_set_kv)
with pytest.raises(ResourceReadOnlyError):
self.get_config_client().set_configuration_setting(read_only_kv)
readable_kv = self.get_config_client().clear_read_only(read_only_kv)
readable_kv = self.get_config_client().set_read_only(read_only_kv, False)
readable_kv.value = to_set_kv.value
readable_kv.tags = to_set_kv.tags
set_kv = self.get_config_client().set_configuration_setting(readable_kv)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,15 +347,15 @@ def test_read_only(self):
kv = self.test_config_setting_no_label
read_only_kv = self.get_config_client().set_read_only(kv)
assert read_only_kv.read_only
readable_kv = self.get_config_client().clear_read_only(read_only_kv)
readable_kv = self.get_config_client().set_read_only(read_only_kv, False)
assert not readable_kv.read_only

def test_delete_read_only(self):
to_delete_kv = self.test_config_setting_no_label
read_only_kv = self.get_config_client().set_read_only(to_delete_kv)
with pytest.raises(ResourceReadOnlyError):
self.get_config_client().delete_configuration_setting(to_delete_kv.key)
self.get_config_client().clear_read_only(read_only_kv)
self.get_config_client().set_read_only(read_only_kv, False)
self.get_config_client().delete_configuration_setting(to_delete_kv.key)
self.to_delete.remove(to_delete_kv)
with pytest.raises(ResourceNotFoundError):
Expand All @@ -368,7 +368,7 @@ def test_set_read_only(self):
read_only_kv = self.get_config_client().set_read_only(to_set_kv)
with pytest.raises(ResourceReadOnlyError):
self.get_config_client().set_configuration_setting(read_only_kv)
readable_kv = self.get_config_client().clear_read_only(read_only_kv)
readable_kv = self.get_config_client().set_read_only(read_only_kv, False)
readable_kv.value = to_set_kv.value
readable_kv.tags = to_set_kv.tags
set_kv = self.get_config_client().set_configuration_setting(readable_kv)
Expand Down