From 0de681868ba9f6f779eacec422107e9990f4e485 Mon Sep 17 00:00:00 2001 From: zjack8 <61671353+zjack8@users.noreply.github.com> Date: Mon, 16 Oct 2023 17:06:50 +1300 Subject: [PATCH 1/3] Added ReadOnly --- .../android/appconfiguration/ReadOnly.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 sdk/android/azure-samples/src/main/java/com/azure/android/appconfiguration/ReadOnly.java diff --git a/sdk/android/azure-samples/src/main/java/com/azure/android/appconfiguration/ReadOnly.java b/sdk/android/azure-samples/src/main/java/com/azure/android/appconfiguration/ReadOnly.java new file mode 100644 index 0000000000000..03df2cf6f7ef9 --- /dev/null +++ b/sdk/android/azure-samples/src/main/java/com/azure/android/appconfiguration/ReadOnly.java @@ -0,0 +1,45 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.android.appconfiguration; + +import android.util.Log; + +import com.azure.data.appconfiguration.ConfigurationClient; +import com.azure.data.appconfiguration.ConfigurationClientBuilder; +import com.azure.data.appconfiguration.models.ConfigurationSetting; +import com.azure.identity.ClientSecretCredential; + +/** + * Sample demonstrates how to set and clear read-only a configuration setting. + */ +public class ReadOnly { + + private static final String TAG = "AppconfigReadOnlyOutput"; + /** + * Runs the sample algorithm and demonstrates how to set and clear read-only a configuration setting. + * + */ + public static void main(String endpoint, ClientSecretCredential credential) { + // The connection string value can be obtained by going to your App Configuration instance in the Azure portal + // and navigating to "Access Keys" page under the "Settings" section. + final ConfigurationClient client = new ConfigurationClientBuilder() + .credential(credential) + .endpoint(endpoint) + .buildClient(); + + // Name of the key to add to the configuration service. + final String key = "hello"; + final String value = "world"; + + final ConfigurationSetting setting = client.setConfigurationSetting(key, null, value); + // Read-Only + final ConfigurationSetting readOnlySetting = client.setReadOnly(setting.getKey(), setting.getLabel(), true); + Log.i(TAG, String.format("Setting is read-only now, Key: %s, Value: %s", + readOnlySetting.getKey(), readOnlySetting.getValue())); + // Clear Read-Only + final ConfigurationSetting clearedReadOnlySetting = client.setReadOnly(setting.getKey(), setting.getLabel(), false); + Log.i(TAG, String.format("Setting is no longer read-only, Key: %s, Value: %s", + clearedReadOnlySetting.getKey(), clearedReadOnlySetting.getValue())); + } +} From aac55b76d4d8f338c028a6a7e61d6bd36e3bd8d7 Mon Sep 17 00:00:00 2001 From: zjack8 <61671353+zjack8@users.noreply.github.com> Date: Mon, 16 Oct 2023 17:07:32 +1300 Subject: [PATCH 2/3] Delete CreateSnapshot.java --- .../appconfiguration/CreateSnapshot.java | 89 ------------------- 1 file changed, 89 deletions(-) delete mode 100644 sdk/android/azure-samples/src/main/java/com/azure/android/appconfiguration/CreateSnapshot.java diff --git a/sdk/android/azure-samples/src/main/java/com/azure/android/appconfiguration/CreateSnapshot.java b/sdk/android/azure-samples/src/main/java/com/azure/android/appconfiguration/CreateSnapshot.java deleted file mode 100644 index 76809106fc1d0..0000000000000 --- a/sdk/android/azure-samples/src/main/java/com/azure/android/appconfiguration/CreateSnapshot.java +++ /dev/null @@ -1,89 +0,0 @@ -//// Copyright (c) Microsoft Corporation. All rights reserved. -//// Licensed under the MIT License. -// -//package com.azure.android.appconfiguration; -// -//import android.util.Log; -// -//import com.azure.core.util.Context; -//import com.azure.data.appconfiguration.ConfigurationClient; -//import com.azure.data.appconfiguration.ConfigurationClientBuilder; -//import com.azure.data.appconfiguration.models.ConfigurationSetting; -//import com.azure.identity.ClientSecretCredential; -// -// -//import java.time.Duration; -//import java.util.ArrayList; -// -///** -// * Sample demonstrates how to create, retrieve, archive, recover a configuration setting snapshot, and list settings -// * by snapshot name. -// */ -//public class CreateSnapshot { -// /** -// * Runs the sample demonstrates how to create, retrieve, archive, recover a configuration setting snapshot, and -// * list settings by snapshot name. -// * -// * @param args Unused. Arguments to the program. -// */ -// -// private static final String TAG = "CreateSnapshotOutput"; -// -// public static void main(String endpoint, ClientSecretCredential credential) { -// // The connection string value can be obtained by going to your App Configuration instance in the Azure portal -// // and navigating to "Access Keys" page under the "Settings" section. -// -// // Instantiate a client that will be used to call the service. -// final ConfigurationClient client = new ConfigurationClientBuilder() -// .credential(credential) -// .endpoint(endpoint) -// .buildClient(); -// -// Log.i(TAG, "Beginning of synchronous sample..."); -// // Prepare first setting. -// ConfigurationSetting setting = client.setConfigurationSetting("TestKey1", null, "value1"); -// Log.i(TAG, String.format("[SetConfigurationSetting] Key: %s, Value: %s.%n", setting.getKey(), setting.getValue())); -// // Prepare second setting. -// ConfigurationSetting setting2 = client.setConfigurationSetting("TestKey2", null, "value2"); -// Log.i(TAG, String.format("[SetConfigurationSetting] Key: %s, Value: %s.%n", setting2.getKey(), setting2.getValue())); -// // Prepare the snapshot filters -// List filters = new ArrayList<>(); -// // Key Name also supports RegExp but only support prefix end with "*", such as "k*" and is case-sensitive. -// filters.add(new SnapshotSettingFilter("Test*")); -// -// // Create a snapshot -// String snapshotName = "{snapshotName}"; -// SyncPoller poller = -// client.beginCreateSnapshot(snapshotName, new ConfigurationSettingSnapshot(filters), Context.NONE); -// poller.setPollInterval(Duration.ofSeconds(10)); -// poller.waitForCompletion(); -// ConfigurationSettingSnapshot snapshot = poller.getFinalResult(); -// Log.i(TAG, String.format("Snapshot name=%s is created at %s, snapshot status is %s.%n", -// snapshot.getName(), snapshot.getCreatedAt(), snapshot.getStatus())); -// -// // Get the snapshot status -// ConfigurationSettingSnapshot getSnapshot = client.getSnapshot(snapshotName); -// Log.i(TAG, String.format("Snapshot name=%s is created at %s, snapshot status is %s.%n", -// getSnapshot.getName(), getSnapshot.getCreatedAt(), getSnapshot.getStatus())); -// -// // Archive a READY snapshot -// ConfigurationSettingSnapshot archivedSnapshot = client.archiveSnapshot(snapshotName); -// Log.i(TAG, String.format("Archived snapshot name=%s is created at %s, snapshot status is %s.%n", -// archivedSnapshot.getName(), archivedSnapshot.getCreatedAt(), archivedSnapshot.getStatus())); -// -// // Recover the Archived snapshot -// ConfigurationSettingSnapshot recoveredSnapshot = client.recoverSnapshot(snapshotName); -// Log.i(TAG, String.format("Recovered snapshot name=%s is created at %s, snapshot status is %s.%n", -// recoveredSnapshot.getName(), recoveredSnapshot.getCreatedAt(), recoveredSnapshot.getStatus())); -// -// // List the configuration settings in the snapshot -// client.listConfigurationSettingsForSnapshot(snapshotName).forEach( -// settingInSnapshot -> { -// Log.i(TAG, String.format("[ConfigurationSetting In Snapshot] Key: %s, Value: %s.%n", -// settingInSnapshot.getKey(), settingInSnapshot.getValue())); -// } -// ); -// -// Log.i(TAG, "End of synchronous sample."); -// } -//} From 347c816f36ab6804935e962a9133fc8049b90e8b Mon Sep 17 00:00:00 2001 From: Mathew Veale Date: Wed, 18 Oct 2023 17:46:08 +1300 Subject: [PATCH 3/3] readOnly implemented --- .../android/AppConfigurationSampleTests.java | 9 +- .../android/appconfiguration/ReadOnly.java | 90 +++++++++---------- 2 files changed, 48 insertions(+), 51 deletions(-) diff --git a/sdk/android/azure-samples/src/androidTest/java/com/azure/android/AppConfigurationSampleTests.java b/sdk/android/azure-samples/src/androidTest/java/com/azure/android/AppConfigurationSampleTests.java index efaba70742f6e..54fd07bb615c0 100644 --- a/sdk/android/azure-samples/src/androidTest/java/com/azure/android/AppConfigurationSampleTests.java +++ b/sdk/android/azure-samples/src/androidTest/java/com/azure/android/AppConfigurationSampleTests.java @@ -57,18 +57,15 @@ public void secretReferenceConfigurationSettingSample() { } } - /* - I've been unable to get the dependencies for CreateSnapshot, I suspect they're in the preview version - of the SDK. Once that is figured out this test should be able to be safely uncommented @Test - public void createSnapshot() { + public void readOnly() { try { - CreateSnapshot.main(appconfigEndpoint, clientSecretCredential); + ReadOnly.main(appconfigEndpoint, clientSecretCredential); } catch (RuntimeException e) { fail(); } } - */ + @Test public void conditionalRequestAsync() { diff --git a/sdk/android/azure-samples/src/main/java/com/azure/android/appconfiguration/ReadOnly.java b/sdk/android/azure-samples/src/main/java/com/azure/android/appconfiguration/ReadOnly.java index 03df2cf6f7ef9..c97f5ac093732 100644 --- a/sdk/android/azure-samples/src/main/java/com/azure/android/appconfiguration/ReadOnly.java +++ b/sdk/android/azure-samples/src/main/java/com/azure/android/appconfiguration/ReadOnly.java @@ -1,45 +1,45 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.android.appconfiguration; - -import android.util.Log; - -import com.azure.data.appconfiguration.ConfigurationClient; -import com.azure.data.appconfiguration.ConfigurationClientBuilder; -import com.azure.data.appconfiguration.models.ConfigurationSetting; -import com.azure.identity.ClientSecretCredential; - -/** - * Sample demonstrates how to set and clear read-only a configuration setting. - */ -public class ReadOnly { - - private static final String TAG = "AppconfigReadOnlyOutput"; - /** - * Runs the sample algorithm and demonstrates how to set and clear read-only a configuration setting. - * - */ - public static void main(String endpoint, ClientSecretCredential credential) { - // The connection string value can be obtained by going to your App Configuration instance in the Azure portal - // and navigating to "Access Keys" page under the "Settings" section. - final ConfigurationClient client = new ConfigurationClientBuilder() - .credential(credential) - .endpoint(endpoint) - .buildClient(); - - // Name of the key to add to the configuration service. - final String key = "hello"; - final String value = "world"; - - final ConfigurationSetting setting = client.setConfigurationSetting(key, null, value); - // Read-Only - final ConfigurationSetting readOnlySetting = client.setReadOnly(setting.getKey(), setting.getLabel(), true); - Log.i(TAG, String.format("Setting is read-only now, Key: %s, Value: %s", - readOnlySetting.getKey(), readOnlySetting.getValue())); - // Clear Read-Only - final ConfigurationSetting clearedReadOnlySetting = client.setReadOnly(setting.getKey(), setting.getLabel(), false); - Log.i(TAG, String.format("Setting is no longer read-only, Key: %s, Value: %s", - clearedReadOnlySetting.getKey(), clearedReadOnlySetting.getValue())); - } -} +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.android.appconfiguration; + +import android.util.Log; + +import com.azure.data.appconfiguration.ConfigurationClient; +import com.azure.data.appconfiguration.ConfigurationClientBuilder; +import com.azure.data.appconfiguration.models.ConfigurationSetting; +import com.azure.identity.ClientSecretCredential; + +/** + * Sample demonstrates how to set and clear read-only a configuration setting. + */ +public class ReadOnly { + + private static final String TAG = "AppconfigReadOnlyOutput"; + /** + * Runs the sample algorithm and demonstrates how to set and clear read-only a configuration setting. + * + */ + public static void main(String endpoint, ClientSecretCredential credential) { + // The connection string value can be obtained by going to your App Configuration instance in the Azure portal + // and navigating to "Access Keys" page under the "Settings" section. + final ConfigurationClient client = new ConfigurationClientBuilder() + .credential(credential) + .endpoint(endpoint) + .buildClient(); + + // Name of the key to add to the configuration service. + final String key = "hello"; + final String value = "world"; + + final ConfigurationSetting setting = client.setConfigurationSetting(key, null, value); + // Read-Only + final ConfigurationSetting readOnlySetting = client.setReadOnly(setting.getKey(), setting.getLabel(), true); + Log.i(TAG, String.format("Setting is read-only now, Key: %s, Value: %s", + readOnlySetting.getKey(), readOnlySetting.getValue())); + // Clear Read-Only + final ConfigurationSetting clearedReadOnlySetting = client.setReadOnly(setting.getKey(), setting.getLabel(), false); + Log.i(TAG, String.format("Setting is no longer read-only, Key: %s, Value: %s", + clearedReadOnlySetting.getKey(), clearedReadOnlySetting.getValue())); + } +}