Skip to content

Commit

Permalink
Per request (#3770)
Browse files Browse the repository at this point in the history
* Per request

* const

* Jeff feedback , clang, and test
  • Loading branch information
gearama authored Jun 27, 2022
1 parent 6e129f5 commit 417c7fa
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 167 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,65 +18,23 @@

namespace Azure { namespace Security { namespace KeyVault { namespace Certificates {

/**
* @brief The API version to use from Key Vault.
*
*/
class ServiceVersion final {
private:
std::string m_version;

public:
/**
* @brief Construct a new Service Version object
*
* @param version The string version for the Key Vault Certificate service.
*/
ServiceVersion(std::string version) : m_version(std::move(version)) {}

/**
* @brief Enable comparing the ext enum.
*
* @param other Another #ServiceVersion to be compared.
*/
bool operator==(ServiceVersion const& other) const { return m_version == other.m_version; }

/**
* @brief Return the #ServiceVersion string representation.
*
*/
std::string const& ToString() const { return m_version; }

/**
* @brief Use to send request to the 7.2 version of Key Vault service.
*
*/
AZ_SECURITY_KEYVAULT_CERTIFICATES_DLLEXPORT static const ServiceVersion V7_2;

/**
* @brief Use to send request to the 7.3 version of Key Vault service.
*
*/
AZ_SECURITY_KEYVAULT_CERTIFICATES_DLLEXPORT static const ServiceVersion V7_3;
};

/**
* @brief Define the options to create an SDK Certificate client.
*
*/
struct CertificateClientOptions final : public Azure::Core::_internal::ClientOptions
{
ServiceVersion Version;
/**
* @brief Service Version used.
*
*/
std::string Version;

/**
* @brief Construct a new Certificate Client Options object.
*
* @param version Optional version for the client.
*/
CertificateClientOptions(ServiceVersion version = ServiceVersion::V7_3)
: Azure::Core::_internal::ClientOptions(), Version(version)
{
}
CertificateClientOptions() : Azure::Core::_internal::ClientOptions() { Version = "7.3"; }
};

}}}} // namespace Azure::Security::KeyVault::Certificates
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ CertificateClient::CertificateClient(
std::string const& vaultUrl,
std::shared_ptr<Core::Credentials::TokenCredential const> credential,
CertificateClientOptions options)
: m_vaultUrl(vaultUrl), m_apiVersion(options.Version.ToString())
: m_vaultUrl(vaultUrl), m_apiVersion(options.Version)
{
auto apiVersion = options.Version.ToString();
auto apiVersion = options.Version;

std::vector<std::unique_ptr<HttpPolicy>> perRetrypolicies;
{
Expand Down Expand Up @@ -493,6 +493,3 @@ Azure::Response<KeyVaultCertificate> CertificateClient::UpdateCertificatePropert
auto value = KeyVaultCertificateSerializer::Deserialize(certificateName, *rawResponse);
return Azure::Response<KeyVaultCertificate>(std::move(value), std::move(rawResponse));
}

const ServiceVersion ServiceVersion::V7_3("7.3");
const ServiceVersion ServiceVersion::V7_2("7.2");
Original file line number Diff line number Diff line change
Expand Up @@ -888,3 +888,22 @@ TEST_F(KeyVaultCertificateClientTest, DISABLED_MergeCertificate)
}
}
}

TEST_F(KeyVaultCertificateClientTest, ServiceVersion)
{
auto credential
= std::make_shared<Azure::Identity::ClientSecretCredential>("tenantID", "AppId", "SecretId");
{
// 7.3
EXPECT_NO_THROW(auto options = CertificateClientOptions(); CertificateClient certificateClient(
"http://account.vault.azure.net", credential, options);
EXPECT_EQ(options.Version, "7.3"););
}
{
// arbitrary version
EXPECT_NO_THROW(
auto options = CertificateClientOptions(); options.Version = "1.0";
CertificateClient certificateClient("http://account.vault.azure.net", credential, options);
EXPECT_EQ(options.Version, "1.0"););
}
}
1 change: 0 additions & 1 deletion sdk/keyvault/azure-security-keyvault-keys/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ set(
src/json_web_key.cpp
src/key_backup.cpp
src/key_client.cpp
src/key_client_options.cpp
src/key_client_paged_responses.cpp
src/key_curve_name.cpp
src/key_operation.cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,61 +43,23 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Keys {
Azure::Nullable<std::string> NextPageToken;
};

class ServiceVersion final {
private:
std::string m_version;

public:
/**
* @brief Construct a new Service Version object
*
* @param version The string version for the Key Vault keys service.
*/
ServiceVersion(std::string version) : m_version(std::move(version)) {}

/**
* @brief Enable comparing the ext enum.
*
* @param other Another #ServiceVersion to be compared.
*/
bool operator==(ServiceVersion const& other) const { return m_version == other.m_version; }

/**
* @brief Return the #ServiceVersion string representation.
*
*/
std::string const& ToString() const { return m_version; }

/**
* @brief Use to send request to the 7.2 version of Key Vault service.
*
*/
AZ_SECURITY_KEYVAULT_KEYS_DLLEXPORT static const ServiceVersion V7_2;

/**
* @brief Use to send request to the 7.3 version of Key Vault service.
*
*/
AZ_SECURITY_KEYVAULT_KEYS_DLLEXPORT static const ServiceVersion V7_3;
};

/**
* @brief Define the options to create an SDK Keys client.
*
*/
struct KeyClientOptions final : public Azure::Core::_internal::ClientOptions
{
ServiceVersion Version;
/**
* @brief Service Version used.
*
*/
std::string Version;

/**
* @brief Construct a new Key Client Options object.
*
* @param version Optional version for the client.
*/
KeyClientOptions(ServiceVersion version = ServiceVersion::V7_3)
: Azure::Core::_internal::ClientOptions(), Version(version)
{
}
KeyClientOptions() : Azure::Core::_internal::ClientOptions() { Version = "7.3"; }
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ KeyClient::KeyClient(
std::string const& vaultUrl,
std::shared_ptr<Core::Credentials::TokenCredential const> credential,
KeyClientOptions options)
: m_vaultUrl(vaultUrl), m_apiVersion(options.Version.ToString())
: m_vaultUrl(vaultUrl), m_apiVersion(options.Version)
{
std::vector<std::unique_ptr<HttpPolicy>> perRetrypolicies;
{
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ TEST(KeyVaultKeyClientUnitTest, ServiceVersion)
= std::make_shared<Azure::Identity::ClientSecretCredential>("tenantID", "AppId", "SecretId");
{
// 7.3
EXPECT_NO_THROW(auto options = KeyClientOptions(ServiceVersion::V7_3);
EXPECT_NO_THROW(auto options = KeyClientOptions();
KeyClient keyClient("http://account.vault.azure.net", credential, options);
EXPECT_EQ(options.Version.ToString(), "7.3"););
EXPECT_EQ(options.Version, "7.3"););
}
{
// arbitrary version
EXPECT_NO_THROW(auto options = KeyClientOptions(ServiceVersion("1.0"));
EXPECT_NO_THROW(auto options = KeyClientOptions(); options.Version = "1.0";
KeyClient keyClient("http://account.vault.azure.net", credential, options);
EXPECT_EQ(options.Version.ToString(), "1.0"););
EXPECT_EQ(options.Version, "1.0"););
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,44 +11,6 @@

namespace Azure { namespace Security { namespace KeyVault { namespace Secrets {

class ServiceVersion final {
private:
std::string m_version;

public:
/**
* @brief Construct a new Service Version object
*
* @param version The string version for the Key Vault keys service.
*/
ServiceVersion(std::string version) : m_version(std::move(version)) {}

/**
* @brief Enable comparing the ext enum.
*
* @param other Another #ServiceVersion to be compared.
*/
bool operator==(ServiceVersion const& other) const { return m_version == other.m_version; }

/**
* @brief Return the #ServiceVersion string representation.
*
*/
std::string const& ToString() const { return m_version; }

/**
* @brief Use to send request to the 7.2 version of Key Vault service.
*
*/
AZURE_SECURITY_KEYVAULT_SECRETS_DLLEXPORT static const ServiceVersion V7_2;

/**
* @brief Use to send request to the 7.3 version of Key Vault service.
*
*/
AZURE_SECURITY_KEYVAULT_SECRETS_DLLEXPORT static const ServiceVersion V7_3;
};

/**
* @brief Define the options to create an SDK Keys client.
*
Expand All @@ -59,17 +21,13 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Secrets {
* @brief Service Version used.
*
*/
const ServiceVersion Version;
std::string Version;

/**
* @brief Construct a new Secret Client Options object.
*
* @param version Optional version for the client.
*/
SecretClientOptions(ServiceVersion version = ServiceVersion::V7_3)
: Azure::Core::_internal::ClientOptions(), Version(version)
{
}
SecretClientOptions() : Azure::Core::_internal::ClientOptions() { Version = "7.3"; }
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ using namespace Azure::Core::Http::Policies;
using namespace Azure::Core::Http::Policies::_internal;
using namespace Azure::Security::KeyVault::Secrets::_detail;

const ServiceVersion ServiceVersion::V7_3("7.3");
const ServiceVersion ServiceVersion::V7_2("7.2");

std::unique_ptr<RawResponse> SecretClient::SendRequest(
Azure::Core::Http::Request& request,
Azure::Core::Context const& context) const
Expand Down Expand Up @@ -64,9 +61,9 @@ SecretClient::SecretClient(
std::string const& vaultUrl,
std::shared_ptr<Core::Credentials::TokenCredential const> credential,
SecretClientOptions options)
: m_vaultUrl(vaultUrl), m_apiVersion(options.Version.ToString())
: m_vaultUrl(vaultUrl), m_apiVersion(options.Version)
{
auto apiVersion = options.Version.ToString();
auto apiVersion = options.Version;
Azure::Core::Url url(vaultUrl);

std::vector<std::unique_ptr<HttpPolicy>> perRetrypolicies;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,16 @@ TEST(SecretClient, ServiceVersion)
= std::make_shared<Azure::Identity::ClientSecretCredential>("tenantID", "AppId", "SecretId");
{
// 7.3
EXPECT_NO_THROW(
auto options = SecretClientOptions(ServiceVersion::V7_3);
SecretClient SecretClient("http://account.vault.azure.net", credential, options);
EXPECT_EQ(options.Version.ToString(), "7.3"););
EXPECT_NO_THROW(auto options = SecretClientOptions(); SecretClient SecretClient(
"http://account.vault.azure.net", credential, options);
EXPECT_EQ(options.Version, "7.3"););
}
{
// arbitrary version
EXPECT_NO_THROW(
auto options = SecretClientOptions(ServiceVersion("1.0"));
auto options = SecretClientOptions(); options.Version = "1.0";
SecretClient secretClient("http://account.vault.azure.net", credential, options);
EXPECT_EQ(options.Version.ToString(), "1.0"););
EXPECT_EQ(options.Version, "1.0"););
}
}

Expand Down

0 comments on commit 417c7fa

Please sign in to comment.