Updates from API Review (#4272)

* Updates from API Review

* clang

* update sample
This commit is contained in:
George Arama 2023-01-31 11:13:36 -08:00 committed by GitHub
parent 4abf69c5b4
commit 139bd10feb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 105 additions and 123 deletions

View File

@ -49,7 +49,7 @@ set(
AZURE_SECURITY_KEYVAULT_ADMINISTRATION_HEADER
inc/azure/keyvault/administration.hpp
inc/azure/keyvault/administration/dll_import_export.hpp
inc/azure/keyvault/administration/rest_client.hpp
inc/azure/keyvault/administration/rest_client_models.hpp
inc/azure/keyvault/administration/rtti.hpp
inc/azure/keyvault/administration/settings_client.hpp
inc/azure/keyvault/administration/settings_client_options.hpp

View File

@ -9,7 +9,7 @@
#pragma once
#include "azure/keyvault/administration/dll_import_export.hpp"
#include "azure/keyvault/administration/rest_client.hpp"
#include "azure/keyvault/administration/rest_client_models.hpp"
#include "azure/keyvault/administration/rtti.hpp"
#include "azure/keyvault/administration/settings_client.hpp"
#include "azure/keyvault/administration/settings_client_options.hpp"

View File

@ -1,92 +0,0 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: MIT
//
// Code generated by Microsoft (R) AutoRest C++ Code Generator.
// Changes may cause incorrect behavior and will be lost if the code is
// regenerated.
#pragma once
#include <azure/core/context.hpp>
#include <azure/core/internal/http/pipeline.hpp>
#include <azure/core/nullable.hpp>
#include <azure/core/response.hpp>
#include <azure/core/url.hpp>
#include <azure/keyvault/administration/dll_import_export.hpp>
#include <memory>
#include <string>
#include <vector>
namespace Azure { namespace Security { namespace KeyVault { namespace Administration {
/**
* @brief The type specifier of the value.
*/
class SettingTypeEnum final {
public:
/**
* @brief Default constructor
*/
SettingTypeEnum() = default;
/**
* @brief Constructor
* @param value Setting Value
*/
explicit SettingTypeEnum(std::string value) : m_value(std::move(value)) {}
bool operator==(const SettingTypeEnum& other) const { return m_value == other.m_value; }
bool operator!=(const SettingTypeEnum& other) const { return !(*this == other); }
/**
* @brief Returns value as string
*
* @returns String value
*/
const std::string& ToString() const { return m_value; }
AZURE_SECURITY_KEYVAULT_ADMINISTRATION_DLLEXPORT const static SettingTypeEnum Boolean;
private:
std::string m_value;
};
/**
* @brief Update Settings Options
*/
struct UpdateSettingOptions final
{
/**
* The value of the pool setting.
*/
std::string Value;
};
/**
* @brief Setting struct
*/
struct Setting final
{
/**
* The account setting to be updated.
*/
std::string Name;
/**
* The value of the pool setting.
*/
std::string Value;
/**
* The type specifier of the value.
*/
Azure::Nullable<SettingTypeEnum> Type;
};
/**
* @brief The settings list result.
*/
struct SettingsListResult final
{
/**
* A response message containing a list of account settings with their
* associated value.
*/
std::vector<Setting> Value;
};
}}}} // namespace Azure::Security::KeyVault::Administration

View File

@ -0,0 +1,76 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: MIT
//
// Code generated by Microsoft (R) AutoRest C++ Code Generator.
// Changes may cause incorrect behavior and will be lost if the code is
// regenerated.
#pragma once
#include <azure/core/context.hpp>
#include <azure/core/internal/extendable_enumeration.hpp>
#include <azure/core/internal/http/pipeline.hpp>
#include <azure/core/nullable.hpp>
#include <azure/core/response.hpp>
#include <azure/core/url.hpp>
#include <azure/keyvault/administration/dll_import_export.hpp>
#include <memory>
#include <string>
#include <vector>
namespace Azure { namespace Security { namespace KeyVault { namespace Administration {
namespace Models {
/**
* @brief The type specifier of the value.
*/
class SettingType final : public Azure::Core::_internal::ExtendableEnumeration<SettingType> {
public:
/**
* @brief Default constructor
*/
SettingType() = default;
/**
* @brief Constructor
* @param value Setting Value
*/
explicit SettingType(std::string value) : ExtendableEnumeration(std::move(value)) {}
/*
* @brief Specifies that this represents the Boolean Type
*/
AZURE_SECURITY_KEYVAULT_ADMINISTRATION_DLLEXPORT const static SettingType Boolean;
};
/**
* @brief Setting struct
*/
struct Setting final
{
/**
* The account setting to be updated.
*/
std::string Name;
/**
* The value of the pool setting.
*/
std::string Value;
/**
* The type specifier of the value.
*/
Azure::Nullable<SettingType> Type;
};
/**
* @brief The settings list result.
*/
struct SettingsListResult final
{
/**
* A response message containing a list of account settings with their
* associated value.
*/
std::vector<Setting> Value;
};
}}}}} // namespace Azure::Security::KeyVault::Administration::Models

View File

@ -12,11 +12,13 @@
#include <azure/core/http/http.hpp>
#include <azure/core/internal/http/pipeline.hpp>
#include <azure/core/response.hpp>
#include <azure/keyvault/administration/rest_client.hpp>
#include <azure/keyvault/administration/rest_client_models.hpp>
#include <azure/keyvault/administration/settings_client_options.hpp>
#include <memory>
#include <string>
using namespace Azure::Security::KeyVault::Administration::Models;
namespace Azure { namespace Security { namespace KeyVault { namespace Administration {
/**
* @brief Settings Client class.
@ -59,27 +61,27 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Administra
/**
* @brief Update a setting.
*
* @param settingName Name of the setting to update.
* @param options Options for updating the setting.
* @param name Name of the setting to update.
* @param value Value of the setting .
* @param context Operation Context.
*
* @returns Response containing the new updated setting.
*/
Azure::Response<Setting> UpdateSetting(
std::string const& settingName,
UpdateSettingOptions const& options,
std::string const& name,
std::string const& value,
const Azure::Core::Context& context = Azure::Core::Context{}) const;
/**
* @brief Gets an existing setting.
*
* @param settingName Name of setting to get.
* @param name Name of setting to get.
* @param context Operation context.
*
* @returns response containing the setting.
*/
Azure::Response<Setting> GetSetting(
std::string const& settingName,
std::string const& name,
const Azure::Core::Context& context = Azure::Core::Context{}) const;
/**

View File

@ -64,20 +64,20 @@ SettingsClient::SettingsClient(
}
Azure::Response<Setting> SettingsClient::UpdateSetting(
std::string const& settingName,
UpdateSettingOptions const& options,
std::string const& name,
std::string const& value,
const Azure::Core::Context& context) const
{
std::string jsonBody;
{
auto jsonRoot = Azure::Core::Json::_internal::json::object();
jsonRoot[ValueField] = options.Value;
jsonRoot[ValueField] = value;
jsonBody = jsonRoot.dump();
}
Azure::Core::IO::MemoryBodyStream requestBody(
reinterpret_cast<const uint8_t*>(jsonBody.data()), jsonBody.length());
auto request = CreateRequest(HttpMethod::Patch, {SettingPathName, settingName}, &requestBody);
auto request = CreateRequest(HttpMethod::Patch, {SettingPathName, name}, &requestBody);
auto pRawResponse = m_pipeline->Send(request, context);
auto httpStatusCode = pRawResponse->GetStatusCode();
if (httpStatusCode != Azure::Core::Http::HttpStatusCode::Ok)
@ -89,10 +89,10 @@ Azure::Response<Setting> SettingsClient::UpdateSetting(
}
Azure::Response<Setting> SettingsClient::GetSetting(
std::string const& settingName,
std::string const& name,
const Azure::Core::Context& context) const
{
auto request = CreateRequest(HttpMethod::Get, {SettingPathName, settingName});
auto request = CreateRequest(HttpMethod::Get, {SettingPathName, name});
auto pRawResponse = m_pipeline->Send(request, context);
auto httpStatusCode = pRawResponse->GetStatusCode();
if (httpStatusCode != Azure::Core::Http::HttpStatusCode::Ok)
@ -140,7 +140,7 @@ Setting SettingsClient::ParseSetting(std::vector<uint8_t> const& responseBody) c
response.Value = jsonRoot[ValueField].get<std::string>();
if (jsonRoot.count(TypeField) != 0)
{
response.Type = SettingTypeEnum(jsonRoot[TypeField].get<std::string>());
response.Type = SettingType(jsonRoot[TypeField].get<std::string>());
}
}
return response;

View File

@ -47,11 +47,8 @@ int main()
std::cout << "Retrieved setting with name " << setting.Name << ", with value " << setting.Value
<< std::endl;
UpdateSettingOptions options;
options.Value = setting.Value;
Setting updatedSetting
= settingsClient.UpdateSetting(settingsList.Value[0].Name, options).Value;
= settingsClient.UpdateSetting(settingsList.Value[0].Name, setting.Value).Value;
std::cout << "Retrieved updated setting with name " << updatedSetting.Name << ", with value "
<< updatedSetting.Value << std::endl;

View File

@ -6,13 +6,14 @@
#include "azure/keyvault/administration/settings_client.hpp"
#include "settings_client_base_test.hpp"
#include <azure/core/base64.hpp>
#include <azure/keyvault/administration/rest_client.hpp>
#include <azure/keyvault/administration/rest_client_models.hpp>
#include <cstddef>
#include <gtest/gtest.h>
#include <string>
#include <thread>
using namespace std::chrono_literals;
using namespace Azure::Security::KeyVault::Administration;
using namespace Azure::Security::KeyVault::Administration::Models;
using namespace Azure::Security::KeyVault::Administration::Test;
using namespace std::chrono_literals;
@ -57,25 +58,23 @@ TEST_F(SettingsClientTest, UpdateSetting)
// create certificate method contains all the checks
auto const& client = GetClientForTest(testName);
{
UpdateSettingOptions options;
options.Value = "false";
auto result = client.UpdateSetting("AllowKeyManagementOperationsThroughARM", options);
std::string value = "false";
auto result = client.UpdateSetting("AllowKeyManagementOperationsThroughARM", value);
EXPECT_EQ(result.Value.Name, "AllowKeyManagementOperationsThroughARM");
EXPECT_EQ(result.Value.Value, "false");
}
{
UpdateSettingOptions options;
options.Value = "true";
auto result = client.UpdateSetting("AllowKeyManagementOperationsThroughARM", options);
std::string value = "true";
auto result = client.UpdateSetting("AllowKeyManagementOperationsThroughARM", value);
EXPECT_EQ(result.Value.Name, "AllowKeyManagementOperationsThroughARM");
EXPECT_EQ(result.Value.Value, "true");
}
{
UpdateSettingOptions options;
options.Value = "false";
auto result = client.UpdateSetting("AllowKeyManagementOperationsThroughARM", options);
std::string value = "false";
auto result = client.UpdateSetting("AllowKeyManagementOperationsThroughARM", value);
EXPECT_EQ(result.Value.Name, "AllowKeyManagementOperationsThroughARM");
EXPECT_EQ(result.Value.Value, "false");