Skip to content

Commit

Permalink
Add samples for Get, Set, and Delete Configuration Settings with comp…
Browse files Browse the repository at this point in the history
…arisons of what we'd expect the user experience to be.
  • Loading branch information
ahsonkhan committed Dec 11, 2024
1 parent d03f77a commit 0f22196
Showing 1 changed file with 138 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

/**
* @brief This sample provides the code implementation to use the App Configuration client SDK for
* C++ to get one or more configuration settings.
* C++ to create, retrieve and delete a configuration setting.
*/

#include <azure/data/appconfiguration.hpp>
Expand All @@ -21,24 +21,151 @@ int main()
std::string url = "https://<your-appconfig-name>.azconfig.io";
auto credential = std::make_shared<Azure::Identity::DefaultAzureCredential>();

// create client
// Create a ConfigurationClient
ConfigurationClient configurationClient(url, credential);

Azure::Response<GetKeyValueResult> response = configurationClient.GetKeyValue("key", "accept");
// Create a configuration setting

GetKeyValueResult result = response.Value;
Azure::Nullable<std::string> valueOfKey = result.Value;
// Current
{
KeyValue entity;
entity.Value = "some-value";

PutKeyValueOptions options;
options.Label = "some-label";
options.Entity = entity;

Azure::Response<PutKeyValueResult> putKeyValueResult = configurationClient.PutKeyValue(
PutKeyValueRequestContentType::ApplicationJson, "some-key", "accept", options);

PutKeyValueResult result = putKeyValueResult.Value;
Azure::Nullable<std::string> valueOfKey = result.Value;

std::cout << result.Key << std::endl; // some-key

if (valueOfKey.HasValue())
if (valueOfKey.HasValue())
{
std::cout << valueOfKey.Value() << std::endl; // some-value
}
}

// Expected

#if 0
{
std::cout << valueOfKey.Value() << std::endl;
ConfigurationSetting setting;
setting.Key = "some-key";
setting.Value = "some-value";

SetSettingOptions options;
options.Label = "some-label";

Azure::Response<ConfigurationSetting> setResult
= configurationClient.SetConfigurationSetting(setting, options);

ConfigurationSetting result = setResult.Value;
Azure::Nullable<std::string> valueOfKey = result.Value;

std::cout << result.Key << std::endl; // some-key

if (valueOfKey.HasValue())
{
std::cout << valueOfKey.Value() << std::endl; // some-value
}
}
else
#endif

// Retrieve a configuration setting

// Current
{
std::cout << "Value for: '"
<< "key"
<< "' does not exist." << std::endl;
GetKeyValueOptions options;
options.Label = "some-label";
Azure::Response<GetKeyValueResult> getKeyValueResult
= configurationClient.GetKeyValue("some-key", "accept", options);

GetKeyValueResult result = getKeyValueResult.Value;
Azure::Nullable<std::string> valueOfKey = result.Value;

if (valueOfKey.HasValue())
{
std::cout << valueOfKey.Value() << std::endl; // some-value
}
else
{
std::cout << "Value for: '" << result.Key << "' does not exist." << std::endl;
}
}

// Expected

#if 0
{
GetConfigurationSettingOptions options;
options.Label = "some-label";
Azure::Response<ConfigurationSetting> getResult
= configurationClient.GetConfigurationSetting("some-key", options);

ConfigurationSetting result = getResult.Value;
Azure::Nullable<std::string> valueOfKey = result.Value;

if (valueOfKey.HasValue())
{
std::cout << valueOfKey.Value() << std::endl; // some-value
}
else
{
std::cout << "Value for: '" << result.Key << "' does not exist." << std::endl;
}
}
#endif

// Delete a configuration setting

// Current
{
DeleteKeyValueOptions options;
options.Label = "some-label";

Azure::Response<DeleteKeyValueResult> deleteKeyValueResult
= configurationClient.DeleteKeyValue("some-key", "accept", options);

DeleteKeyValueResult result = deleteKeyValueResult.Value;
Azure::Nullable<std::string> valueOfKey = result.Value;

if (valueOfKey.HasValue())
{
std::cout << valueOfKey.Value() << std::endl; // some-value
}
else
{
std::cout << "Value for: '" << result.Key << "' does not exist." << std::endl;
}
}

// Expected

#if 0
{
DeleteKeyValueOptions options;
options.Label = "some-label";

Azure::Response<ConfigurationSetting> deleteKeyValueResult
= configurationClient.DeleteConfigurationSetting("some-key", options);

ConfigurationSetting result = deleteKeyValueResult.Value;
Azure::Nullable<std::string> valueOfKey = result.Value;

if (valueOfKey.HasValue())
{
std::cout << valueOfKey.Value() << std::endl; // some-value
}
else
{
std::cout << "Value for: '" << result.Key << "' does not exist." << std::endl;
}
}
#endif
}
catch (Azure::Core::Credentials::AuthenticationException const& e)
{
Expand Down

0 comments on commit 0f22196

Please sign in to comment.