Start delete secret (#2695)
* first stab * hmmmm * working * forgot include * cleanup * remove pragma * PR comments * pedantic semicolon * PR comments
This commit is contained in:
parent
2b63bc6536
commit
650a74ca62
@ -35,6 +35,8 @@ set(
|
||||
inc/azure/keyvault/keyvault_secrets.hpp
|
||||
inc/azure/keyvault/secrets/keyvault_deleted_secret.hpp
|
||||
inc/azure/keyvault/secrets/keyvault_backup_secret.hpp
|
||||
inc/azure/keyvault/secrets/keyvault_operations.hpp
|
||||
inc/azure/keyvault/secrets/keyvault_options.hpp
|
||||
)
|
||||
|
||||
set(
|
||||
@ -46,6 +48,7 @@ set(
|
||||
src/keyvault_protocol.cpp
|
||||
src/secret_client.cpp
|
||||
src/secret_serializers.cpp
|
||||
src/keyvault_operations.cpp
|
||||
)
|
||||
|
||||
add_library(azure-security-keyvault-secrets ${AZURE_SECURITY_KEYVAULT_SECRETS_HEADER} ${AZURE_SECURITY_KEYVAULT_SECRETS_SOURCE})
|
||||
|
||||
@ -11,6 +11,8 @@
|
||||
#include "azure/keyvault/secrets/dll_import_export.hpp"
|
||||
#include "azure/keyvault/secrets/keyvault_backup_secret.hpp"
|
||||
#include "azure/keyvault/secrets/keyvault_deleted_secret.hpp"
|
||||
#include "azure/keyvault/secrets/keyvault_operations.hpp"
|
||||
#include "azure/keyvault/secrets/keyvault_options.hpp"
|
||||
#include "azure/keyvault/secrets/keyvault_secret.hpp"
|
||||
#include "azure/keyvault/secrets/keyvault_secret_properties.hpp"
|
||||
#include "azure/keyvault/secrets/secret_client.hpp"
|
||||
|
||||
@ -0,0 +1,175 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
/**
|
||||
* @brief Provides a wrapper class for the Azure Core Operation
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "azure/keyvault/secrets/keyvault_deleted_secret.hpp"
|
||||
#include "azure/keyvault/secrets/keyvault_secret.hpp"
|
||||
#include <azure/core/http/http.hpp>
|
||||
#include <azure/core/operation.hpp>
|
||||
#include <azure/core/operation_status.hpp>
|
||||
#include <azure/core/response.hpp>
|
||||
#include <thread>
|
||||
|
||||
namespace Azure { namespace Security { namespace KeyVault { namespace Secrets {
|
||||
class SecretClient;
|
||||
/**
|
||||
* @brief Represents a long running operation to restore a deleted secret.
|
||||
*/
|
||||
class KeyVaultRestoreDeletedSecretOperation final
|
||||
: public Azure::Core::Operation<KeyVaultSecret> {
|
||||
|
||||
private:
|
||||
friend class SecretClient;
|
||||
std::shared_ptr<SecretClient> m_secretClient;
|
||||
KeyVaultSecret m_value;
|
||||
std::string m_continuationToken;
|
||||
|
||||
Azure::Response<KeyVaultSecret> PollUntilDoneInternal(
|
||||
std::chrono::milliseconds period,
|
||||
Azure::Core::Context& context) override;
|
||||
|
||||
std::unique_ptr<Azure::Core::Http::RawResponse> PollInternal(
|
||||
Azure::Core::Context const& context) override;
|
||||
|
||||
/*
|
||||
* Only friend classes are permitted to construct an Operation. This is because a
|
||||
* KeyVaultPipelne is required and it is not exposed to customers.
|
||||
*
|
||||
* Since C++ doesn't offer `internal` access, we use friends-only instead.
|
||||
*/
|
||||
KeyVaultRestoreDeletedSecretOperation(
|
||||
std::shared_ptr<SecretClient> secretClient,
|
||||
Azure::Response<KeyVaultSecret> response);
|
||||
|
||||
KeyVaultRestoreDeletedSecretOperation(
|
||||
std::string resumeToken,
|
||||
std::shared_ptr<SecretClient> secretClient);
|
||||
|
||||
/**
|
||||
* @brief Get the #Azure::Core::Http::RawResponse of the operation request.
|
||||
* @return A reference to an #Azure::Core::Http::RawResponse.
|
||||
* @note Does not give up ownership of the RawResponse.
|
||||
*/
|
||||
Azure::Core::Http::RawResponse const& GetRawResponseInternal() const override
|
||||
{
|
||||
return *m_rawResponse;
|
||||
}
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief Get the #Azure::Security::KeyVault::Secrets::KeyVaultSecret object.
|
||||
*
|
||||
* @return A KeyVaultSecret object.
|
||||
*/
|
||||
KeyVaultSecret Value() const override { return m_value; }
|
||||
|
||||
/**
|
||||
* @brief Get an Url as string which can be used to get the status of the operation.
|
||||
*
|
||||
* @return std::string
|
||||
*/
|
||||
std::string GetResumeToken() const override { return m_continuationToken; }
|
||||
|
||||
/**
|
||||
* @brief Create a #KeyVaultRestoreDeletedSecretOperation from the \p resumeToken fetched from
|
||||
* another `Operation<T>`, updated to the the latest operation status.
|
||||
*
|
||||
* @remark After the operation is initialized, it is used to poll the last update from the
|
||||
* server using the \p context.
|
||||
*
|
||||
* @param resumeToken A previously generated token used to resume the polling of the
|
||||
* operation.
|
||||
* @param client A #secretClient that is used for getting status updates.
|
||||
* @param context A #Azure::Core::Context controlling the request lifetime.
|
||||
* @return KeyVaultRestoreDeletedSecretOperation
|
||||
*/
|
||||
static KeyVaultRestoreDeletedSecretOperation CreateFromResumeToken(
|
||||
std::string const& resumeToken,
|
||||
SecretClient const& client,
|
||||
Azure::Core::Context const& context = Azure::Core::Context());
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Represents a delete secret long running operation
|
||||
*/
|
||||
class KeyVaultDeleteSecretOperation final : public Azure::Core::Operation<KeyVaultDeletedSecret> {
|
||||
|
||||
private:
|
||||
friend class SecretClient;
|
||||
std::shared_ptr<SecretClient> m_secretClient;
|
||||
KeyVaultDeletedSecret m_value;
|
||||
std::string m_continuationToken;
|
||||
|
||||
Azure::Response<KeyVaultDeletedSecret> PollUntilDoneInternal(
|
||||
std::chrono::milliseconds period,
|
||||
Azure::Core::Context& context) override;
|
||||
|
||||
std::unique_ptr<Azure::Core::Http::RawResponse> PollInternal(
|
||||
Azure::Core::Context const& context) override;
|
||||
|
||||
/*
|
||||
* Only friend classes are permitted to call the constructor . This is because a
|
||||
* KeyVaultPipelne is required and it is not exposed to customers.
|
||||
*
|
||||
* Since C++ doesn't offer `internal` access, we use friends-only instead.
|
||||
*/
|
||||
KeyVaultDeleteSecretOperation(
|
||||
std::shared_ptr<SecretClient> secretClient,
|
||||
Azure::Response<KeyVaultDeletedSecret> response);
|
||||
|
||||
KeyVaultDeleteSecretOperation(
|
||||
std::string resumeToken,
|
||||
std::shared_ptr<SecretClient> secretClient);
|
||||
|
||||
/**
|
||||
* @brief Get the #Azure::Core::Http::RawResponse of the operation request.
|
||||
* @return A reference to an #Azure::Core::Http::RawResponse.
|
||||
* @note Does not give up ownership of the RawResponse.
|
||||
*/
|
||||
Azure::Core::Http::RawResponse const& GetRawResponseInternal() const override
|
||||
{
|
||||
return *m_rawResponse;
|
||||
}
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief Get the #Azure::Security::KeyVault::Secrets::KeyVaultDeletedSecret object.
|
||||
*
|
||||
* @remark The deleted secret contains the recovery id if the key can be recovered.
|
||||
*
|
||||
* @return A deleted secret object.
|
||||
*/
|
||||
KeyVaultDeletedSecret Value() const override { return m_value; }
|
||||
|
||||
/**
|
||||
* @brief Get an Url as string which can be used to get the status of the delete secret
|
||||
* operation.
|
||||
*
|
||||
* @return std::string
|
||||
*/
|
||||
std::string GetResumeToken() const override { return m_continuationToken; }
|
||||
|
||||
/**
|
||||
* @brief Create a #KeyVaultDeleteSecretOperation from the \p resumeToken fetched from another
|
||||
* `Operation<T>`, updated to the the latest operation status.
|
||||
*
|
||||
* @remark After the operation is initialized, it is used to poll the last update from the
|
||||
* server using the \p context.
|
||||
*
|
||||
* @param resumeToken A previously generated token used to resume the polling of the
|
||||
* operation.
|
||||
* @param client A #secretClient that is used for getting status updates.
|
||||
* @param context A #Azure::Core::Context controlling the request lifetime.
|
||||
* @return KeyVaultDeleteSecretOperation
|
||||
*/
|
||||
static KeyVaultDeleteSecretOperation CreateFromResumeToken(
|
||||
std::string const& resumeToken,
|
||||
SecretClient const& client,
|
||||
Azure::Core::Context const& context = Azure::Core::Context());
|
||||
};
|
||||
}}}} // namespace Azure::Security::KeyVault::Secrets
|
||||
@ -0,0 +1,90 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Keyvault Secret actions options
|
||||
*/
|
||||
#pragma once
|
||||
#include "azure/keyvault/secrets/dll_import_export.hpp"
|
||||
#include <azure/core/internal/client_options.hpp>
|
||||
|
||||
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 Define the options to create an SDK Keys client.
|
||||
*
|
||||
*/
|
||||
struct SecretClientOptions final : public Azure::Core::_internal::ClientOptions
|
||||
{
|
||||
ServiceVersion Version;
|
||||
|
||||
/**
|
||||
* @brief Construct a new Secret Client Options object.
|
||||
*
|
||||
* @param version Optional version for the client.
|
||||
*/
|
||||
SecretClientOptions(ServiceVersion version = ServiceVersion::V7_2)
|
||||
: Azure::Core::_internal::ClientOptions(), Version(version)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Optional parameters for SecretClient::GetSecret
|
||||
*
|
||||
*/
|
||||
struct GetSecretOptions final
|
||||
{
|
||||
/**
|
||||
* @brief Specify the secret version to get.
|
||||
*
|
||||
*/
|
||||
std::string Version;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Optional parameters for SecretClient::UpdateSecretParameters
|
||||
*
|
||||
*/
|
||||
struct UpdateSecretPropertiesOptions final
|
||||
{
|
||||
/**
|
||||
* @brief Specify the secret version to update.
|
||||
*
|
||||
*/
|
||||
std::string Version;
|
||||
};
|
||||
}}}} // namespace Azure::Security::KeyVault::Secrets
|
||||
@ -10,12 +10,13 @@
|
||||
|
||||
#include "azure/keyvault/secrets/keyvault_backup_secret.hpp"
|
||||
#include "azure/keyvault/secrets/keyvault_deleted_secret.hpp"
|
||||
#include "azure/keyvault/secrets/keyvault_operations.hpp"
|
||||
#include "azure/keyvault/secrets/keyvault_options.hpp"
|
||||
#include "azure/keyvault/secrets/keyvault_secret.hpp"
|
||||
#include "dll_import_export.hpp"
|
||||
#include <azure/core/http/http.hpp>
|
||||
#include <azure/core/internal/http/pipeline.hpp>
|
||||
#include <azure/core/response.hpp>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
|
||||
@ -25,83 +26,6 @@ namespace Azure { namespace Security { namespace KeyVault { namespace _detail {
|
||||
|
||||
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 Define the options to create an SDK Keys client.
|
||||
*
|
||||
*/
|
||||
struct SecretClientOptions final : public Azure::Core::_internal::ClientOptions
|
||||
{
|
||||
ServiceVersion Version;
|
||||
|
||||
/**
|
||||
* @brief Construct a new Secret Client Options object.
|
||||
*
|
||||
* @param version Optional version for the client.
|
||||
*/
|
||||
SecretClientOptions(ServiceVersion version = ServiceVersion::V7_2)
|
||||
: Azure::Core::_internal::ClientOptions(), Version(version)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Optional parameters for SecretClient::GetSecret
|
||||
*
|
||||
*/
|
||||
struct GetSecretOptions final
|
||||
{
|
||||
/**
|
||||
* @brief Specify the secret version to get.
|
||||
*
|
||||
*/
|
||||
std::string Version;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Optional parameters for SecretClient::UpdateSecretParameters
|
||||
*
|
||||
*/
|
||||
struct UpdateSecretPropertiesOptions final
|
||||
{
|
||||
/**
|
||||
* @brief Specify the secret version to update.
|
||||
*
|
||||
*/
|
||||
std::string Version;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Define a model for a purged key.
|
||||
*
|
||||
@ -153,7 +77,7 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Secrets {
|
||||
* This operation is applicable to any secret stored in Azure Key Vault.
|
||||
* This operation requires the secrets/get permission.
|
||||
*
|
||||
* @param name The name of the secret<span class="x x-first x-last">.</span>
|
||||
* @param name The name of the secret.
|
||||
* @param options The optional parameters for this request.
|
||||
*
|
||||
* @param context The context for the operation can be used for request cancellation.
|
||||
@ -169,7 +93,7 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Secrets {
|
||||
* the specified deleted secret along with its attributes.
|
||||
* This operation requires the secrets/get permission.
|
||||
*
|
||||
* @param name The name of the secret<span class="x x-first x-last">.</span>
|
||||
* @param name The name of the secret.
|
||||
* @param context The context for the operation can be used for request cancellation.
|
||||
*
|
||||
* @return The Secret wrapped in the Response.
|
||||
@ -181,8 +105,8 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Secrets {
|
||||
/**
|
||||
* @brief Set a secret in a specified key vault.
|
||||
*
|
||||
* @param name The name of the secret<span class="x x-first x-last">.</span>
|
||||
* @param value The value of the secret<span class="x x-first x-last">.</span>
|
||||
* @param name The name of the secret.
|
||||
* @param value The value of the secret.
|
||||
*
|
||||
* @param context The context for the operation can be used for request cancellation.
|
||||
* @return The Secret wrapped in the Response.
|
||||
@ -195,8 +119,8 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Secrets {
|
||||
/**
|
||||
* @brief Set a secret in a specified key vault.
|
||||
*
|
||||
* @param name The name of the secret<span class="x x-first x-last">.</span>
|
||||
* @param secret The secret definition <span class="x x-first x-last">.</span>
|
||||
* @param name The name of the secret.
|
||||
* @param secret The secret definition.
|
||||
*
|
||||
* @param context The context for the operation can be used for request cancellation.
|
||||
* @return The Secret wrapped in the Response.
|
||||
@ -213,7 +137,7 @@ 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<span class="x x-first x-last">.</span>
|
||||
* @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.
|
||||
@ -233,7 +157,7 @@ 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<span class="x x-first x-last">.</span>
|
||||
* @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.
|
||||
@ -252,7 +176,7 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Secrets {
|
||||
* All versions of the secret will be downloaded.
|
||||
* This operation requires the secrets/backup permission.
|
||||
*
|
||||
* @param name The name of the secret<span class="x x-first x-last">.</span>
|
||||
* @param name The name of the secret.
|
||||
* @param context The context for the operation can be used for request cancellation.
|
||||
*
|
||||
* @return The The backup blob containing the backed up secret.
|
||||
@ -281,7 +205,7 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Secrets {
|
||||
* recovery. This operation can only be enabled on a soft-delete enabled vault. This operation
|
||||
* requires the secrets/purge permission.
|
||||
*
|
||||
* @param name The name of the secret<span class="x x-first x-last">.</span>
|
||||
* @param name The name of the secret.
|
||||
* @param context The context for the operation can be used for request cancellation.
|
||||
*
|
||||
* @return Response<PurgedSecret> is success.
|
||||
@ -289,6 +213,34 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Secrets {
|
||||
Azure::Response<PurgedSecret> PurgeDeletedSecret(
|
||||
std::string const& name,
|
||||
Azure::Core::Context const& context = Azure::Core::Context()) const;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Delete a secret from a specified key vault.
|
||||
*
|
||||
* @remark The DELETE operation applies to any secret stored in Azure Key Vault.
|
||||
* DELETE cannot be applied to an individual version of a secret.
|
||||
* This operation requires the secrets/delete permission.
|
||||
*
|
||||
* @param name The name of the secret.
|
||||
* @param context The context for the operation can be used for request cancellation.
|
||||
*/
|
||||
Azure::Security::KeyVault::Secrets::KeyVaultDeleteSecretOperation StartDeleteSecret(
|
||||
std::string const& name,
|
||||
Azure::Core::Context const& context = Azure::Core::Context()) const;
|
||||
|
||||
/**
|
||||
* @brief Recover the deleted secret to the latest version.
|
||||
*
|
||||
* @remark Recovers the deleted secret in the specified vault.
|
||||
* This operation can only be performed on a soft-delete enabled vault.
|
||||
* This operation requires the secrets/recover permission.
|
||||
*
|
||||
* @param name The name of the secret.
|
||||
* @param context The context for the operation can be used for request cancellation.
|
||||
*/
|
||||
Azure::Security::KeyVault::Secrets::KeyVaultRestoreDeletedSecretOperation
|
||||
StartRecoverDeletedSecret(
|
||||
std::string const& name,
|
||||
Azure::Core::Context const& context = Azure::Core::Context()) const;
|
||||
};
|
||||
}}}} // namespace Azure::Security::KeyVault::Secrets
|
||||
|
||||
@ -0,0 +1,197 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
/**
|
||||
* @brief Keyvault operations definition.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "azure/keyvault/secrets/keyvault_operations.hpp"
|
||||
#include "azure/keyvault/secrets/secret_client.hpp"
|
||||
#include "private/secret_serializers.hpp"
|
||||
// KeyVaultRestoreDeletedSecretOperation
|
||||
|
||||
Azure::Response<KeyVaultSecret> KeyVaultRestoreDeletedSecretOperation::PollUntilDoneInternal(
|
||||
std::chrono::milliseconds period,
|
||||
Azure::Core::Context& context)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
// Poll will update the raw response.
|
||||
Poll(context);
|
||||
if (IsDone())
|
||||
{
|
||||
break;
|
||||
}
|
||||
std::this_thread::sleep_for(period);
|
||||
}
|
||||
|
||||
return Azure::Response<KeyVaultSecret>(
|
||||
m_value, std::make_unique<Azure::Core::Http::RawResponse>(*m_rawResponse));
|
||||
}
|
||||
|
||||
std::unique_ptr<Azure::Core::Http::RawResponse> KeyVaultRestoreDeletedSecretOperation::PollInternal(
|
||||
Azure::Core::Context const& context)
|
||||
{
|
||||
std::unique_ptr<Azure::Core::Http::RawResponse> rawResponse;
|
||||
if (IsDone())
|
||||
{
|
||||
try
|
||||
{
|
||||
rawResponse
|
||||
= m_secretClient->GetSecret(m_value.Name, GetSecretOptions(), context).RawResponse;
|
||||
}
|
||||
catch (Azure::Core::RequestFailedException& error)
|
||||
{
|
||||
rawResponse = std::move(error.RawResponse);
|
||||
}
|
||||
|
||||
switch (rawResponse->GetStatusCode())
|
||||
{
|
||||
case Azure::Core::Http::HttpStatusCode::Ok:
|
||||
case Azure::Core::Http::HttpStatusCode::Forbidden: {
|
||||
m_status = Azure::Core::OperationStatus::Succeeded;
|
||||
break;
|
||||
}
|
||||
case Azure::Core::Http::HttpStatusCode::NotFound: {
|
||||
m_status = Azure::Core::OperationStatus::Running;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw Azure::Core::RequestFailedException(rawResponse);
|
||||
}
|
||||
|
||||
if (m_status == Azure::Core::OperationStatus::Succeeded)
|
||||
{
|
||||
m_value = _detail::KeyVaultSecretSerializer::KeyVaultSecretDeserialize(
|
||||
m_value.Name, *rawResponse);
|
||||
}
|
||||
}
|
||||
return rawResponse;
|
||||
}
|
||||
|
||||
KeyVaultRestoreDeletedSecretOperation::KeyVaultRestoreDeletedSecretOperation(
|
||||
std::shared_ptr<SecretClient> secretClient,
|
||||
Azure::Response<KeyVaultSecret> response)
|
||||
: m_secretClient(secretClient)
|
||||
{
|
||||
m_value = response.Value;
|
||||
|
||||
m_rawResponse = std::move(response.RawResponse);
|
||||
|
||||
m_continuationToken = m_value.Name;
|
||||
|
||||
if (m_value.Name.empty() == false)
|
||||
{
|
||||
m_status = Azure::Core::OperationStatus::Succeeded;
|
||||
}
|
||||
}
|
||||
|
||||
KeyVaultRestoreDeletedSecretOperation::KeyVaultRestoreDeletedSecretOperation(
|
||||
std::string resumeToken,
|
||||
std::shared_ptr<SecretClient> secretClient)
|
||||
: m_secretClient(secretClient), m_continuationToken(std::move(resumeToken))
|
||||
{
|
||||
m_value.Name = resumeToken;
|
||||
}
|
||||
|
||||
KeyVaultRestoreDeletedSecretOperation KeyVaultRestoreDeletedSecretOperation::CreateFromResumeToken(
|
||||
std::string const& resumeToken,
|
||||
SecretClient const& client,
|
||||
Azure::Core::Context const& context)
|
||||
{
|
||||
KeyVaultRestoreDeletedSecretOperation operation(
|
||||
resumeToken, std::make_shared<SecretClient>(client));
|
||||
operation.Poll(context);
|
||||
return operation;
|
||||
}
|
||||
// KeyVaultDeleteSecretOperation
|
||||
Azure::Response<KeyVaultDeletedSecret> KeyVaultDeleteSecretOperation::PollUntilDoneInternal(
|
||||
std::chrono::milliseconds period,
|
||||
Azure::Core::Context& context)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
Poll(context);
|
||||
if (IsDone())
|
||||
{
|
||||
break;
|
||||
}
|
||||
std::this_thread::sleep_for(period);
|
||||
}
|
||||
|
||||
return Azure::Response<KeyVaultDeletedSecret>(
|
||||
m_value, std::make_unique<Azure::Core::Http::RawResponse>(*m_rawResponse));
|
||||
}
|
||||
|
||||
std::unique_ptr<Azure::Core::Http::RawResponse> KeyVaultDeleteSecretOperation::PollInternal(
|
||||
Azure::Core::Context const& context)
|
||||
{
|
||||
std::unique_ptr<Azure::Core::Http::RawResponse> rawResponse;
|
||||
if (!IsDone())
|
||||
{
|
||||
try
|
||||
{
|
||||
rawResponse = m_secretClient->GetDeletedSecret(m_value.Name, context).RawResponse;
|
||||
}
|
||||
catch (Azure::Core::RequestFailedException& error)
|
||||
{
|
||||
rawResponse = std::move(error.RawResponse);
|
||||
}
|
||||
|
||||
switch (rawResponse->GetStatusCode())
|
||||
{
|
||||
case Azure::Core::Http::HttpStatusCode::Ok:
|
||||
case Azure::Core::Http::HttpStatusCode::Forbidden: {
|
||||
m_status = Azure::Core::OperationStatus::Succeeded;
|
||||
break;
|
||||
}
|
||||
case Azure::Core::Http::HttpStatusCode::NotFound: {
|
||||
m_status = Azure::Core::OperationStatus::Running;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw Azure::Core::RequestFailedException(rawResponse);
|
||||
}
|
||||
|
||||
if (m_status == Azure::Core::OperationStatus::Succeeded)
|
||||
{
|
||||
m_value = _detail::KeyVaultDeletedSecretSerializer::KeyVaultDeletedSecretDeserialize(
|
||||
m_value.Name, *rawResponse);
|
||||
}
|
||||
}
|
||||
return rawResponse;
|
||||
}
|
||||
|
||||
KeyVaultDeleteSecretOperation::KeyVaultDeleteSecretOperation(
|
||||
std::shared_ptr<SecretClient> secretClient,
|
||||
Azure::Response<KeyVaultDeletedSecret> response)
|
||||
: m_secretClient(secretClient)
|
||||
{
|
||||
m_value = response.Value;
|
||||
m_rawResponse = std::move(response.RawResponse);
|
||||
m_continuationToken = m_value.Name;
|
||||
|
||||
if (m_value.Name.empty() == false)
|
||||
{
|
||||
m_status = Azure::Core::OperationStatus::Succeeded;
|
||||
}
|
||||
}
|
||||
|
||||
KeyVaultDeleteSecretOperation::KeyVaultDeleteSecretOperation(
|
||||
std::string resumeToken,
|
||||
std::shared_ptr<SecretClient> secretClient)
|
||||
: m_secretClient(secretClient), m_continuationToken(std::move(resumeToken))
|
||||
{
|
||||
m_value.Name = resumeToken;
|
||||
}
|
||||
|
||||
KeyVaultDeleteSecretOperation KeyVaultDeleteSecretOperation::CreateFromResumeToken(
|
||||
std::string const& resumeToken,
|
||||
SecretClient const& client,
|
||||
Azure::Core::Context const& context)
|
||||
{
|
||||
KeyVaultDeleteSecretOperation operation(resumeToken, std::make_shared<SecretClient>(client));
|
||||
operation.Poll(context);
|
||||
return operation;
|
||||
}
|
||||
@ -16,6 +16,7 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Secrets {
|
||||
static constexpr char const DeletedSecretPath[] = "deletedsecrets";
|
||||
static constexpr char const BackupSecretPath[] = "backup";
|
||||
static constexpr char const RestoreSecretPath[] = "restore";
|
||||
static constexpr char const RecoverDeletedSecretPath[] = "recover";
|
||||
|
||||
/******************* Secret property names ***********/
|
||||
|
||||
|
||||
@ -7,12 +7,11 @@
|
||||
*/
|
||||
|
||||
#include "azure/keyvault/secrets/secret_client.hpp"
|
||||
|
||||
#include "azure/keyvault/secrets/keyvault_operations.hpp"
|
||||
#include "private/keyvault_protocol.hpp"
|
||||
#include "private/package_version.hpp"
|
||||
#include "private/secret_constants.hpp"
|
||||
#include "private/secret_serializers.hpp"
|
||||
|
||||
#include <azure/core/credentials/credentials.hpp>
|
||||
#include <azure/core/http/http.hpp>
|
||||
#include <azure/core/http/policies/policy.hpp>
|
||||
@ -175,3 +174,33 @@ Azure::Response<PurgedSecret> SecretClient::PurgeDeletedSecret(
|
||||
[](Azure::Core::Http::RawResponse const&) { return PurgedSecret(); },
|
||||
{_detail::DeletedSecretPath, name});
|
||||
}
|
||||
|
||||
Azure::Security::KeyVault::Secrets::KeyVaultDeleteSecretOperation SecretClient::StartDeleteSecret(
|
||||
std::string const& name,
|
||||
Azure::Core::Context const& context) const
|
||||
{
|
||||
return Azure::Security::KeyVault::Secrets::KeyVaultDeleteSecretOperation(
|
||||
std::make_shared<SecretClient>(*this),
|
||||
m_protocolClient->SendRequest<KeyVaultDeletedSecret>(
|
||||
context,
|
||||
Azure::Core::Http::HttpMethod::Delete,
|
||||
[&name](Azure::Core::Http::RawResponse const& rawResponse) {
|
||||
return _detail::KeyVaultDeletedSecretSerializer::KeyVaultDeletedSecretDeserialize(
|
||||
name, rawResponse);
|
||||
},
|
||||
{_detail::SecretPath, name}));
|
||||
}
|
||||
|
||||
Azure::Security::KeyVault::Secrets::KeyVaultRestoreDeletedSecretOperation SecretClient::
|
||||
StartRecoverDeletedSecret(std::string const& name, Azure::Core::Context const& context) const
|
||||
{
|
||||
return Azure::Security::KeyVault::Secrets::KeyVaultRestoreDeletedSecretOperation(
|
||||
std::make_shared<SecretClient>(*this),
|
||||
m_protocolClient->SendRequest<KeyVaultSecret>(
|
||||
context,
|
||||
Azure::Core::Http::HttpMethod::Post,
|
||||
[&name](Azure::Core::Http::RawResponse const& rawResponse) {
|
||||
return _detail::KeyVaultSecretSerializer::KeyVaultSecretDeserialize(name, rawResponse);
|
||||
},
|
||||
{_detail::DeletedSecretPath, name, _detail::RecoverDeletedSecretPath}));
|
||||
}
|
||||
|
||||
@ -34,5 +34,15 @@ int main()
|
||||
|
||||
auto response = secretClient.PurgeDeletedSecret("someSecret3");
|
||||
|
||||
// auto response4 = secretClient.BackupSecret("someSecret2");
|
||||
// auto response5 = secretClient.RestoreSecretBackup(response4.Value.Secret);
|
||||
|
||||
auto response6 = secretClient.StartRecoverDeletedSecret("someSecret2");
|
||||
if (!response6.IsDone())
|
||||
{
|
||||
auto resumeToken = response6.GetResumeToken();
|
||||
auto response7 = response6.CreateFromResumeToken(resumeToken, secretClient);
|
||||
auto reasponse8 = response7.Poll();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user