Add samples for Get, Set, and Delete Configuration Settings with comparisons of what we'd expect the user experience to be. (#6286)
This commit is contained in:
parent
30902ff60f
commit
a046842add
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This sample provides the code implementation to use the App Configuration client SDK for
|
* @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>
|
#include <azure/data/appconfiguration.hpp>
|
||||||
@ -21,24 +21,151 @@ int main()
|
|||||||
std::string url = "https://<your-appconfig-name>.azconfig.io";
|
std::string url = "https://<your-appconfig-name>.azconfig.io";
|
||||||
auto credential = std::make_shared<Azure::Identity::DefaultAzureCredential>();
|
auto credential = std::make_shared<Azure::Identity::DefaultAzureCredential>();
|
||||||
|
|
||||||
// create client
|
// Create a ConfigurationClient
|
||||||
ConfigurationClient configurationClient(url, credential);
|
ConfigurationClient configurationClient(url, credential);
|
||||||
|
|
||||||
Azure::Response<GetKeyValueResult> response = configurationClient.GetKeyValue("key", "accept");
|
// Create a configuration setting
|
||||||
|
|
||||||
GetKeyValueResult result = response.Value;
|
// Current
|
||||||
Azure::Nullable<std::string> valueOfKey = result.Value;
|
{
|
||||||
|
KeyValue entity;
|
||||||
|
entity.Value = "some-value";
|
||||||
|
|
||||||
if (valueOfKey.HasValue())
|
PutKeyValueOptions options;
|
||||||
{
|
options.Label = "some-label";
|
||||||
std::cout << valueOfKey.Value() << std::endl;
|
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())
|
||||||
|
{
|
||||||
|
std::cout << valueOfKey.Value() << std::endl; // some-value
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
// Expected
|
||||||
|
|
||||||
|
#if 0
|
||||||
{
|
{
|
||||||
std::cout << "Value for: '"
|
ConfigurationSetting setting;
|
||||||
<< "key"
|
setting.Key = "some-key";
|
||||||
<< "' does not exist." << std::endl;
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Retrieve a configuration setting
|
||||||
|
|
||||||
|
// Current
|
||||||
|
{
|
||||||
|
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)
|
catch (Azure::Core::Credentials::AuthenticationException const& e)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user