Api view feedback (#2773)

* first set

* some more

* final set

* formats

* remove friend structs serializers
This commit is contained in:
George Arama 2021-08-20 15:42:47 -07:00 committed by GitHub
parent 8fe306e15f
commit 27dc6bba32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 105 additions and 172 deletions

View File

@ -15,7 +15,7 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Secrets {
* @brief A Deleted Secret consisting of its previous id, attributes and its tags,
* as well as information on when it will be purged.
*/
struct DeletedSecret : public Secret
struct DeletedSecret : public KeyVaultSecret
{
/**
* @brief A Deleted Secret consisting of its previous id, attributes and its tags,
@ -31,7 +31,7 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Secrets {
/**
* @brief The time when the secret was deleted, in UTC.
*/
Azure::DateTime DeletedDate;
Azure::DateTime DeletedOn;
/**
* @brief Default constructor.
@ -43,6 +43,6 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Secrets {
*
* @param name Name of the deleted secret.
*/
DeletedSecret(std::string name) : Secret(std::move(name)) {}
DeletedSecret(std::string name) : KeyVaultSecret(std::move(name)) {}
};
}}}} // namespace Azure::Security::KeyVault::Secrets

View File

@ -20,15 +20,15 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Secrets {
/**
* @brief Represents a long running operation to restore a deleted secret.
*/
class RecoverDeletedSecretOperation final : public Azure::Core::Operation<Secret> {
class RecoverDeletedSecretOperation final : public Azure::Core::Operation<KeyVaultSecret> {
private:
friend class SecretClient;
std::shared_ptr<SecretClient> m_secretClient;
Secret m_value;
KeyVaultSecret m_value;
std::string m_continuationToken;
Azure::Response<Secret> PollUntilDoneInternal(
Azure::Response<KeyVaultSecret> PollUntilDoneInternal(
std::chrono::milliseconds period,
Azure::Core::Context& context) override;
@ -43,7 +43,7 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Secrets {
*/
RecoverDeletedSecretOperation(
std::shared_ptr<SecretClient> secretClient,
Azure::Response<Secret> response);
Azure::Response<KeyVaultSecret> response);
RecoverDeletedSecretOperation(
std::string resumeToken,
@ -65,7 +65,7 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Secrets {
*
* @return A Secret object.
*/
Secret Value() const override { return m_value; }
KeyVaultSecret Value() const override { return m_value; }
/**
* @brief Get an Url as string which can be used to get the status of the operation.

View File

@ -94,7 +94,6 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Secrets {
*/
struct GetPropertiesOfSecretsOptions final
{
Azure::Nullable<size_t> MaxResults;
Azure::Nullable<std::string> NextPageToken;
};
@ -104,7 +103,6 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Secrets {
*/
struct GetPropertiesOfSecretVersionsOptions final
{
Azure::Nullable<size_t> MaxResults;
Azure::Nullable<std::string> NextPageToken;
};
@ -114,7 +112,6 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Secrets {
*/
struct GetDeletedSecretsOptions final
{
Azure::Nullable<size_t> MaxResults;
Azure::Nullable<std::string> NextPageToken;
};
}}}} // namespace Azure::Security::KeyVault::Secrets

View File

@ -10,7 +10,7 @@
#include "azure/keyvault/secrets/keyvault_secret_properties.hpp"
namespace Azure { namespace Security { namespace KeyVault { namespace Secrets {
struct Secret
struct KeyVaultSecret
{
/**
* @brief The name of the secret.
@ -22,7 +22,7 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Secrets {
* @brief The secret value.
*
*/
std::string Value;
Azure::Nullable<std::string> Value;
/**
* @brief The secret id.
@ -40,7 +40,19 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Secrets {
* @brief Construct a new Secret object.
*
*/
Secret() = default;
KeyVaultSecret() = default;
/**
* @brief The vault url of the secret.
*
*/
std::string VaultUrl() { return Properties.VaultUrl; }
/**
* @brief The version of the secret.
*
*/
std::string Version() { return Properties.Version; }
/**
* @brief Construct a new Secret object.
@ -48,7 +60,7 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Secrets {
* @param name The name of the secret.
* @param value The name of the secret.
*/
Secret(std::string const& name, std::string const& value)
KeyVaultSecret(std::string const& name, std::string const& value)
: Name(name), Value(value), Properties(name)
{
if (Name.empty())
@ -56,14 +68,14 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Secrets {
throw std::invalid_argument("Name cannot be empty");
}
if (Value.empty())
if (Value.HasValue() == false || Value.Value().empty())
{
throw std::invalid_argument("Value cannot be empty");
}
};
private:
Secret(std::string name) : Name(std::move(name))
KeyVaultSecret(std::string name) : Name(std::move(name))
{
if (Name.empty())
{

View File

@ -21,7 +21,6 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Secrets {
*/
struct SecretProperties final
{
/**
* @brief Indicate whether the secret is enabled and useable for cryptographic operations.
*
@ -92,7 +91,7 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Secrets {
* backing a certificate, then managed will be true.
*
*/
bool Managed = false;
bool Managed;
/**
* @brief The secret id.

View File

@ -84,7 +84,7 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Secrets {
* @param context The context for the operation can be used for request cancellation.
* @return The Secret wrapped in the Response.
*/
Azure::Response<Secret> GetSecret(
Azure::Response<KeyVaultSecret> GetSecret(
std::string const& name,
GetSecretOptions const& options = GetSecretOptions(),
Azure::Core::Context const& context = Azure::Core::Context()) const;
@ -112,7 +112,7 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Secrets {
* @param context The context for the operation can be used for request cancellation.
* @return The Secret wrapped in the Response.
*/
Azure::Response<Secret> SetSecret(
Azure::Response<KeyVaultSecret> SetSecret(
std::string const& name,
std::string const& value,
Azure::Core::Context const& context = Azure::Core::Context()) const;
@ -126,29 +126,9 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Secrets {
* @param context The context for the operation can be used for request cancellation.
* @return The Secret wrapped in the Response.
*/
Azure::Response<Secret> SetSecret(
Azure::Response<KeyVaultSecret> SetSecret(
std::string const& name,
Secret const& secret,
Azure::Core::Context const& context = Azure::Core::Context()) const;
/**
* @brief Updates the attributes associated with a specified secret in a given key vault.
* The UPDATE operation changes specified attributes of an existing stored secret.
* Attributes that are not specified in the request are left unchanged.
* The value of a secret itself cannot be changed.
* This operation requires the secrets/set permission.
*
* @param name The name of the secret.
* @param options The optional parameters for this request.
* @param properties The properties to update
* @param context The context for the operation can be used for request cancellation.
*
* @return The Secret wrapped in the Response.
*/
Azure::Response<Secret> UpdateSecretProperties(
std::string const& name,
UpdateSecretPropertiesOptions const& options,
SecretProperties const& properties,
KeyVaultSecret const& secret,
Azure::Core::Context const& context = Azure::Core::Context()) const;
/**
@ -158,16 +138,12 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Secrets {
* The value of a secret itself cannot be changed.
* This operation requires the secrets/set permission.
*
* @param name The name of the secret.
* @param version The version of the secret for this request.
* @param properties The properties to update
* @param context The context for the operation can be used for request cancellation.
*
* @return The Secret wrapped in the Response.
*/
Azure::Response<Secret> UpdateSecretProperties(
std::string const& name,
std::string const& version,
Azure::Response<KeyVaultSecret> UpdateSecretProperties(
SecretProperties const& properties,
Azure::Core::Context const& context = Azure::Core::Context()) const;
@ -196,7 +172,7 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Secrets {
*
* @return The Secret wrapped in the Response.
*/
Azure::Response<Secret> RestoreSecretBackup(
Azure::Response<KeyVaultSecret> RestoreSecretBackup(
std::vector<uint8_t> const& backup,
Azure::Core::Context const& context = Azure::Core::Context()) const;

View File

@ -10,7 +10,7 @@
#include "azure/keyvault/secrets/secret_client.hpp"
#include "private/secret_serializers.hpp"
Azure::Response<Secret> RecoverDeletedSecretOperation::PollUntilDoneInternal(
Azure::Response<KeyVaultSecret> RecoverDeletedSecretOperation::PollUntilDoneInternal(
std::chrono::milliseconds period,
Azure::Core::Context& context)
{
@ -25,7 +25,7 @@ Azure::Response<Secret> RecoverDeletedSecretOperation::PollUntilDoneInternal(
std::this_thread::sleep_for(period);
}
return Azure::Response<Secret>(
return Azure::Response<KeyVaultSecret>(
m_value, std::make_unique<Azure::Core::Http::RawResponse>(*m_rawResponse));
}
@ -68,7 +68,7 @@ std::unique_ptr<Azure::Core::Http::RawResponse> RecoverDeletedSecretOperation::P
RecoverDeletedSecretOperation::RecoverDeletedSecretOperation(
std::shared_ptr<SecretClient> secretClient,
Azure::Response<Secret> response)
Azure::Response<KeyVaultSecret> response)
: m_secretClient(secretClient)
{
m_value = response.Value;

View File

@ -23,18 +23,18 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Secrets {
struct SecretSerializer final
{
// Creates a new key based on a name and an HTTP raw response.
static Secret Deserialize(
static KeyVaultSecret Deserialize(
std::string const& name,
Azure::Core::Http::RawResponse const& rawResponse);
// Create from HTTP raw response only.
static Secret Deserialize(Azure::Core::Http::RawResponse const& rawResponse);
static KeyVaultSecret Deserialize(Azure::Core::Http::RawResponse const& rawResponse);
// Updates a Key based on an HTTP raw response.
static void Deserialize(Secret& key, Azure::Core::Http::RawResponse const& rawResponse);
static void Deserialize(KeyVaultSecret& key, Azure::Core::Http::RawResponse const& rawResponse);
// Serializes a key vault secret for set action
static std::string Serialize(Secret const& parameters);
static std::string Serialize(KeyVaultSecret const& parameters);
// Extract the host out of the URL (with port if available)
static std::string GetUrlAuthorityWithScheme(Azure::Core::Url const& url)
@ -111,14 +111,14 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Secrets {
static std::string Serialize(std::vector<uint8_t> const& backup);
};
class SecretPropertiesPagedResultSerializer final {
public:
struct SecretPropertiesPagedResultSerializer final
{
static SecretPropertiesPagedResponse Deserialize(
Azure::Core::Http::RawResponse const& rawResponse);
};
class DeletedSecretPagedResultSerializer final {
public:
struct DeletedSecretPagedResultSerializer final
{
static DeletedSecretPagedResponse Deserialize(
Azure::Core::Http::RawResponse const& rawResponse);
};

View File

@ -77,12 +77,12 @@ SecretClient::SecretClient(
options, TelemetryName, apiVersion, std::move(perRetrypolicies), {}));
}
Azure::Response<Secret> SecretClient::GetSecret(
Azure::Response<KeyVaultSecret> SecretClient::GetSecret(
std::string const& name,
GetSecretOptions const& options,
Azure::Core::Context const& context) const
{
return m_protocolClient->SendRequest<Secret>(
return m_protocolClient->SendRequest<KeyVaultSecret>(
context,
Azure::Core::Http::HttpMethod::Get,
[&name](Azure::Core::Http::RawResponse const& rawResponse) {
@ -104,21 +104,21 @@ Azure::Response<DeletedSecret> SecretClient::GetDeletedSecret(
{_detail::DeletedSecretPath, name});
}
Azure::Response<Secret> SecretClient::SetSecret(
Azure::Response<KeyVaultSecret> SecretClient::SetSecret(
std::string const& name,
std::string const& value,
Azure::Core::Context const& context) const
{
Secret setParameters(name, value);
KeyVaultSecret setParameters(name, value);
return SetSecret(name, setParameters, context);
}
Azure::Response<Secret> SecretClient::SetSecret(
Azure::Response<KeyVaultSecret> SecretClient::SetSecret(
std::string const& name,
Secret const& secret,
KeyVaultSecret const& secret,
Azure::Core::Context const& context) const
{
return m_protocolClient->SendRequest<Secret>(
return m_protocolClient->SendRequest<KeyVaultSecret>(
context,
Azure::Core::Http::HttpMethod::Put,
[&secret]() { return _detail::SecretSerializer::Serialize(secret); },
@ -128,32 +128,18 @@ Azure::Response<Secret> SecretClient::SetSecret(
{_detail::SecretPath, name});
}
Azure::Response<Secret> SecretClient::UpdateSecretProperties(
std::string const& name,
UpdateSecretPropertiesOptions const& options,
Azure::Response<KeyVaultSecret> SecretClient::UpdateSecretProperties(
SecretProperties const& properties,
Azure::Core::Context const& context) const
{
return m_protocolClient->SendRequest<Secret>(
return m_protocolClient->SendRequest<KeyVaultSecret>(
context,
Azure::Core::Http::HttpMethod::Patch,
[&properties]() { return _detail::SecretPropertiesSerializer::Serialize(properties); },
[&name](Azure::Core::Http::RawResponse const& rawResponse) {
return _detail::SecretSerializer::Deserialize(name, rawResponse);
[&properties](Azure::Core::Http::RawResponse const& rawResponse) {
return _detail::SecretSerializer::Deserialize(properties.Name, rawResponse);
},
{_detail::SecretPath, name, options.Version});
}
Azure::Response<Secret> SecretClient::UpdateSecretProperties(
std::string const& name,
std::string const& version,
SecretProperties const& properties,
Azure::Core::Context const& context) const
{
UpdateSecretPropertiesOptions options;
options.Version = version;
return UpdateSecretProperties(name, options, properties, context);
{_detail::SecretPath, properties.Name, properties.Version});
}
Azure::Response<BackupSecretResult> SecretClient::BackupSecret(
@ -169,11 +155,11 @@ Azure::Response<BackupSecretResult> SecretClient::BackupSecret(
{_detail::SecretPath, name, _detail::BackupSecretPath});
}
Azure::Response<Secret> SecretClient::RestoreSecretBackup(
Azure::Response<KeyVaultSecret> SecretClient::RestoreSecretBackup(
std::vector<uint8_t> const& backup,
Azure::Core::Context const& context) const
{
return m_protocolClient->SendRequest<Secret>(
return m_protocolClient->SendRequest<KeyVaultSecret>(
context,
Azure::Core::Http::HttpMethod::Post,
[&backup]() { return _detail::RestoreSecretSerializer::Serialize(backup); },
@ -214,7 +200,7 @@ Azure::Security::KeyVault::Secrets::RecoverDeletedSecretOperation SecretClient::
{
return Azure::Security::KeyVault::Secrets::RecoverDeletedSecretOperation(
std::make_shared<SecretClient>(*this),
m_protocolClient->SendRequest<Secret>(
m_protocolClient->SendRequest<KeyVaultSecret>(
context,
Azure::Core::Http::HttpMethod::Post,
[&name](Azure::Core::Http::RawResponse const& rawResponse) {
@ -229,13 +215,6 @@ SecretPropertiesPagedResponse SecretClient::GetPropertiesOfSecrets(
{
auto const request
= BuildRequestFromContinuationToken(options.NextPageToken, {_detail::SecretPath});
size_t maxResults = _detail::PagedMaxResults;
if (options.MaxResults.HasValue() && (options.MaxResults.Value() <= _detail::PagedMaxResults))
{
maxResults = options.MaxResults.Value();
}
request.Query->emplace(_detail::PagedMaxResultsName, std::to_string(maxResults));
auto response = m_protocolClient->SendRequest<SecretPropertiesPagedResponse>(
context,
@ -259,13 +238,6 @@ SecretPropertiesPagedResponse SecretClient::GetPropertiesOfSecretsVersions(
{
auto const request = BuildRequestFromContinuationToken(
options.NextPageToken, {_detail::SecretPath, name, _detail::VersionsName});
size_t maxResults = _detail::PagedMaxResults;
if (options.MaxResults.HasValue() && (options.MaxResults.Value() <= _detail::PagedMaxResults))
{
maxResults = options.MaxResults.Value();
}
request.Query->emplace(_detail::PagedMaxResultsName, std::to_string(maxResults));
auto response = m_protocolClient->SendRequest<SecretPropertiesPagedResponse>(
context,
@ -289,13 +261,6 @@ DeletedSecretPagedResponse SecretClient::GetDeletedSecrets(
{
auto const request
= BuildRequestFromContinuationToken(options.NextPageToken, {_detail::DeletedSecretPath});
size_t maxResults = _detail::PagedMaxResults;
if (options.MaxResults.HasValue() && (options.MaxResults.Value() <= _detail::PagedMaxResults))
{
maxResults = options.MaxResults.Value();
}
request.Query->emplace(_detail::PagedMaxResultsName, std::to_string(maxResults));
auto response = m_protocolClient->SendRequest<DeletedSecretPagedResponse>(
context,

View File

@ -20,27 +20,27 @@ using namespace Azure::Security::KeyVault::Secrets;
using namespace Azure::Security::KeyVault::Secrets::_detail;
// Creates a new key based on a name and an HTTP raw response.
Secret SecretSerializer::Deserialize(
KeyVaultSecret SecretSerializer::Deserialize(
std::string const& name,
Azure::Core::Http::RawResponse const& rawResponse)
{
Secret secret;
KeyVaultSecret secret;
secret.Name = name;
_detail::SecretSerializer::Deserialize(secret, rawResponse);
return secret;
}
// Create from HTTP raw response only.
Secret SecretSerializer::Deserialize(Azure::Core::Http::RawResponse const& rawResponse)
KeyVaultSecret SecretSerializer::Deserialize(Azure::Core::Http::RawResponse const& rawResponse)
{
Secret secret;
KeyVaultSecret secret;
_detail::SecretSerializer::Deserialize(secret, rawResponse);
return secret;
}
// Updates a Key based on an HTTP raw response.
void SecretSerializer::Deserialize(
Secret& secret,
KeyVaultSecret& secret,
Azure::Core::Http::RawResponse const& rawResponse)
{
auto const& body = rawResponse.GetBody();
@ -149,19 +149,17 @@ void DeletedSecretSerializer::Deserialize(
secret.RecoveryId = jsonParser[_detail::RecoveryIdPropertyName];
secret.ScheduledPurgeDate = PosixTimeConverter::PosixTimeToDateTime(
jsonParser[_detail::ScheduledPurgeDatePropertyName]);
secret.DeletedDate
secret.DeletedOn
= PosixTimeConverter::PosixTimeToDateTime(jsonParser[_detail::DeletedDatePropertyName]);
}
// serializes a set secret parameters object
std::string SecretSerializer::Serialize(Secret const& parameters)
std::string SecretSerializer::Serialize(KeyVaultSecret const& parameters)
{
json payload;
// value is required
payload[ValuePropertyName] = parameters.Value;
JsonOptional::SetFromNullable(parameters.Value, payload, _detail::ValuePropertyName);
// all else is optional
JsonOptional::SetFromNullable(
parameters.Properties.ContentType, payload, _detail::ContentTypePropertyName);
@ -409,7 +407,7 @@ DeletedSecretPagedResponse DeletedSecretPagedResultSerializer::Deserialize(
item.RecoveryId = secretProperties[_detail::RecoveryIdPropertyName];
item.ScheduledPurgeDate = PosixTimeConverter::PosixTimeToDateTime(
secretProperties[_detail::ScheduledPurgeDatePropertyName]);
item.DeletedDate = PosixTimeConverter::PosixTimeToDateTime(
item.DeletedOn = PosixTimeConverter::PosixTimeToDateTime(
secretProperties[_detail::DeletedDatePropertyName]);
result.Items.emplace_back(item);

View File

@ -46,18 +46,15 @@ int main()
secretClient.SetSecret(secretName, secretValue);
// get secret
Secret secret = secretClient.GetSecret(secretName).Value;
KeyVaultSecret secret = secretClient.GetSecret(secretName).Value;
std::cout << "Secret is returned with name " << secret.Name << " and value " << secret.Value
<< std::endl;
std::cout << "Secret is returned with name " << secret.Name << " and value "
<< secret.Value.Value() << std::endl;
// change one of the properties
secret.Properties.ContentType = "my content";
// update the secret
Secret updatedSecret
= secretClient
.UpdateSecretProperties(secret.Name, secret.Properties.Version, secret.Properties)
.Value;
KeyVaultSecret updatedSecret = secretClient.UpdateSecretProperties(secret.Properties).Value;
std::cout << "Secret's content type is now " << updatedSecret.Properties.ContentType.Value()
<< std::endl;

View File

@ -26,7 +26,7 @@
using namespace Azure::Security::KeyVault::Secrets;
using namespace std::chrono_literals;
void AssertSecretsEqual(Secret const& expected, Secret const& actual);
void AssertSecretsEqual(KeyVaultSecret const& expected, KeyVaultSecret const& actual);
int main()
{
@ -48,10 +48,10 @@ int main()
secretClient.SetSecret(secretName, secretValue);
// get secret
Secret secret = secretClient.GetSecret(secretName).Value;
KeyVaultSecret secret = secretClient.GetSecret(secretName).Value;
std::cout << "Secret is returned with name " << secret.Name << " and value " << secret.Value
<< std::endl;
std::cout << "Secret is returned with name " << secret.Name << " and value "
<< secret.Value.Value() << std::endl;
size_t backUpSize = 0;
{
@ -114,7 +114,7 @@ int main()
return 0;
}
void AssertSecretsEqual(Secret const& expected, Secret const& actual)
void AssertSecretsEqual(KeyVaultSecret const& expected, KeyVaultSecret const& actual)
{
#if defined(NDEBUG)
// Use (void) to silence unused warnings.

View File

@ -25,7 +25,7 @@
using namespace Azure::Security::KeyVault::Secrets;
using namespace std::chrono_literals;
void AssertSecretsEqual(Secret const& expected, Secret const& actual);
void AssertSecretsEqual(KeyVaultSecret const& expected, KeyVaultSecret const& actual);
int main()
{
@ -48,10 +48,10 @@ int main()
secretClient.SetSecret(secretName, secretValue);
// get secret
Secret secret = secretClient.GetSecret(secretName).Value;
KeyVaultSecret secret = secretClient.GetSecret(secretName).Value;
std::cout << "Secret is returned with name " << secret.Name << " and value " << secret.Value
<< std::endl;
std::cout << "Secret is returned with name " << secret.Name << " and value "
<< secret.Value.Value() << std::endl;
// start deleting the secret
DeleteSecretOperation operation = secretClient.StartDeleteSecret(secret.Name);
@ -64,7 +64,7 @@ int main()
= secretClient.StartRecoverDeletedSecret(secret.Name);
// poll until done
Secret restoredSecret = recoverOperation.PollUntilDone(2s).Value;
KeyVaultSecret restoredSecret = recoverOperation.PollUntilDone(2s).Value;
AssertSecretsEqual(secret, restoredSecret);
@ -89,7 +89,7 @@ int main()
return 0;
}
void AssertSecretsEqual(Secret const& expected, Secret const& actual)
void AssertSecretsEqual(KeyVaultSecret const& expected, KeyVaultSecret const& actual)
{
#if defined(NDEBUG)
// Use (void) to silence unused warnings.

View File

@ -44,10 +44,10 @@ int main()
try
{
// create secret
Secret secret1 = secretClient.SetSecret(secretName, secretValue).Value;
Secret secret2 = secretClient.SetSecret(secretName2, secretValue).Value;
KeyVaultSecret secret1 = secretClient.SetSecret(secretName, secretValue).Value;
KeyVaultSecret secret2 = secretClient.SetSecret(secretName2, secretValue).Value;
std::cout << "Secret1 Version : " << secret1.Properties.Version << std::endl;
std::cout << "Secret1 Version : " << secret1.Version() << std::endl;
// get properties of secrets
for (auto secrets = secretClient.GetPropertiesOfSecrets(); secrets.HasPage();

View File

@ -14,7 +14,7 @@ TEST(KeyVaultSecretSerializer, GetClientDeserializePartial1)
{
auto response = Helpers::GetPartialResponse();
Secret secret = _detail::SecretSerializer::Deserialize(response);
KeyVaultSecret secret = _detail::SecretSerializer::Deserialize(response);
Helpers::RunPartialExpect(secret);
}
@ -22,7 +22,7 @@ TEST(KeyVaultSecretSerializer, GetClientDeserializePartial2)
{
auto response = Helpers::GetPartialResponse();
Secret secret = _detail::SecretSerializer::Deserialize("name1", response);
KeyVaultSecret secret = _detail::SecretSerializer::Deserialize("name1", response);
Helpers::RunPartialExpect(secret);
}
@ -31,7 +31,7 @@ TEST(KeyVaultSecretSerializer, GetClientDeserializePartial3)
{
auto response = Helpers::GetPartialResponse();
Secret secret = Secret("name2", "a");
KeyVaultSecret secret = KeyVaultSecret("name2", "a");
_detail::SecretSerializer::Deserialize(secret, response);
Helpers::RunPartialExpect(secret);
@ -41,7 +41,7 @@ TEST(KeyVaultSecretSerializer, GetClientdeserializeFull1)
{
auto response = Helpers::GetFullResponse();
Secret secret = _detail::SecretSerializer::Deserialize(response);
KeyVaultSecret secret = _detail::SecretSerializer::Deserialize(response);
Helpers::RunFullExpect(secret);
}
@ -49,7 +49,7 @@ TEST(KeyVaultSecretSerializer, GetClientdeserializeFull2)
{
auto response = Helpers::GetFullResponse();
Secret secret = _detail::SecretSerializer::Deserialize("name1", response);
KeyVaultSecret secret = _detail::SecretSerializer::Deserialize("name1", response);
Helpers::RunFullExpect(secret);
}
@ -58,7 +58,7 @@ TEST(KeyVaultSecretSerializer, GetClientdeserializeFull3)
{
auto response = Helpers::GetFullResponse();
Secret secret = Secret("name2", "a");
KeyVaultSecret secret = KeyVaultSecret("name2", "a");
_detail::SecretSerializer::Deserialize(secret, response);
Helpers::RunFullExpect(secret);

View File

@ -23,6 +23,7 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Secrets {
constexpr static const uint8_t responseBody[] = R"json({
"value": "mysecretvalue",
"id": "https://myvault.vault.azure.net/secrets/mysecretname/4387e9f3d6e14c459867679a90fd0f79",
"managed":true,
"attributes": {
"enabled": true,
"created": 1493938410,
@ -102,11 +103,11 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Secrets {
return response;
}
static void RunPartialExpect(Secret& secret, bool expectValue = true)
static void RunPartialExpect(KeyVaultSecret& secret, bool expectValue = true)
{
if (expectValue)
{
EXPECT_EQ(secret.Value, "mysecretvalue");
EXPECT_EQ(secret.Value.Value(), "mysecretvalue");
}
EXPECT_EQ(secret.Name, "mysecretname");
@ -117,17 +118,17 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Secrets {
secret.Id,
"https://myvault.vault.azure.net/secrets/mysecretname/"
"4387e9f3d6e14c459867679a90fd0f79");
EXPECT_EQ(secret.Properties.Managed, true);
EXPECT_EQ(secret.Properties.KeyId.HasValue(), false);
EXPECT_EQ(secret.Properties.Managed, false);
EXPECT_EQ(secret.Properties.UpdatedOn.HasValue(), true);
EXPECT_EQ(secret.Properties.CreatedOn.HasValue(), true);
}
static void RunFullExpect(Secret& secret, bool expectValue = true)
static void RunFullExpect(KeyVaultSecret& secret, bool expectValue = true)
{
if (expectValue)
{
EXPECT_EQ(secret.Value, "mysecretvalue");
EXPECT_EQ(secret.Value.Value(), "mysecretvalue");
EXPECT_EQ(secret.Properties.ContentType.Value(), "ct");
EXPECT_EQ(secret.Properties.KeyId.Value(), "kid");
}
@ -151,7 +152,7 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Secrets {
EXPECT_EQ(
secret.RecoveryId, "https://myvault.vault.azure.net/deletedsecrets/GetDeletedSecretTest");
EXPECT_EQ(secret.ScheduledPurgeDate.ToString(), "2017-08-02T22:53:53Z");
EXPECT_EQ(secret.DeletedDate.ToString(), "2017-05-04T22:53:53Z");
EXPECT_EQ(secret.DeletedOn.ToString(), "2017-05-04T22:53:53Z");
}
};
}}}}} // namespace Azure::Security::KeyVault::Secrets::_test

View File

@ -17,20 +17,20 @@ using namespace Azure::Core::Json::_internal;
TEST(KeyvaultSecretSetParametersSerializer, SetValue)
{
Secret params("name", "value");
KeyVaultSecret params("name", "value");
std::string result = SecretSerializer::Serialize(params);
auto jsonParser = json::parse(result);
EXPECT_EQ(jsonParser[ValuePropertyName], params.Value);
EXPECT_EQ(jsonParser[ValuePropertyName], params.Value.Value());
EXPECT_EQ(jsonParser[IdPropertyName], nullptr);
EXPECT_EQ(jsonParser[ContentTypePropertyName], nullptr);
}
TEST(KeyvaultSecretSetParametersSerializer, SetValueCT)
{
Secret params("name", "value");
KeyVaultSecret params("name", "value");
params.Properties.ContentType = "ct";
@ -38,13 +38,13 @@ TEST(KeyvaultSecretSetParametersSerializer, SetValueCT)
auto jsonParser = json::parse(result);
EXPECT_EQ(jsonParser[ValuePropertyName], params.Value);
EXPECT_EQ(jsonParser[ValuePropertyName], params.Value.Value());
EXPECT_EQ(jsonParser[ContentTypePropertyName], params.Properties.ContentType.Value());
}
TEST(KeyvaultSecretSetParametersSerializer, SetValueCTAttrTag)
{
Secret params("name", "value");
KeyVaultSecret params("name", "value");
params.Properties.ContentType = "ct";
params.Properties.Enabled = true;
@ -54,7 +54,7 @@ TEST(KeyvaultSecretSetParametersSerializer, SetValueCTAttrTag)
auto jsonParser = json::parse(result);
EXPECT_EQ(jsonParser[ValuePropertyName], params.Value);
EXPECT_EQ(jsonParser[ValuePropertyName], params.Value.Value());
EXPECT_EQ(jsonParser[AttributesPropertyName][TagsPropertyName]["a"], "b");
EXPECT_EQ(jsonParser[AttributesPropertyName][EnabledPropertyName], true);
EXPECT_EQ(jsonParser[ContentTypePropertyName], params.Properties.ContentType.Value());

View File

@ -16,7 +16,6 @@ TEST(SecretPropertiesSerializer, Serialize1)
properties.ContentType = "contentType";
properties.Enabled = true;
properties.RecoverableDays = 5;
auto serialized = _detail::SecretPropertiesSerializer::Serialize(properties);
@ -26,9 +25,6 @@ TEST(SecretPropertiesSerializer, Serialize1)
EXPECT_EQ(
properties.Enabled.Value(),
jsonParser[_detail::AttributesPropertyName][_detail::EnabledPropertyName]);
EXPECT_EQ(
properties.RecoverableDays.Value(),
jsonParser[_detail::AttributesPropertyName][_detail::RecoverableDaysPropertyName]);
}
TEST(SecretPropertiesSerializer, Serialize2)
@ -37,7 +33,6 @@ TEST(SecretPropertiesSerializer, Serialize2)
properties.ContentType = "contentType";
properties.Enabled = true;
properties.RecoverableDays = 5;
properties.Tags.emplace("a", "b");
auto serialized = _detail::SecretPropertiesSerializer::Serialize(properties);
@ -48,9 +43,6 @@ TEST(SecretPropertiesSerializer, Serialize2)
EXPECT_EQ(
properties.Enabled.Value(),
jsonParser[_detail::AttributesPropertyName][_detail::EnabledPropertyName]);
EXPECT_EQ(
properties.RecoverableDays.Value(),
jsonParser[_detail::AttributesPropertyName][_detail::RecoverableDaysPropertyName]);
EXPECT_EQ(properties.Tags["a"], jsonParser[_detail::TagsPropertyName]["a"]);
}
@ -60,7 +52,6 @@ TEST(SecretPropertiesSerializer, Serialize3)
properties.ContentType = "contentType";
properties.Enabled = true;
properties.RecoverableDays = 5;
properties.Tags.emplace("a", "b");
properties.Tags.emplace("c", "d");
@ -72,9 +63,6 @@ TEST(SecretPropertiesSerializer, Serialize3)
EXPECT_EQ(
properties.Enabled.Value(),
jsonParser[_detail::AttributesPropertyName][_detail::EnabledPropertyName]);
EXPECT_EQ(
properties.RecoverableDays.Value(),
jsonParser[_detail::AttributesPropertyName][_detail::RecoverableDaysPropertyName]);
for (auto kvp : properties.Tags)
{
EXPECT_EQ(properties.Tags[kvp.first], jsonParser[_detail::TagsPropertyName][kvp.first]);