Class ConfigurationClient
This class provides a client that contains all the operations for ConfigurationSettings,
FeatureFlagConfigurationSetting or
SecretReferenceConfigurationSetting in Azure App Configuration Store.
Operations allowed by the client are adding, retrieving, deleting, set read-only status ConfigurationSettings, and
listing settings or revision of a setting based on a filter.
Additionally, this class allows to add an external synchronization token to ensure service requests receive
up-to-date values. Use the updateSyncToken method.
Getting Started
In order to interact with the App Configuration service you'll need to create an instance of the
ConfigurationClient class. To make this possible you'll need the connection
string of the configuration store. Alternatively, you can use AAD authentication via
Azure Identity
to connect to the service.
- Connection string, see
connectionString. - Azure Active Directory, see
TokenCredential.
Instantiating a synchronous Configuration Client
ConfigurationClient configurationClient = new ConfigurationClientBuilder()
.connectionString(connectionString)
.buildClient();
View this for additional ways to construct the client.
App Configuration support multiple operations, such as create, update, retrieve, and delete a configuration setting. See methods in client level class below to explore all capabilities that library provides.
For more configuration setting types, see
FeatureFlagConfigurationSetting and
SecretReferenceConfigurationSetting.
Add Configuration Setting
The addConfigurationSetting(ConfigurationSetting)
method can be used to add a configuration setting in the Azure App Configuration.
The sample below shows how to add a setting with the key "prodDBConnection", label "westUS" and value
"db_connection" using ConfigurationClient.
ConfigurationSetting setting = configurationClient.addConfigurationSetting(new ConfigurationSetting()
.setKey("prodDBConnection")
.setLabel("westUS")
.setValue("db_connection"));
System.out.printf("Key: %s, Label: %s, Value: %s", setting.getKey(), setting.getLabel(), setting.getValue());
Note: For asynchronous sample, refer to ConfigurationAsyncClient.
Update Configuration Setting
The setConfigurationSetting(ConfigurationSetting)
method can be used to update a configuration setting in the Azure App Configuration.
The sample below shows how to update setting's value "db_connection" to "updated_db_connection"
ConfigurationSetting setting = configurationClient.setConfigurationSetting(new ConfigurationSetting()
.setKey("prodDBConnection")
.setLabel("westUS")
.setValue("db_connection"));
System.out.printf("Key: %s, Label: %s, Value: %s", setting.getKey(), setting.getLabel(), setting.getValue());
// Update the value of the setting to "updated_db_connection".
setting = configurationClient.setConfigurationSetting(new ConfigurationSetting()
.setKey("prodDBConnection")
.setLabel("westUS")
.setValue("updated_db_connection"));
System.out.printf("Key: %s, Label: %s, Value: %s", setting.getKey(), setting.getLabel(), setting.getValue());
Note: For asynchronous sample, refer to ConfigurationAsyncClient.
Get Configuration Setting
The getConfigurationSetting(ConfigurationSetting)
method can be used to get a configuration setting in the Azure App Configuration.
The sample below shows how to retrieve the setting with the key "prodDBConnection".
ConfigurationSetting setting = configurationClient.getConfigurationSetting(new ConfigurationSetting()
.setKey("prodDBConnection")
.setLabel("westUS"));
System.out.printf("Key: %s, Value: %s", setting.getKey(), setting.getValue());
Note: For asynchronous sample, refer to ConfigurationAsyncClient.
Delete Configuration Setting
The deleteConfigurationSetting(ConfigurationSetting)
method can be used to delete a configuration setting in the Azure App Configuration.
The sample below shows how to delete the setting with the key "prodDBConnection".
ConfigurationSetting setting = configurationClient.deleteConfigurationSetting(new ConfigurationSetting()
.setKey("prodDBConnection")
.setLabel("westUS"));
System.out.printf("Key: %s, Value: %s", setting.getKey(), setting.getValue());
Note: For asynchronous sample, refer to ConfigurationAsyncClient.
Set the Configuration Setting to read-only
The setReadOnly(ConfigurationSetting, boolean)
method can be used to conditionally set a configuration setting to read-only in the Azure App Configuration.
The sample below shows how to conditionally set the setting to read-only with the key "prodDBConnection".
ConfigurationSetting setting = configurationClient.setReadOnly(new ConfigurationSetting()
.setKey("prodDBConnection")
.setLabel("westUS"),
true);
System.out.printf("Key: %s, Value: %s", setting.getKey(), setting.getValue());
Note: For asynchronous sample, refer to ConfigurationAsyncClient.
Clear read-only of the Configuration Setting
The setReadOnly(ConfigurationSetting, boolean)
method can be used to conditionally clear read-only of the setting in the Azure App Configuration.
The sample below shows how to conditionally clear read-only of the setting with the key "prodDBConnection".
ConfigurationSetting setting = configurationClient.setReadOnly(new ConfigurationSetting()
.setKey("prodDBConnection")
.setLabel("westUS"),
false);
System.out.printf("Key: %s, Value: %s", setting.getKey(), setting.getValue());
Note: For asynchronous sample, refer to ConfigurationAsyncClient.
List Configuration Settings
The listConfigurationSettings(SettingSelector)
method can be used to list configuration settings in the Azure App Configuration.
The sample below shows how to list all settings that use the key "prodDBConnection".
SettingSelector settingSelector = new SettingSelector().setKeyFilter("prodDBConnection");
configurationClient.listConfigurationSettings(settingSelector).forEach(setting -> {
System.out.printf("Key: %s, Value: %s", setting.getKey(), setting.getValue());
});
Note: For asynchronous sample, refer to ConfigurationAsyncClient.
List revisions of a Configuration Setting
The listRevisions(SettingSelector)
method can be used to list all revisions of a configuration setting in the Azure App Configuration.
The sample below shows how to list all revision of a setting that use the key "prodDBConnection".
SettingSelector settingSelector = new SettingSelector().setKeyFilter("prodDBConnection");
configurationClient.listRevisions(settingSelector).streamByPage().forEach(resp -> {
System.out.printf("Response headers are %s. Url %s and status code %d %n", resp.getHeaders(),
resp.getRequest().getUrl(), resp.getStatusCode());
resp.getItems().forEach(value -> {
System.out.printf("Response value is %d %n", value);
});
});
Note: For asynchronous sample, refer to ConfigurationAsyncClient.
-
Method Summary
Modifier and TypeMethodDescriptionAdds a configuration value in the service if that key and label does not exist.addConfigurationSetting(String key, String label, String value) Adds a configuration value in the service if that key does not exist.com.azure.core.http.rest.Response<ConfigurationSetting>addConfigurationSettingWithResponse(ConfigurationSetting setting, com.azure.core.util.Context context) Adds a configuration value in the service if that key and label does not exist.archiveSnapshot(String snapshotName) Update a snapshot status fromConfigurationSnapshotStatus.READYtoConfigurationSnapshotStatus.ARCHIVED.com.azure.core.http.rest.Response<ConfigurationSnapshot>archiveSnapshotWithResponse(String snapshotName, com.azure.core.http.MatchConditions matchConditions, com.azure.core.util.Context context) Update a snapshot status fromConfigurationSnapshotStatus.READYtoConfigurationSnapshotStatus.ARCHIVED.com.azure.core.util.polling.SyncPoller<com.azure.core.util.polling.PollOperationDetails,ConfigurationSnapshot> beginCreateSnapshot(String snapshotName, ConfigurationSnapshot snapshot, com.azure.core.util.Context context) Create aConfigurationSnapshotby providing a snapshot name and aConfigurationSnapshot.Deletes theConfigurationSettingwith a matchingkey, and optionallabeland optional ETag combination.deleteConfigurationSetting(String key, String label) com.azure.core.http.rest.Response<ConfigurationSetting>deleteConfigurationSettingWithResponse(ConfigurationSetting setting, boolean ifUnchanged, com.azure.core.util.Context context) Deletes theConfigurationSettingwith a matchingkey, and optionallabeland optional ETag combination.getConfigurationSetting(String key, String label) Attempts to get a ConfigurationSetting that matches thekey, and the optionallabelcombination.getConfigurationSetting(String key, String label, OffsetDateTime acceptDateTime) Attempts to get a ConfigurationSetting that matches thekey, the optionallabel, and the optionalacceptDateTimecombination.com.azure.core.http.rest.Response<ConfigurationSetting>getConfigurationSettingWithResponse(ConfigurationSetting setting, OffsetDateTime acceptDateTime, boolean ifChanged, com.azure.core.util.Context context) Gets the service endpoint for the Azure App Configuration instance.getSnapshot(String snapshotName) Get aConfigurationSnapshotby given the snapshot name.com.azure.core.http.rest.Response<ConfigurationSnapshot>getSnapshotWithResponse(String snapshotName, List<SnapshotFields> fields, com.azure.core.util.Context context) Get aConfigurationSnapshotby given the snapshot name.com.azure.core.http.rest.PagedIterable<ConfigurationSetting>listConfigurationSettings(SettingSelector selector) Fetches the configuration settings that match theselector.com.azure.core.http.rest.PagedIterable<ConfigurationSetting>listConfigurationSettings(SettingSelector selector, com.azure.core.util.Context context) Fetches the configuration settings that match theselector.com.azure.core.http.rest.PagedIterable<ConfigurationSetting>listConfigurationSettingsForSnapshot(String snapshotName) Fetches the configuration settings in a snapshot that matches thesnapshotName.com.azure.core.http.rest.PagedIterable<ConfigurationSetting>listConfigurationSettingsForSnapshot(String snapshotName, List<SettingFields> fields, com.azure.core.util.Context context) Fetches the configuration settings in a snapshot that matches thesnapshotName.com.azure.core.http.rest.PagedIterable<ConfigurationSetting>listRevisions(SettingSelector selector) Lists chronological/historical representation ofConfigurationSettingresource(s).com.azure.core.http.rest.PagedIterable<ConfigurationSetting>listRevisions(SettingSelector selector, com.azure.core.util.Context context) Lists chronological/historical representation ofConfigurationSettingresource(s).com.azure.core.http.rest.PagedIterable<ConfigurationSnapshot>listSnapshots(SnapshotSelector selector) List snapshots by givenSnapshotSelector.com.azure.core.http.rest.PagedIterable<ConfigurationSnapshot>listSnapshots(SnapshotSelector selector, com.azure.core.util.Context context) List snapshots by givenSnapshotSelector.recoverSnapshot(String snapshotName) Update a snapshot status fromConfigurationSnapshotStatus.ARCHIVEDtoConfigurationSnapshotStatus.READY.com.azure.core.http.rest.Response<ConfigurationSnapshot>recoverSnapshotWithResponse(String snapshotName, com.azure.core.http.MatchConditions matchConditions, com.azure.core.util.Context context) Update a snapshot status fromConfigurationSnapshotStatus.ARCHIVEDtoConfigurationSnapshotStatus.READY.Creates or updates a configuration value in the service.setConfigurationSetting(String key, String label, String value) Creates or updates a configuration value in the service with the given key and.com.azure.core.http.rest.Response<ConfigurationSetting>setConfigurationSettingWithResponse(ConfigurationSetting setting, boolean ifUnchanged, com.azure.core.util.Context context) Creates or updates a configuration value in the service.setReadOnly(ConfigurationSetting setting, boolean isReadOnly) Sets the read-only status for theConfigurationSetting.setReadOnly(String key, String label, boolean isReadOnly) com.azure.core.http.rest.Response<ConfigurationSetting>setReadOnlyWithResponse(ConfigurationSetting setting, boolean isReadOnly, com.azure.core.util.Context context) Sets the read-only status for theConfigurationSetting.voidupdateSyncToken(String token) Adds an external synchronization token to ensure service requests receive up-to-date values.
-
Method Details
-
getEndpoint
Gets the service endpoint for the Azure App Configuration instance.- Returns:
- the service endpoint for the Azure App Configuration instance.
-
addConfigurationSetting
Adds a configuration value in the service if that key does not exist. Thelabelis optional.Code Samples
Add a setting with the key "prodDBConnection", label "westUS" and value "db_connection".
ConfigurationSetting result = configurationClient .addConfigurationSetting("prodDBConnection", "westUS", "db_connection"); System.out.printf("Key: %s, Label: %s, Value: %s", result.getKey(), result.getLabel(), result.getValue());- Parameters:
key- The key of the configuration setting to add.label- The label of the configuration setting to create. Ifnullno label will be used.value- The value associated with this configuration setting key.- Returns:
- The
ConfigurationSettingthat was created, ornullif a key collision occurs or the key is an invalid value (which will also throw ServiceRequestException described below). - Throws:
IllegalArgumentException- Ifkeyisnull.com.azure.core.exception.ResourceModifiedException- If a ConfigurationSetting with the same key exists.com.azure.core.exception.HttpResponseException- Ifkeyis an empty string.
-
addConfigurationSetting
Adds a configuration value in the service if that key and label does not exist. The label value of the ConfigurationSetting is optional. For more configuration setting types, seeFeatureFlagConfigurationSettingandSecretReferenceConfigurationSetting.Code Samples
Add a setting with the key "prodDBConnection", label "westUS" and value "db_connection".
ConfigurationSetting setting = configurationClient.addConfigurationSetting(new ConfigurationSetting() .setKey("prodDBConnection") .setLabel("westUS") .setValue("db_connection")); System.out.printf("Key: %s, Label: %s, Value: %s", setting.getKey(), setting.getLabel(), setting.getValue());- Parameters:
setting- The setting to add based on its key and optional label combination.- Returns:
- The
ConfigurationSettingthat was created, ornullif a key collision occurs or the key is an invalid value (which will also throw ServiceRequestException described below). - Throws:
NullPointerException- Ifsettingisnull.IllegalArgumentException- Ifkeyisnull.com.azure.core.exception.ResourceModifiedException- If a ConfigurationSetting with the same key and label exists.com.azure.core.exception.HttpResponseException- Ifkeyis an empty string.
-
addConfigurationSettingWithResponse
public com.azure.core.http.rest.Response<ConfigurationSetting> addConfigurationSettingWithResponse(ConfigurationSetting setting, com.azure.core.util.Context context) Adds a configuration value in the service if that key and label does not exist. The label value of the ConfigurationSetting is optional. For more configuration setting types, seeFeatureFlagConfigurationSettingandSecretReferenceConfigurationSetting.Code Samples
Add a setting with the key "prodDBConnection", label "westUS", and value "db_connection".
Response<ConfigurationSetting> responseResultSetting = configurationClient .addConfigurationSettingWithResponse(new ConfigurationSetting() .setKey("prodDBConnection") .setLabel("westUS") .setValue("db_connection"), new Context(key1, value1)); ConfigurationSetting resultSetting = responseResultSetting.getValue(); System.out.printf("Key: %s, Label: %s, Value: %s", resultSetting.getKey(), resultSetting.getLabel(), resultSetting.getValue());- Parameters:
setting- The setting to add based on its key and optional label combination.context- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A REST response containing the the
ConfigurationSettingthat was created, ornull, if a key collision occurs or the key is an invalid value (which will also throw ServiceRequestException described below). - Throws:
NullPointerException- Ifsettingisnull.IllegalArgumentException- Ifkeyisnull.com.azure.core.exception.ResourceModifiedException- If a ConfigurationSetting with the same key and label exists.com.azure.core.exception.HttpResponseException- Ifkeyis an empty string.
-
setConfigurationSetting
Creates or updates a configuration value in the service with the given key and. thelabelis optional.Code Samples
Add a setting with the key "prodDBConnection", "westUS" and value "db_connection".
Update setting's value "db_connection" to "updated_db_connection"
ConfigurationSetting result = configurationClient .setConfigurationSetting("prodDBConnection", "westUS", "db_connection"); System.out.printf("Key: %s, Label: %s, Value: %s", result.getKey(), result.getLabel(), result.getValue()); // Update the value of the setting to "updated_db_connection". result = configurationClient.setConfigurationSetting("prodDBConnection", "westUS", "updated_db_connection"); System.out.printf("Key: %s, Label: %s, Value: %s", result.getKey(), result.getLabel(), result.getValue());- Parameters:
key- The key of the configuration setting to create or update.label- The label of the configuration setting to create or update. Ifnullno label will be used.value- The value of this configuration setting.- Returns:
- The
ConfigurationSettingthat was created or updated, ornullif the key is an invalid value (which will also throw ServiceRequestException described below). - Throws:
IllegalArgumentException- Ifkeyisnull.com.azure.core.exception.ResourceModifiedException- If the setting exists and is read-only.com.azure.core.exception.HttpResponseException- Ifkeyis an empty string.
-
setConfigurationSetting
Creates or updates a configuration value in the service. Partial updates are not supported and the entire configuration setting is updated. For more configuration setting types, seeFeatureFlagConfigurationSettingandSecretReferenceConfigurationSetting.Code Samples
Add a setting with the key "prodDBConnection" and value "db_connection".
Update setting's value "db_connection" to "updated_db_connection"
ConfigurationSetting setting = configurationClient.setConfigurationSetting(new ConfigurationSetting() .setKey("prodDBConnection") .setLabel("westUS") .setValue("db_connection")); System.out.printf("Key: %s, Label: %s, Value: %s", setting.getKey(), setting.getLabel(), setting.getValue()); // Update the value of the setting to "updated_db_connection". setting = configurationClient.setConfigurationSetting(new ConfigurationSetting() .setKey("prodDBConnection") .setLabel("westUS") .setValue("updated_db_connection")); System.out.printf("Key: %s, Label: %s, Value: %s", setting.getKey(), setting.getLabel(), setting.getValue());- Parameters:
setting- The setting to create or update based on its key, optional label and optional ETag combination.- Returns:
- The
ConfigurationSettingthat was created or updated, ornullif the key is an invalid value (which will also throw ServiceRequestException described below). - Throws:
NullPointerException- Ifsettingisnull.IllegalArgumentException- Ifkeyisnull.com.azure.core.exception.ResourceModifiedException- If theETagwas specified, is not the wildcard character, and the current configuration value's ETag does not match, or the setting exists and is read-only.com.azure.core.exception.HttpResponseException- Ifkeyis an empty string.
-
setConfigurationSettingWithResponse
public com.azure.core.http.rest.Response<ConfigurationSetting> setConfigurationSettingWithResponse(ConfigurationSetting setting, boolean ifUnchanged, com.azure.core.util.Context context) Creates or updates a configuration value in the service. Partial updates are not supported and the entire configuration setting is updated. For more configuration setting types, seeFeatureFlagConfigurationSettingandSecretReferenceConfigurationSetting. IfETagis specified, the configuration value is updated if the current setting's ETag matches. If the ETag's value is equal to the wildcard character ("*"), the setting will always be updated.Code Samples
Add a setting with the key "prodDBConnection" and value "db_connection".
Update setting's value "db_connection" to "updated_db_connection"
// Add a setting with the key "prodDBConnection", label "westUS", and value "db_connection" Response<ConfigurationSetting> responseSetting = configurationClient.setConfigurationSettingWithResponse( new ConfigurationSetting() .setKey("prodDBConnection") .setLabel("westUS") .setValue("db_connection"), false, new Context(key2, value2)); ConfigurationSetting initSetting = responseSetting.getValue(); System.out.printf("Key: %s, Value: %s", initSetting.getKey(), initSetting.getValue()); // Update the value of the setting to "updated_db_connection". responseSetting = configurationClient.setConfigurationSettingWithResponse(new ConfigurationSetting() .setKey("prodDBConnection") .setLabel("westUS") .setValue("updated_db_connection"), false, new Context(key2, value2)); ConfigurationSetting updatedSetting = responseSetting.getValue(); System.out.printf("Key: %s, Value: %s", updatedSetting.getKey(), updatedSetting.getValue());- Parameters:
setting- The setting to create or update based on its key, optional label and optional ETag combination.ifUnchanged- A boolean indicates ifsettingETagis used as an IF-MATCH header.context- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A REST response contains the
ConfigurationSettingthat was created or updated, ornull, if the configuration value does not exist or the key is an invalid value (which will also throw ServiceRequestException described below). - Throws:
NullPointerException- Ifsettingisnull.IllegalArgumentException- Ifkeyisnull.com.azure.core.exception.ResourceModifiedException- If theETagwas specified, is not the wildcard character, and the current configuration value's ETag does not match, or the setting exists and is read-only.com.azure.core.exception.HttpResponseException- Ifkeyis an empty string.
-
getConfigurationSetting
Attempts to get a ConfigurationSetting that matches thekey, and the optionallabelcombination.Code Samples
Retrieve the setting with the key "prodDBConnection".
ConfigurationSetting resultNoDateTime = configurationClient.getConfigurationSetting("prodDBConnection", "westUS"); System.out.printf("Key: %s, Value: %s", resultNoDateTime.getKey(), resultNoDateTime.getValue());- Parameters:
key- The key of the setting to retrieve.label- The label of the configuration setting to retrieve. Ifnullno label will be used.- Returns:
- The
ConfigurationSettingstored in the service, ornull, if the configuration value does not exist or the key is an invalid value (which will also throw ServiceRequestException described below). - Throws:
IllegalArgumentException- Ifkeyisnull.com.azure.core.exception.ResourceNotFoundException- If a ConfigurationSetting withkeydoes not exist.com.azure.core.exception.HttpResponseException- Ifkeyis an empty string.
-
getConfigurationSetting
public ConfigurationSetting getConfigurationSetting(String key, String label, OffsetDateTime acceptDateTime) Attempts to get a ConfigurationSetting that matches thekey, the optionallabel, and the optionalacceptDateTimecombination.Code Samples
Retrieve the setting with the key "prodDBConnection".
ConfigurationSetting result = configurationClient.getConfigurationSetting("prodDBConnection", "westUS", null); System.out.printf("Key: %s, Value: %s", result.getKey(), result.getValue());- Parameters:
key- The key of the setting to retrieve.label- The label of the configuration setting to create or update. Ifnullno label will be used.acceptDateTime- Datetime to access a past state of the configuration setting. Ifnullthen the current state of the configuration setting will be returned.- Returns:
- The
ConfigurationSettingstored in the service, ornull, if the configuration value does not exist or the key is an invalid value (which will also throw ServiceRequestException described below). - Throws:
IllegalArgumentException- Ifkeyisnull.com.azure.core.exception.ResourceNotFoundException- If a ConfigurationSetting withkeydoes not exist.com.azure.core.exception.HttpResponseException- Ifkeyis an empty string.
-
getConfigurationSetting
Attempts to get the ConfigurationSetting with a matchingkey, and optionallabel, optionalacceptDateTimeand optional ETag combination. For more configuration setting types, seeFeatureFlagConfigurationSettingandSecretReferenceConfigurationSetting.Code Samples
Retrieve the setting with the key "prodDBConnection".
ConfigurationSetting setting = configurationClient.getConfigurationSetting(new ConfigurationSetting() .setKey("prodDBConnection") .setLabel("westUS")); System.out.printf("Key: %s, Value: %s", setting.getKey(), setting.getValue());- Parameters:
setting- The setting to retrieve.- Returns:
- The
ConfigurationSettingstored in the service, ornull, if the configuration value does not exist or the key is an invalid value (which will also throw ServiceRequestException described below). - Throws:
NullPointerException- Ifsettingisnull.IllegalArgumentException- Ifkeyisnull.com.azure.core.exception.ResourceNotFoundException- If a ConfigurationSetting with the same key and label does not exist.com.azure.core.exception.HttpResponseException- If thekeyis an empty string.
-
getConfigurationSettingWithResponse
public com.azure.core.http.rest.Response<ConfigurationSetting> getConfigurationSettingWithResponse(ConfigurationSetting setting, OffsetDateTime acceptDateTime, boolean ifChanged, com.azure.core.util.Context context) Attempts to get the ConfigurationSetting with a matchingkey, and optionallabel, optionalacceptDateTimeand optional ETag combination. For more configuration setting types, seeFeatureFlagConfigurationSettingandSecretReferenceConfigurationSetting.Code Samples
Retrieve the setting with the key "prodDBConnection".
// Retrieve the setting with the key-label "prodDBConnection"-"westUS". Response<ConfigurationSetting> responseResultSetting = configurationClient.getConfigurationSettingWithResponse( new ConfigurationSetting() .setKey("prodDBConnection") .setLabel("westUS"), null, false, new Context(key1, value1)); System.out.printf("Key: %s, Value: %s", responseResultSetting.getValue().getKey(), responseResultSetting.getValue().getValue());- Parameters:
setting- The setting to retrieve.acceptDateTime- Datetime to access a past state of the configuration setting. Ifnullthen the current state of the configuration setting will be returned.ifChanged- Flag indicating if thesettingETagis used as an If-None-Match header.context- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A REST response contains the
ConfigurationSettingstored in the service, ornull, if the configuration value does not exist or the key is an invalid value (which will also throw ServiceRequestException described below). - Throws:
NullPointerException- Ifsettingisnull.IllegalArgumentException- Ifkeyisnull.com.azure.core.exception.ResourceNotFoundException- If a ConfigurationSetting with the same key and label does not exist.com.azure.core.exception.HttpResponseException- If thekeyis an empty string.
-
deleteConfigurationSetting
Deletes theConfigurationSettingwith a matchingkeyand optionallabelcombination.Code Samples
Delete the setting with the key "prodDBConnection".
ConfigurationSetting result = configurationClient.deleteConfigurationSetting("prodDBConnection", "westUS"); System.out.printf("Key: %s, Value: %s", result.getKey(), result.getValue());- Parameters:
key- The key of configuration setting to delete.label- The label of configuration setting to delete. Ifnullno label will be used.- Returns:
- The deleted ConfigurationSetting or
nullif it didn't exist.nullis also returned if thekeyis an invalid value (which will also throw ServiceRequestException described below). - Throws:
IllegalArgumentException- Ifkeyisnull.com.azure.core.exception.ResourceModifiedException- Ifsettingis read-only.com.azure.core.exception.HttpResponseException- Ifkeyis an empty string.
-
deleteConfigurationSetting
Deletes theConfigurationSettingwith a matchingkey, and optionallabeland optional ETag combination. For more configuration setting types, seeFeatureFlagConfigurationSettingandSecretReferenceConfigurationSetting.Code Samples
Delete the setting with the key "prodDBConnection".
ConfigurationSetting setting = configurationClient.deleteConfigurationSetting(new ConfigurationSetting() .setKey("prodDBConnection") .setLabel("westUS")); System.out.printf("Key: %s, Value: %s", setting.getKey(), setting.getValue());- Parameters:
setting- The setting to delete based on its key, optional label and optional ETag combination.- Returns:
- The deleted ConfigurationSetting or
nullif it didn't exist.nullis also returned if thekeyis an invalid value (which will also throw ServiceRequestException described below). - Throws:
IllegalArgumentException- Ifkeyisnull.NullPointerException- Whensettingisnull.com.azure.core.exception.ResourceModifiedException- Ifsettingis read-only.com.azure.core.exception.ResourceNotFoundException- IfETagis specified, not the wildcard character, and does not match the current ETag value.com.azure.core.exception.HttpResponseException- Ifkeyis an empty string.
-
deleteConfigurationSettingWithResponse
public com.azure.core.http.rest.Response<ConfigurationSetting> deleteConfigurationSettingWithResponse(ConfigurationSetting setting, boolean ifUnchanged, com.azure.core.util.Context context) Deletes theConfigurationSettingwith a matchingkey, and optionallabeland optional ETag combination. For more configuration setting types, seeFeatureFlagConfigurationSettingandSecretReferenceConfigurationSetting. IfETagis specified and is not the wildcard character ("*"), then the setting is only deleted if the ETag matches the current ETag; this means that no one has updated the ConfigurationSetting yet.Code Samples
Delete the setting with the key "prodDBConnection".
Response<ConfigurationSetting> responseSetting = configurationClient.deleteConfigurationSettingWithResponse( new ConfigurationSetting() .setKey("prodDBConnection") .setLabel("westUS"), false, new Context(key2, value2)); System.out.printf( "Key: %s, Value: %s", responseSetting.getValue().getKey(), responseSetting.getValue().getValue());- Parameters:
setting- The setting to delete based on its key, optional label and optional ETag combination.ifUnchanged- Flag indicating if thesettingETagis used as an IF-MATCH header.context- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A REST response containing the deleted ConfigurationSetting or
nullif didn't exist.nullis also returned if thekeyis an invalid value orETagis set but does not match the current ETag (which will also throw ServiceRequestException described below). - Throws:
IllegalArgumentException- Ifkeyisnull.NullPointerException- Whensettingisnull.com.azure.core.exception.ResourceModifiedException- Ifsettingis read-only.com.azure.core.exception.ResourceNotFoundException- IfETagis specified, not the wildcard character, and does not match the current ETag value.com.azure.core.exception.HttpResponseException- Ifkeyis an empty string.
-
setReadOnly
Sets the read-only status for theConfigurationSettingthat matches thekey, the optionallabel.Code Samples
Set the setting to read-only with the key-label "prodDBConnection"-"westUS".
ConfigurationSetting result = configurationClient.setReadOnly("prodDBConnection", "westUS", true); System.out.printf("Key: %s, Value: %s", result.getKey(), result.getValue());Clear read-only of the setting with the key-label "prodDBConnection"-"westUS".
ConfigurationSetting result = configurationClient.setReadOnly("prodDBConnection", "westUS", false); System.out.printf("Key: %s, Value: %s", result.getKey(), result.getValue());- Parameters:
key- The key of configuration setting to set to read-only or not read-only based on theisReadOnly.label- The label of configuration setting to set to read-only or not read-only based on theisReadOnlyvalue, or optionally. Ifnullno label will be used.isReadOnly- Flag used to set the read-only status of the configuration.truewill put the configuration into a read-only state,falsewill clear the state.- Returns:
- The
ConfigurationSettingthat is read-only, ornullis also returned if a key collision occurs or the key is an invalid value (which will also throw HttpResponseException described below). - Throws:
IllegalArgumentException- Ifkeyisnull.com.azure.core.exception.HttpResponseException- Ifkeyis an empty string.
-
setReadOnly
Sets the read-only status for theConfigurationSetting. For more configuration setting types, seeFeatureFlagConfigurationSettingandSecretReferenceConfigurationSetting.Code Samples
Set the setting to read-only with the key-label "prodDBConnection"-"westUS".
ConfigurationSetting setting = configurationClient.setReadOnly(new ConfigurationSetting() .setKey("prodDBConnection") .setLabel("westUS"), true); System.out.printf("Key: %s, Value: %s", setting.getKey(), setting.getValue());Clear read-only of the setting with the key-label "prodDBConnection"-"westUS".
ConfigurationSetting setting = configurationClient.setReadOnly(new ConfigurationSetting() .setKey("prodDBConnection") .setLabel("westUS"), false); System.out.printf("Key: %s, Value: %s", setting.getKey(), setting.getValue());- Parameters:
setting- The configuration setting to set to read-only or not read-only based on theisReadOnly.isReadOnly- Flag used to set the read-only status of the configuration.truewill put the configuration into a read-only state,falsewill clear the state.- Returns:
- The
ConfigurationSettingthat is read-only, ornullis also returned if a key collision occurs or the key is an invalid value (which will also throw HttpResponseException described below). - Throws:
IllegalArgumentException- Ifkeyisnull.com.azure.core.exception.HttpResponseException- Ifkeyis an empty string.
-
setReadOnlyWithResponse
public com.azure.core.http.rest.Response<ConfigurationSetting> setReadOnlyWithResponse(ConfigurationSetting setting, boolean isReadOnly, com.azure.core.util.Context context) Sets the read-only status for theConfigurationSetting. For more configuration setting types, seeFeatureFlagConfigurationSettingandSecretReferenceConfigurationSetting.Code Samples
Set the setting to read-only with the key-label "prodDBConnection"-"westUS".
ConfigurationSetting resultSetting = configurationClient.setReadOnlyWithResponse(new ConfigurationSetting() .setKey("prodDBConnection") .setLabel("westUS"), true, Context.NONE) .getValue(); System.out.printf("Key: %s, Value: %s", resultSetting.getKey(), resultSetting.getValue());Clear read-only of the setting with the key-label "prodDBConnection"-"westUS".
Response<ConfigurationSetting> responseSetting = configurationClient .setConfigurationSettingWithResponse( new ConfigurationSetting().setKey("prodDBConnection").setLabel("westUS"), false, new Context(key2, value2)); System.out.printf("Key: %s, Value: %s", responseSetting.getValue().getKey(), responseSetting.getValue().getValue());- Parameters:
setting- The configuration setting to set to read-only or not read-only based on theisReadOnly.isReadOnly- Flag used to set the read-only status of the configuration.truewill put the configuration into a read-only state,falsewill clear the state.context- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A REST response containing the read-only or not read-only ConfigurationSetting if
isReadOnlyis true or null, or false respectively. Or returnnullif the setting didn't exist.nullis also returned if thekeyis an invalid value. (which will also throw HttpResponseException described below). - Throws:
IllegalArgumentException- Ifkeyisnull.com.azure.core.exception.HttpResponseException- Ifkeyis an empty string.
-
listConfigurationSettings
public com.azure.core.http.rest.PagedIterable<ConfigurationSetting> listConfigurationSettings(SettingSelector selector) Fetches the configuration settings that match theselector. Ifselectorisnull, then all theconfiguration settingsare fetched with their current values.Code Samples
Retrieve all settings that use the key "prodDBConnection".
SettingSelector settingSelector = new SettingSelector().setKeyFilter("prodDBConnection"); configurationClient.listConfigurationSettings(settingSelector).forEach(setting -> { System.out.printf("Key: %s, Value: %s", setting.getKey(), setting.getValue()); });- Parameters:
selector- Optional. Selector to filter configuration setting results from the service.- Returns:
- A
PagedIterableof ConfigurationSettings that matches theselector. If no options were provided, the List contains all of the current settings in the service. - Throws:
com.azure.core.exception.HttpResponseException- If a client or service error occurs, such as a 404, 409, 429 or 500.
-
listConfigurationSettings
public com.azure.core.http.rest.PagedIterable<ConfigurationSetting> listConfigurationSettings(SettingSelector selector, com.azure.core.util.Context context) Fetches the configuration settings that match theselector. Ifselectorisnull, then all theconfiguration settingsare fetched with their current values.Code Samples
Retrieve all settings that use the key "prodDBConnection".
SettingSelector settingSelector = new SettingSelector().setKeyFilter("prodDBConnection"); Context ctx = new Context(key2, value2); configurationClient.listConfigurationSettings(settingSelector, ctx).forEach(setting -> { System.out.printf("Key: %s, Value: %s", setting.getKey(), setting.getValue()); });- Parameters:
selector- Optional. Selector to filter configuration setting results from the service.context- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A
PagedIterableof ConfigurationSettings that matches theselector. If no options were provided, thePagedIterablecontains all the current settings in the service. - Throws:
com.azure.core.exception.HttpResponseException- If a client or service error occurs, such as a 404, 409, 429 or 500.
-
listConfigurationSettingsForSnapshot
public com.azure.core.http.rest.PagedIterable<ConfigurationSetting> listConfigurationSettingsForSnapshot(String snapshotName) Fetches the configuration settings in a snapshot that matches thesnapshotName. IfsnapshotNameisnull, then all theconfiguration settingsare fetched with their current values.Code Samples
String snapshotName = "{snapshotName}"; configurationClient.listConfigurationSettingsForSnapshot(snapshotName).forEach(setting -> { System.out.printf("Key: %s, Value: %s", setting.getKey(), setting.getValue()); });- Parameters:
snapshotName- Optional. A filter used getConfigurationSettings for a snapshot. The value should be the name of the snapshot.- Returns:
- A
PagedIterableof ConfigurationSettings that matches theselector. If no options were provided, the List contains all of the current settings in the service. - Throws:
com.azure.core.exception.HttpResponseException- If a client or service error occurs, such as a 404, 409, 429 or 500.
-
listConfigurationSettingsForSnapshot
public com.azure.core.http.rest.PagedIterable<ConfigurationSetting> listConfigurationSettingsForSnapshot(String snapshotName, List<SettingFields> fields, com.azure.core.util.Context context) Fetches the configuration settings in a snapshot that matches thesnapshotName. IfsnapshotNameisnull, then all theconfiguration settingsare fetched with their current values.Code Samples
String snapshotName = "{snapshotName}"; List<SettingFields> fields = Arrays.asList(SettingFields.KEY); Context ctx = new Context(key2, value2); configurationClient.listConfigurationSettingsForSnapshot(snapshotName, fields, ctx) .forEach(setting -> System.out.printf("Key: %s, Value: %s", setting.getKey(), setting.getValue()));- Parameters:
snapshotName- Optional. A filter used getConfigurationSettings for a snapshot. The value should be the name of the snapshot.fields- Optional. The fields to select for the query response. If none are set, the service will return the ConfigurationSettings with a default set of properties.context- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A
PagedIterableof ConfigurationSettings that matches theselector. If no options were provided, thePagedIterablecontains all the current settings in the service. - Throws:
com.azure.core.exception.HttpResponseException- If a client or service error occurs, such as a 404, 409, 429 or 500.
-
listRevisions
public com.azure.core.http.rest.PagedIterable<ConfigurationSetting> listRevisions(SettingSelector selector) Lists chronological/historical representation ofConfigurationSettingresource(s). Revisions are provided in descending order from theirlastModifieddate. Revisions expire after a period of time, see Pricing for more information. Ifselectorisnull, then all theConfigurationSettingsare fetched in their current state. Otherwise, the results returned match the parameters given inselector.Code Samples
Retrieve all revisions of the setting that has the key "prodDBConnection".
SettingSelector settingSelector = new SettingSelector().setKeyFilter("prodDBConnection"); configurationClient.listRevisions(settingSelector).streamByPage().forEach(resp -> { System.out.printf("Response headers are %s. Url %s and status code %d %n", resp.getHeaders(), resp.getRequest().getUrl(), resp.getStatusCode()); resp.getItems().forEach(value -> { System.out.printf("Response value is %d %n", value); }); });- Parameters:
selector- Optional. Used to filter configuration setting revisions from the service.- Returns:
PagedIterableofConfigurationSettingrevisions.- Throws:
com.azure.core.exception.HttpResponseException- If a client or service error occurs, such as a 404, 409, 429 or 500.
-
listRevisions
public com.azure.core.http.rest.PagedIterable<ConfigurationSetting> listRevisions(SettingSelector selector, com.azure.core.util.Context context) Lists chronological/historical representation ofConfigurationSettingresource(s). Revisions are provided in descending order from theirlastModifieddate. Revisions expire after a period of time, see Pricing for more information. Ifselectorisnull, then all theConfigurationSettingsare fetched in their current state. Otherwise, the results returned match the parameters given inselector.Code Samples
Retrieve all revisions of the setting that has the key "prodDBConnection".
SettingSelector settingSelector = new SettingSelector().setKeyFilter("prodDBConnection"); Context ctx = new Context(key2, value2); configurationClient.listRevisions(settingSelector, ctx).forEach(setting -> { System.out.printf("Key: %s, Value: %s", setting.getKey(), setting.getValue()); });- Parameters:
selector- Optional. Used to filter configuration setting revisions from the service.context- Additional context that is passed through the Http pipeline during the service call.- Returns:
PagedIterableofConfigurationSettingrevisions.- Throws:
com.azure.core.exception.HttpResponseException- If a client or service error occurs, such as a 404, 409, 429 or 500.
-
beginCreateSnapshot
public com.azure.core.util.polling.SyncPoller<com.azure.core.util.polling.PollOperationDetails,ConfigurationSnapshot> beginCreateSnapshot(String snapshotName, ConfigurationSnapshot snapshot, com.azure.core.util.Context context) Create aConfigurationSnapshotby providing a snapshot name and aConfigurationSnapshot.Code Samples
List<ConfigurationSettingsFilter> filters = new ArrayList<>(); // Key Name also supports RegExp but only support prefix end with "*", such as "k*" and is case-sensitive. filters.add(new ConfigurationSettingsFilter("{keyName}")); String snapshotName = "{snapshotName}"; Context ctx = new Context(key2, value2); SyncPoller<PollOperationDetails, ConfigurationSnapshot> poller = client.beginCreateSnapshot(snapshotName, new ConfigurationSnapshot(filters).setRetentionPeriod(Duration.ofHours(1)), ctx); poller.setPollInterval(Duration.ofSeconds(10)); poller.waitForCompletion(); ConfigurationSnapshot snapshot = poller.getFinalResult(); System.out.printf("Snapshot name=%s is created at %s%n", snapshot.getName(), snapshot.getCreatedAt());- Parameters:
snapshotName- The name of theConfigurationSnapshotto create.snapshot- The snapshot to create.context- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A
SyncPollerthat polls the creating snapshot operation until it has completed or has failed. The completed operation returns aConfigurationSnapshot.
-
getSnapshot
Get aConfigurationSnapshotby given the snapshot name.Code Samples
String snapshotName = "{snapshotName}"; ConfigurationSnapshot getSnapshot = client.getSnapshot(snapshotName); System.out.printf("Snapshot name=%s is created at %s, snapshot status is %s.%n", getSnapshot.getName(), getSnapshot.getCreatedAt(), getSnapshot.getStatus());- Parameters:
snapshotName- the snapshot name.- Returns:
- A
ConfigurationSnapshot.
-
getSnapshotWithResponse
public com.azure.core.http.rest.Response<ConfigurationSnapshot> getSnapshotWithResponse(String snapshotName, List<SnapshotFields> fields, com.azure.core.util.Context context) Get aConfigurationSnapshotby given the snapshot name.Code Samples
String snapshotName = "{snapshotName}"; Context ctx = new Context(key2, value2); ConfigurationSnapshot getSnapshot = client.getSnapshotWithResponse( snapshotName, Arrays.asList(SnapshotFields.NAME, SnapshotFields.CREATED_AT, SnapshotFields.STATUS, SnapshotFields.FILTERS), ctx) .getValue(); // Only properties `name`, `createAt`, `status` and `filters` have value, and expect null or // empty value other than the `fields` specified in the request. System.out.printf("Snapshot name=%s is created at %s, snapshot status is %s.%n", getSnapshot.getName(), getSnapshot.getCreatedAt(), getSnapshot.getStatus()); List<ConfigurationSettingsFilter> filters = getSnapshot.getFilters(); for (ConfigurationSettingsFilter filter : filters) { System.out.printf("Snapshot filter key=%s, label=%s.%n", filter.getKey(), filter.getLabel()); }- Parameters:
snapshotName- the snapshot name.fields- Used to select what fields are present in the returned resource(s).context- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A
ResponseofConfigurationSnapshot.
-
archiveSnapshot
Update a snapshot status fromConfigurationSnapshotStatus.READYtoConfigurationSnapshotStatus.ARCHIVED.Code Samples
String snapshotName = "{snapshotName}"; ConfigurationSnapshot archivedSnapshot = client.archiveSnapshot(snapshotName); System.out.printf("Archived snapshot name=%s is created at %s, snapshot status is %s.%n", archivedSnapshot.getName(), archivedSnapshot.getCreatedAt(), archivedSnapshot.getStatus());- Parameters:
snapshotName- the snapshot name.- Returns:
- A
ConfigurationSnapshot.
-
archiveSnapshotWithResponse
public com.azure.core.http.rest.Response<ConfigurationSnapshot> archiveSnapshotWithResponse(String snapshotName, com.azure.core.http.MatchConditions matchConditions, com.azure.core.util.Context context) Update a snapshot status fromConfigurationSnapshotStatus.READYtoConfigurationSnapshotStatus.ARCHIVED.To turn on using 'if-match' header, set the second parameter 'ifUnchanged' to true. It used to perform an operation only if the targeted resource's ETag matches the value provided. Otherwise, it will throw an exception '412 Precondition Failed'.
Code Samples
String snapshotName = "{snapshotName}"; MatchConditions matchConditions = new MatchConditions().setIfMatch("{etag}"); Context ctx = new Context(key2, value2); ConfigurationSnapshot archivedSnapshot = client.archiveSnapshotWithResponse(snapshotName, matchConditions, ctx) .getValue(); System.out.printf("Archived snapshot name=%s is created at %s, snapshot status is %s.%n", archivedSnapshot.getName(), archivedSnapshot.getCreatedAt(), archivedSnapshot.getStatus());- Parameters:
snapshotName- the snapshot name.matchConditions- Specifies HTTP options for conditional requests.context- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A
ResponseofConfigurationSnapshot.
-
recoverSnapshot
Update a snapshot status fromConfigurationSnapshotStatus.ARCHIVEDtoConfigurationSnapshotStatus.READY.Code Samples
String snapshotName = "{snapshotName}"; ConfigurationSnapshot recoveredSnapshot = client.recoverSnapshot(snapshotName); System.out.printf("Recovered snapshot name=%s is created at %s, snapshot status is %s.%n", recoveredSnapshot.getName(), recoveredSnapshot.getCreatedAt(), recoveredSnapshot.getStatus());- Parameters:
snapshotName- the snapshot name.- Returns:
- A
ConfigurationSnapshot.
-
recoverSnapshotWithResponse
public com.azure.core.http.rest.Response<ConfigurationSnapshot> recoverSnapshotWithResponse(String snapshotName, com.azure.core.http.MatchConditions matchConditions, com.azure.core.util.Context context) Update a snapshot status fromConfigurationSnapshotStatus.ARCHIVEDtoConfigurationSnapshotStatus.READY.To turn on using 'if-match' header, set the second parameter 'ifUnchanged' to true. It used to perform an operation only if the targeted resource's ETag matches the value provided. Otherwise, it will throw an exception '412 Precondition Failed'.
Code Samples
String snapshotName = "{snapshotName}"; MatchConditions matchConditions = new MatchConditions().setIfMatch("{etag}"); Context ctx = new Context(key2, value2); ConfigurationSnapshot recoveredSnapshot = client.recoverSnapshotWithResponse(snapshotName, matchConditions, ctx) .getValue(); System.out.printf("Recovered snapshot name=%s is created at %s, snapshot status is %s.%n", recoveredSnapshot.getName(), recoveredSnapshot.getCreatedAt(), recoveredSnapshot.getStatus());- Parameters:
snapshotName- the snapshot name.matchConditions- Specifies HTTP options for conditional requests.context- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A
ResponseofConfigurationSnapshot.
-
listSnapshots
public com.azure.core.http.rest.PagedIterable<ConfigurationSnapshot> listSnapshots(SnapshotSelector selector) List snapshots by givenSnapshotSelector.Code Samples
String snapshotNameFilter = "{snapshotNamePrefix}*"; client.listSnapshots(new SnapshotSelector().setNameFilter(snapshotNameFilter)) .forEach(snapshotResult -> { System.out.printf("Listed Snapshot name = %s is created at %s, snapshot status is %s.%n", snapshotResult.getName(), snapshotResult.getCreatedAt(), snapshotResult.getStatus()); });- Parameters:
selector- Optional. Used to filterConfigurationSnapshotfrom the service.- Returns:
- A
PagedIterableofConfigurationSnapshot.
-
listSnapshots
public com.azure.core.http.rest.PagedIterable<ConfigurationSnapshot> listSnapshots(SnapshotSelector selector, com.azure.core.util.Context context) List snapshots by givenSnapshotSelector.Code Samples
String snapshotNameFilter = "{snapshotNamePrefix}*"; Context ctx = new Context(key2, value2); client.listSnapshots(new SnapshotSelector().setNameFilter(snapshotNameFilter), ctx) .forEach(snapshotResult -> { System.out.printf("Listed Snapshot name = %s is created at %s, snapshot status is %s.%n", snapshotResult.getName(), snapshotResult.getCreatedAt(), snapshotResult.getStatus()); });- Parameters:
selector- Optional. Used to filterConfigurationSnapshotfrom the service.context- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A
PagedIterableofConfigurationSnapshot.
-
updateSyncToken
Adds an external synchronization token to ensure service requests receive up-to-date values.- Parameters:
token- an external synchronization token to ensure service requests receive up-to-date values.- Throws:
NullPointerException- if the given token is null.
-