// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. /** * @brief This sample provides the code implementation to use the App Configuration client SDK for * C++ to create, retrieve and delete a configuration setting. */ #include #include #include #include using namespace Azure::Data::AppConfiguration; using namespace Azure::Identity; // Make the setting read-only static void SetReadOnly(ConfigurationClient& configurationClient) { // Current { PutLockOptions options; options.Label = "some-label"; Azure::Response putLockResult = configurationClient.PutLock("some-key", "accept", options); PutLockResult result = putLockResult.Value; Azure::Nullable isLocked = result.Locked; std::cout << result.Key << std::endl; // some-key if (isLocked.HasValue()) { std::cout << "isLocked: " << isLocked.Value() << std::endl; // true } } // Expected #if 0 { SetReadOnlyOptions options; options.Label = "some-label"; Azure::Response setReadOnlyResult = configurationClient.SetReadOnly("some-key", true, options); ConfigurationSetting result = setReadOnlyResult.Value; Azure::Nullable isReadOnly = result.IsReadOnly; std::cout << result.Key << std::endl; // some-key if (isReadOnly.HasValue()) { std::cout << "isReadOnly: " << isReadOnly.Value() << std::endl; // true } } #endif } // Try modifying a read-only setting and then modify a read-write setting static void SetConfigurationSetting(ConfigurationClient& configurationClient) { // Current { KeyValue entity; entity.Value = "another-value"; PutKeyValueOptions options; options.Label = "some-label"; options.Entity = entity; Azure::Response putKeyValueResult = configurationClient.PutKeyValue( PutKeyValueRequestContentType::ApplicationJson, "some-key", "accept", options); PutKeyValueResult result = putKeyValueResult.Value; Azure::Nullable valueOfKey = result.Value; std::cout << result.Key << std::endl; // some-key if (valueOfKey.HasValue()) { std::cout << valueOfKey.Value() << std::endl; // another-value } } // Expected #if 0 { ConfigurationSetting setting; setting.Key = "some-key"; setting.Value = "another-value"; SetSettingOptions options; options.Label = "some-label"; Azure::Response setResult = configurationClient.SetConfigurationSetting(setting, options); ConfigurationSetting result = setResult.Value; Azure::Nullable valueOfKey = result.Value; std::cout << result.Key << std::endl; // some-key if (valueOfKey.HasValue()) { std::cout << valueOfKey.Value() << std::endl; // another-value } } #endif } // Make the setting read-write static void SetReadWrite(ConfigurationClient& configurationClient) { // Current { DeleteLockOptions options; options.Label = "some-label"; Azure::Response deleteLockResult = configurationClient.DeleteLock("some-key", "accept", options); DeleteLockResult result = deleteLockResult.Value; Azure::Nullable isLocked = result.Locked; std::cout << result.Key << std::endl; // some-key if (isLocked.HasValue()) { std::cout << "isLocked: " << isLocked.Value() << std::endl; // false } } // Expected #if 0 { SetReadOnlyOptions options; options.Label = "some-label"; Azure::Response setReadOnlyResult = configurationClient.SetReadOnly("some-key", false, options); ConfigurationSetting result = setReadOnlyResult.Value; Azure::Nullable isReadOnly = result.IsReadOnly; std::cout << result.Key << std::endl; // some-key if (isReadOnly.HasValue()) { std::cout << "isReadOnly: " << isReadOnly.Value() << std::endl; // false } } #endif } // Retreive labels based on filters static void RetrieveLabels(ConfigurationClient& configurationClient) { // Current { GetLabelsOptions options; // To get all labels, don't set Name or use the any wildcard ("*"). options.Name = "production*"; options.AcceptDatetime = "Fri, 10 Jan 2025 00:00:00 GMT"; for (GetLabelsPagedResponse labelsPage = configurationClient.GetLabels("accept", options); labelsPage.HasPage(); labelsPage.MoveToNextPage()) { if (labelsPage.Items.HasValue()) { std::vector