[Certificates] Create Certificate operation return (#3392)
* fix cert create * PR feedback, readme update * clang
This commit is contained in:
parent
172808eb1c
commit
5050bee3bf
@ -84,13 +84,18 @@ auto response = certificateClient.StartCreateCertificate(certificateName, option
|
||||
|
||||
### Getting a Certificate once completed
|
||||
|
||||
Call PollUntilDone to poll the status of the creation. Once the opperation has completed it will return the certificate.
|
||||
Call PollUntilDone to poll the status of the creation. Once the opperation has completed we will call GetCertificate to get the newly created certificate.
|
||||
|
||||
```cpp Snippet:CertificateSample1Get
|
||||
// wait for complete to get the certificate
|
||||
certificate = response.PollUntilDone(defaultWait).Value;
|
||||
|
||||
auto pollResponse = response.PollUntilDone(defaultWait).Value;
|
||||
// check the status of the poll response
|
||||
if (!pollResponse.Error && pollResponse.Status.Value() == "completed")
|
||||
{
|
||||
// get the certificate
|
||||
auto result = certificateClient.GetCertificate(certificateName).Value;
|
||||
std::cout << "Created certificate with policy. Certificate name : " << certificate.Name();
|
||||
}
|
||||
```
|
||||
|
||||
### Updating certificate properties
|
||||
|
||||
@ -23,17 +23,16 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Certificat
|
||||
* @brief Represents a create certificate long running operation
|
||||
*/
|
||||
class CreateCertificateOperation final
|
||||
: public Azure::Core::Operation<KeyVaultCertificateWithPolicy> {
|
||||
: public Azure::Core::Operation<CertificateOperationProperties> {
|
||||
|
||||
friend class CertificateClient;
|
||||
|
||||
private:
|
||||
std::shared_ptr<CertificateClient> m_certificateClient;
|
||||
KeyVaultCertificateWithPolicy m_value;
|
||||
CertificateOperationProperties m_properties;
|
||||
CertificateOperationProperties m_value;
|
||||
std::string m_continuationToken;
|
||||
|
||||
Azure::Response<KeyVaultCertificateWithPolicy> PollUntilDoneInternal(
|
||||
Azure::Response<CertificateOperationProperties> PollUntilDoneInternal(
|
||||
std::chrono::milliseconds period,
|
||||
Azure::Core::Context& context) override;
|
||||
|
||||
@ -47,7 +46,7 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Certificat
|
||||
*/
|
||||
CreateCertificateOperation(
|
||||
std::shared_ptr<CertificateClient> certificateClient,
|
||||
Azure::Response<KeyVaultCertificateWithPolicy> response);
|
||||
Azure::Response<CertificateOperationProperties> response);
|
||||
|
||||
CreateCertificateOperation(
|
||||
std::string resumeToken,
|
||||
@ -70,9 +69,8 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Certificat
|
||||
*
|
||||
* @return A CertificateOperationProperties object.
|
||||
*/
|
||||
KeyVaultCertificateWithPolicy Value() const override { return m_value; }
|
||||
CertificateOperationProperties Value() const override { return m_value; }
|
||||
|
||||
CertificateOperationProperties Properties() const { return m_properties; }
|
||||
/**
|
||||
* @brief Get an Url as string which can be used to get the status of the
|
||||
* operation.
|
||||
|
||||
@ -45,13 +45,18 @@ auto response = certificateClient.StartCreateCertificate(certificateName, option
|
||||
|
||||
## Getting a Certificate
|
||||
|
||||
Call PollUntilDone to poll the status of the creation. Once the opperation has completed it will return the certificate.
|
||||
Call PollUntilDone to poll the status of the creation. Once the opperation has completed we will call GetCertificate
|
||||
|
||||
```cpp Snippet:CertificateSample1Get
|
||||
// wait for complete to get the certificate
|
||||
certificate = response.PollUntilDone(defaultWait).Value;
|
||||
|
||||
auto pollResponse = response.PollUntilDone(defaultWait).Value;
|
||||
// check the status of the poll response
|
||||
if (!pollResponse.Error && pollResponse.Status.Value() == "completed")
|
||||
{
|
||||
// get the certificate
|
||||
auto result = certificateClient.GetCertificate(certificateName).Value;
|
||||
std::cout << "Created certificate with policy. Certificate name : " << certificate.Name();
|
||||
}
|
||||
```
|
||||
|
||||
## Updating certificate properties
|
||||
|
||||
@ -35,7 +35,7 @@ CertificateClient certificateClient(std::getenv("AZURE_KEYVAULT_URL"), credentia
|
||||
## Creating a Certificate
|
||||
|
||||
Call StartCreateCertificate to create a new certificate, with specified properties and policy.
|
||||
Call PollUntilDone to poll the status of the creation. Once the opperation has completed it will return the certificate.
|
||||
Call PollUntilDone to poll the status of the creation. Once the opperation has completed we can continue.
|
||||
|
||||
```cpp Snippet:CertificateSample2Create
|
||||
std::string certificateName = "Sample1";
|
||||
|
||||
@ -9,7 +9,7 @@
|
||||
|
||||
using namespace Azure::Security::KeyVault::Certificates;
|
||||
|
||||
Azure::Response<KeyVaultCertificateWithPolicy> CreateCertificateOperation::PollUntilDoneInternal(
|
||||
Azure::Response<CertificateOperationProperties> CreateCertificateOperation::PollUntilDoneInternal(
|
||||
std::chrono::milliseconds period,
|
||||
Azure::Core::Context& context)
|
||||
{
|
||||
@ -23,19 +23,7 @@ Azure::Response<KeyVaultCertificateWithPolicy> CreateCertificateOperation::PollU
|
||||
std::this_thread::sleep_for(period);
|
||||
}
|
||||
|
||||
if (!m_properties.Error)
|
||||
{
|
||||
auto response = m_certificateClient->GetCertificate(m_properties.Name);
|
||||
m_value = response.Value;
|
||||
m_rawResponse = std::move(response.RawResponse);
|
||||
}
|
||||
else
|
||||
{
|
||||
// the raw response here is from the pending operation thus contains the Properties.
|
||||
throw Azure::Core::RequestFailedException(m_rawResponse);
|
||||
}
|
||||
|
||||
return Azure::Response<KeyVaultCertificateWithPolicy>(
|
||||
return Azure::Response<CertificateOperationProperties>(
|
||||
m_value, std::make_unique<Azure::Core::Http::RawResponse>(*m_rawResponse));
|
||||
}
|
||||
|
||||
@ -71,7 +59,7 @@ std::unique_ptr<Azure::Core::Http::RawResponse> CreateCertificateOperation::Poll
|
||||
|
||||
if (m_status == Azure::Core::OperationStatus::Succeeded)
|
||||
{
|
||||
m_properties = _detail::CertificateOperationSerializer::Deserialize(*rawResponse);
|
||||
m_value = _detail::CertificateOperationSerializer::Deserialize(*rawResponse);
|
||||
}
|
||||
|
||||
return rawResponse;
|
||||
@ -79,14 +67,14 @@ std::unique_ptr<Azure::Core::Http::RawResponse> CreateCertificateOperation::Poll
|
||||
|
||||
CreateCertificateOperation::CreateCertificateOperation(
|
||||
std::shared_ptr<CertificateClient> certificateClient,
|
||||
Azure::Response<KeyVaultCertificateWithPolicy> response)
|
||||
Azure::Response<CertificateOperationProperties> response)
|
||||
: m_certificateClient(certificateClient)
|
||||
{
|
||||
m_value = response.Value;
|
||||
m_rawResponse = std::move(response.RawResponse);
|
||||
m_continuationToken = m_value.Name();
|
||||
m_continuationToken = m_value.Name;
|
||||
|
||||
if (!m_value.Name().empty())
|
||||
if (!m_value.Name.empty())
|
||||
{
|
||||
m_status = Azure::Core::OperationStatus::Succeeded;
|
||||
}
|
||||
@ -113,26 +101,26 @@ void CreateCertificateOperation::Cancel(Azure::Core::Context const& context)
|
||||
{
|
||||
auto response
|
||||
= m_certificateClient->CancelPendingCertificateOperation(m_continuationToken, context);
|
||||
m_properties = response.Value;
|
||||
m_value = response.Value;
|
||||
}
|
||||
void CreateCertificateOperation::Delete(Azure::Core::Context const& context)
|
||||
{
|
||||
auto response
|
||||
= m_certificateClient->DeletePendingCertificateOperation(m_continuationToken, context);
|
||||
m_properties = response.Value;
|
||||
m_value = response.Value;
|
||||
}
|
||||
|
||||
bool CreateCertificateOperation::IsCompleted() const
|
||||
{
|
||||
bool completed = false;
|
||||
|
||||
if (m_properties.Status
|
||||
&& (m_properties.Status.Value() == _detail::CompletedValue
|
||||
|| m_properties.Status.Value() == _detail::DeletedValue))
|
||||
if (m_value.Status
|
||||
&& (m_value.Status.Value() == _detail::CompletedValue
|
||||
|| m_value.Status.Value() == _detail::DeletedValue))
|
||||
{
|
||||
completed = true;
|
||||
}
|
||||
if (m_properties.Error.HasValue())
|
||||
if (m_value.Error.HasValue())
|
||||
{
|
||||
completed = true;
|
||||
}
|
||||
|
||||
@ -67,9 +67,18 @@ int main()
|
||||
// start the create process
|
||||
auto response = certificateClient.StartCreateCertificate(certificateName, options);
|
||||
// wait for complete to get the certificate
|
||||
certificate = response.PollUntilDone(defaultWait).Value;
|
||||
|
||||
std::cout << "Created certificate with policy. Certificate name : " << certificate.Name();
|
||||
auto pollResponse = response.PollUntilDone(defaultWait).Value;
|
||||
// check the status of the poll response
|
||||
if (!pollResponse.Error && pollResponse.Status.Value() == "completed")
|
||||
{
|
||||
// get the certificate
|
||||
auto result = certificateClient.GetCertificate(certificateName).Value;
|
||||
std::cout << "Created certificate with policy. Certificate name : " << certificate.Name();
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Create certificate with policy result : " << pollResponse.Status.Value();
|
||||
}
|
||||
}
|
||||
// update certificate
|
||||
{
|
||||
|
||||
@ -157,10 +157,20 @@ KeyVaultCertificateWithPolicy CreateCertificate(
|
||||
// start the create process
|
||||
auto response = certificateClient.StartCreateCertificate(certificateName, options);
|
||||
// wait for complete to get the certificate
|
||||
auto certificate = response.PollUntilDone(defaultWait).Value;
|
||||
auto pollResponse = response.PollUntilDone(defaultWait).Value;
|
||||
|
||||
std::cout << "Created certificate with policy. Certificate name : " << certificate.Name();
|
||||
|
||||
return certificate;
|
||||
// check the status of the poll response
|
||||
if (!pollResponse.Error && pollResponse.Status.Value() == "completed")
|
||||
{
|
||||
// get the certificate
|
||||
auto certificate = certificateClient.GetCertificate(certificateName).Value;
|
||||
std::cout << "Created certificate with policy. Certificate name : " << certificate.Name();
|
||||
return certificate;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw std::runtime_error(
|
||||
"Create certificate with policy result : " + pollResponse.Status.Value());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -176,7 +176,13 @@ namespace Azure {
|
||||
options.Policy.LifetimeActions.emplace_back(action);
|
||||
|
||||
auto response = client.StartCreateCertificate(name, options);
|
||||
auto result = response.PollUntilDone(defaultWait);
|
||||
auto pollResult = response.PollUntilDone(defaultWait);
|
||||
EXPECT_EQ(pollResult.Value.Name, name);
|
||||
EXPECT_TRUE(pollResult.Value.Status.HasValue());
|
||||
EXPECT_EQ(pollResult.Value.Status.Value(), "completed");
|
||||
EXPECT_EQ(pollResult.RawResponse->GetStatusCode(), Azure::Core::Http::HttpStatusCode::Ok);
|
||||
// get the certificate
|
||||
auto result = client.GetCertificate(name);
|
||||
|
||||
EXPECT_EQ(result.Value.Name(), options.Properties.Name);
|
||||
EXPECT_EQ(result.Value.Properties.Name, options.Properties.Name);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user