diff --git a/sdk/appconfiguration/azure-appconfiguration/HISTORY.md b/sdk/appconfiguration/azure-appconfiguration/HISTORY.md index dcee42dec0cd..f1e3fdcd3ced 100644 --- a/sdk/appconfiguration/azure-appconfiguration/HISTORY.md +++ b/sdk/appconfiguration/azure-appconfiguration/HISTORY.md @@ -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 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 3f3e6067ae89..a09eb5041888 100644 --- a/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/_azure_appconfiguration_client.py +++ b/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/_azure_appconfiguration_client.py @@ -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` @@ -492,6 +494,7 @@ 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, @@ -499,52 +502,20 @@ def set_read_only( } 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) 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 ddc530bbed41..2d06ae4d9d2e 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 @@ -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` @@ -508,6 +510,7 @@ 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, @@ -515,52 +518,20 @@ async def set_read_only( } 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) diff --git a/sdk/appconfiguration/azure-appconfiguration/samples/README.md b/sdk/appconfiguration/azure-appconfiguration/samples/README.md index 1bf54e61b328..86d549dc16e4 100644 --- a/sdk/appconfiguration/azure-appconfiguration/samples/README.md +++ b/sdk/appconfiguration/azure-appconfiguration/samples/README.md @@ -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 | diff --git a/sdk/appconfiguration/azure-appconfiguration/samples/read_only_async_sample.py b/sdk/appconfiguration/azure-appconfiguration/samples/read_only_async_sample.py index 490a0977001c..58b7d4e8fcaa 100644 --- a/sdk/appconfiguration/azure-appconfiguration/samples/read_only_async_sample.py +++ b/sdk/appconfiguration/azure-appconfiguration/samples/read_only_async_sample.py @@ -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 """ @@ -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("") diff --git a/sdk/appconfiguration/azure-appconfiguration/samples/read_only_sample.py b/sdk/appconfiguration/azure-appconfiguration/samples/read_only_sample.py index bb851b182eca..7b73192f5508 100644 --- a/sdk/appconfiguration/azure-appconfiguration/samples/read_only_sample.py +++ b/sdk/appconfiguration/azure-appconfiguration/samples/read_only_sample.py @@ -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 """ @@ -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("") diff --git a/sdk/appconfiguration/azure-appconfiguration/tests/app_config_asynctests/async_proxy.py b/sdk/appconfiguration/azure-appconfiguration/tests/app_config_asynctests/async_proxy.py index e42f8468c153..f8f2ad5611f4 100644 --- a/sdk/appconfiguration/azure-appconfiguration/tests/app_config_asynctests/async_proxy.py +++ b/sdk/appconfiguration/azure-appconfiguration/tests/app_config_asynctests/async_proxy.py @@ -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) ) diff --git a/sdk/appconfiguration/azure-appconfiguration/tests/app_config_asynctests/test_azure_configuration_client_async.py b/sdk/appconfiguration/azure-appconfiguration/tests/app_config_asynctests/test_azure_configuration_client_async.py index 9b418c679e24..29e03c1f0f0a 100644 --- a/sdk/appconfiguration/azure-appconfiguration/tests/app_config_asynctests/test_azure_configuration_client_async.py +++ b/sdk/appconfiguration/azure-appconfiguration/tests/app_config_asynctests/test_azure_configuration_client_async.py @@ -348,7 +348,7 @@ 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): @@ -356,7 +356,7 @@ def test_delete_read_only(self): 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): @@ -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) diff --git a/sdk/appconfiguration/azure-appconfiguration/tests/test_azure_configuration_client.py b/sdk/appconfiguration/azure-appconfiguration/tests/test_azure_configuration_client.py index bf7c62b331e3..a541172f2038 100644 --- a/sdk/appconfiguration/azure-appconfiguration/tests/test_azure_configuration_client.py +++ b/sdk/appconfiguration/azure-appconfiguration/tests/test_azure_configuration_client.py @@ -347,7 +347,7 @@ 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): @@ -355,7 +355,7 @@ def test_delete_read_only(self): 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): @@ -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)