async def main(): CONNECTION_STRING = get_connection_string() # Create app config client client = AzureAppConfigurationClient.from_connection_string( CONNECTION_STRING) print("Set new configuration setting") config_setting = ConfigurationSetting(key="MyKey", value="my value", content_type="my content type", tags={"my tag": "my tag value"}) returned_config_setting = await client.set_configuration_setting( config_setting) print("New configuration setting:") print_configuration_setting(returned_config_setting) print("") print("Get configuration setting") fetched_config_setting = await client.get_configuration_setting(key="MyKey" ) print("Fetched configuration setting:") print_configuration_setting(fetched_config_setting) print("") print("Delete configuration setting") await client.delete_configuration_setting(key="MyKey")
def main(): CONNECTION_STRING = get_connection_string() # Create app config client client = AzureAppConfigurationClient.from_connection_string( CONNECTION_STRING) print("Add new configuration setting") config_setting = ConfigurationSetting(key="MyKey", label="MyLabel", value="my value", content_type="my content type", tags={"my tag": "my tag value"}) added_config_setting = client.add_configuration_setting(config_setting) print("New configuration setting:") print_configuration_setting(added_config_setting) print("") print("Set configuration setting") added_config_setting.value = "new value" added_config_setting.content_type = "new content type" updated_config_setting = client.set_configuration_setting(config_setting) print_configuration_setting(updated_config_setting) print("") print("List configuration settings") config_settings = client.list_configuration_settings(labels=["MyLabel"]) for item in config_settings: print_configuration_setting(item) print("Delete configuration setting") client.delete_configuration_setting( key="MyKey", label="MyLabel", )
async def main(): CONNECTION_STRING = get_connection_string() # Create app config client client = AzureAppConfigurationClient.from_connection_string(CONNECTION_STRING) config_setting = ConfigurationSetting( key="MyKey", value="my value", content_type="my content type", tags={"my tag": "my tag value"} ) returned_config_setting = await client.set_configuration_setting(config_setting) returned_config_setting.value = "new value" returned_config_setting.content_type = "new content type" await client.set_configuration_setting(config_setting) items = client.list_revisions(key_filter="MyKey") async for item in items: print_configuration_setting(item) print("") await client.delete_configuration_setting( key="MyKey", )
def main(): CONNECTION_STRING = get_connection_string() # Create app config client client = AzureAppConfigurationClient.from_connection_string( CONNECTION_STRING) print("Set new configuration setting") config_setting = ConfigurationSetting(key="MyKey", value="my value", content_type="my content type", tags={"my tag": "my tag value"}) returned_config_setting = client.set_configuration_setting(config_setting) print("New configuration setting:") print_configuration_setting(returned_config_setting) print("") print("Read only configuration setting:") read_only_config_setting = client.set_read_only(returned_config_setting) print_configuration_setting(read_only_config_setting) print("") print("Clear read only configuration setting:") read_write_config_setting = client.clear_read_only(returned_config_setting) print_configuration_setting(read_write_config_setting) print("") print("Delete configuration setting") client.delete_configuration_setting(key="MyKey", )
def handle_event_grid_notifications(event_grid_events): # type: (List[dict[str, Any]]) -> None CONNECTION_STRING = get_connection_string() all_keys = [] with AzureAppConfigurationClient.from_connection_string(CONNECTION_STRING) as client: for event_grid_event in event_grid_events: if event_grid_event["eventType"] == 'Microsoft.KeyValueModified': sync_token = event['data']['syncToken'] client.update_sync_token(sync_token) new_key = client.get_configuration_setting(key=event['data']['key'], label=event['data']['label']) all_keys.append(new_key)
def main(): CONNECTION_STRING = get_connection_string() # Create app config client client = AzureAppConfigurationClient.from_connection_string( CONNECTION_STRING) # Unconditional set config_setting = ConfigurationSetting(key="MyKey", value="my value", content_type="my content type", tags={"my tag": "my tag value"}) client.set_configuration_setting(config_setting) # Unconditional get first_get = client.get_configuration_setting(key="MyKey") print_configuration_setting(first_get) # Conditional get, expect to return None because it is not modified second_get = client.get_configuration_setting( key="MyKey", etag=first_get.etag, match_condition=MatchConditions.IfModified) print_configuration_setting(second_get) # Conditional set first_get.value = "new value" client.set_configuration_setting( configuration_setting=first_get, match_condition=MatchConditions.IfNotModified) # Conditional set, expect to see error because it is modified try: client.set_configuration_setting( configuration_setting=first_get, match_condition=MatchConditions.IfNotModified) except ResourceModifiedError: pass client.delete_configuration_setting(key="MyKey")