samples update for nullable (#5574)
* samples update for nullable * weqe * maybe * key sample
This commit is contained in:
parent
6390582951
commit
340543bb03
@ -71,7 +71,10 @@ auto updatedCertificate
|
||||
.Value;
|
||||
|
||||
std::cout << "After update certificate is enabled : "
|
||||
<< (updatedCertificate.Properties.Enabled.Value() ? "true" : "false");
|
||||
<< (updatedCertificate.Properties.Enabled.HasValue()
|
||||
&& updatedCertificate.Properties.Enabled.Value()
|
||||
? "true"
|
||||
: "false");
|
||||
```
|
||||
|
||||
## Deleting a Certificate
|
||||
|
||||
@ -93,7 +93,10 @@ int main()
|
||||
.Value;
|
||||
|
||||
std::cout << "After update certificate is enabled : "
|
||||
<< (updatedCertificate.Properties.Enabled.Value() ? "true" : "false");
|
||||
<< (updatedCertificate.Properties.Enabled.HasValue()
|
||||
&& updatedCertificate.Properties.Enabled.Value()
|
||||
? "true"
|
||||
: "false");
|
||||
}
|
||||
// delete the certificate
|
||||
{
|
||||
|
||||
@ -158,7 +158,8 @@ KeyVaultCertificateWithPolicy CreateCertificate(
|
||||
auto pollResponse = response.PollUntilDone(defaultWait).Value;
|
||||
|
||||
// check the status of the poll response
|
||||
if (!pollResponse.Error && pollResponse.Status.Value() == "completed")
|
||||
if (!pollResponse.Error && pollResponse.Status.HasValue()
|
||||
&& pollResponse.Status.Value() == "completed")
|
||||
{
|
||||
// get the certificate
|
||||
auto certificate = certificateClient.GetCertificate(certificateName).Value;
|
||||
|
||||
@ -313,8 +313,6 @@ client.PurgeDeletedKey(key.Name());
|
||||
This example lists all the keys in the specified Azure Key Vault.
|
||||
|
||||
```cpp
|
||||
Pageable<KeyProperties> allKeys = client.GetPropertiesOfKeys();
|
||||
|
||||
for (auto keys = client.GetPropertiesOfKeys(); keys.HasPage(); keys.MoveToNextPage())
|
||||
{
|
||||
for (auto const& key : keys.Items)
|
||||
|
||||
@ -51,108 +51,104 @@ For detailed samples please review the samples provided.
|
||||
|
||||
First step is to create a SecretClient.
|
||||
|
||||
<!-- @insert_snippet: SecretSample1CreateCredential -->
|
||||
```cpp
|
||||
auto credential = std::make_shared<Azure::Identity::DefaultAzureCredential>();
|
||||
auto credential = std::make_shared<Azure::Identity::DefaultAzureCredential>();
|
||||
|
||||
// create client
|
||||
SecretClient secretClient(std::getenv("AZURE_KEYVAULT_URL"), credential);
|
||||
// create client
|
||||
SecretClient secretClient(std::getenv("AZURE_KEYVAULT_URL"), credential);
|
||||
```
|
||||
|
||||
### Create a secret
|
||||
|
||||
We call the secret client to create a secret.
|
||||
|
||||
<!-- @insert_snippet: SecretSample1CreateSecret -->
|
||||
```cpp
|
||||
std::string secretName("MySampleSecret");
|
||||
std::string secretValue("my secret value");
|
||||
std::string secretName("MySampleSecret");
|
||||
std::string secretValue("my secret value");
|
||||
|
||||
secretClient.SetSecret(secretName, secretValue);
|
||||
secretClient.SetSecret(secretName, secretValue);
|
||||
```
|
||||
|
||||
### Get a secret
|
||||
|
||||
We retrieve a secret by name.
|
||||
|
||||
<!-- @insert_snippet: SecretSample1GetSecret -->
|
||||
```cpp
|
||||
// get secret
|
||||
KeyVaultSecret secret = secretClient.GetSecret(secretName).Value;
|
||||
// get secret
|
||||
KeyVaultSecret secret = secretClient.GetSecret(secretName).Value;
|
||||
|
||||
std::cout << "Secret is returned with name " << secret.Name << " and value "
|
||||
<< secret.Value.Value() << std::endl;
|
||||
std::string valueString = secret.Value.HasValue() ? secret.Value.Value() : "NONE RETURNED";
|
||||
std::cout << "Secret is returned with name " << secret.Name << " and value "
|
||||
<< valueString << std::endl;
|
||||
```
|
||||
|
||||
### Update a secret
|
||||
|
||||
Updating an existing secret
|
||||
|
||||
<!-- @insert_snippet: SecretSample1UpdateSecretProperties -->
|
||||
```cpp
|
||||
// change one of the properties
|
||||
secret.Properties.ContentType = "my content";
|
||||
// update the secret
|
||||
KeyVaultSecret updatedSecret = secretClient.UpdateSecretProperties(secret.Properties).Value;
|
||||
std::cout << "Secret's content type is now " << updatedSecret.Properties.ContentType.Value()
|
||||
<< std::endl;
|
||||
// change one of the properties
|
||||
secret.Properties.ContentType = "my content";
|
||||
// update the secret
|
||||
KeyVaultSecret updatedSecret = secretClient.UpdateSecretProperties(secret.Properties).Value;
|
||||
std::string updatedValueString = updatedSecret.Value.HasValue() ? updatedSecret.Value.Value()
|
||||
: "NONE RETURNED";
|
||||
std::cout << "Secret's content type is now " << updatedValueString
|
||||
<< std::endl;
|
||||
```
|
||||
|
||||
### Delete a secret
|
||||
|
||||
Delete an existing secret.
|
||||
|
||||
<!-- @insert_snippet: SecretSample1DeleteSecret -->
|
||||
```cpp
|
||||
// start deleting the secret
|
||||
DeleteSecretOperation operation = secretClient.StartDeleteSecret(secret.Name);
|
||||
// start deleting the secret
|
||||
DeleteSecretOperation operation = secretClient.StartDeleteSecret(secret.Name);
|
||||
|
||||
// You only need to wait for completion if you want to purge or recover the secret.
|
||||
// The duration of the delete operation might vary
|
||||
// in case returns too fast increase the timeout value
|
||||
operation.PollUntilDone(20s);
|
||||
// You only need to wait for completion if you want to purge or recover the secret.
|
||||
// The duration of the delete operation might vary
|
||||
// in case returns too fast increase the timeout value
|
||||
operation.PollUntilDone(20s);
|
||||
|
||||
// purge the deleted secret
|
||||
secretClient.PurgeDeletedSecret(secret.Name);
|
||||
// purge the deleted secret
|
||||
secretClient.PurgeDeletedSecret(secret.Name);
|
||||
```
|
||||
|
||||
### Delete and purge a secret
|
||||
|
||||
Delete and Purge a secret.
|
||||
|
||||
<!-- @insert_snippet: SecretSample1DeleteSecret -->
|
||||
```cpp
|
||||
// start deleting the secret
|
||||
DeleteSecretOperation operation = secretClient.StartDeleteSecret(secret.Name);
|
||||
// start deleting the secret
|
||||
DeleteSecretOperation operation = secretClient.StartDeleteSecret(secret.Name);
|
||||
|
||||
// You only need to wait for completion if you want to purge or recover the secret.
|
||||
// The duration of the delete operation might vary
|
||||
// in case returns too fast increase the timeout value
|
||||
operation.PollUntilDone(20s);
|
||||
// You only need to wait for completion if you want to purge or recover the secret.
|
||||
// The duration of the delete operation might vary
|
||||
// in case returns too fast increase the timeout value
|
||||
operation.PollUntilDone(20s);
|
||||
|
||||
// purge the deleted secret
|
||||
secretClient.PurgeDeletedSecret(secret.Name);
|
||||
// purge the deleted secret
|
||||
secretClient.PurgeDeletedSecret(secret.Name);
|
||||
```
|
||||
|
||||
### List Secrets
|
||||
|
||||
List all the secrets in keyvault.
|
||||
|
||||
<!-- @insert_snippet: SecretSample4ListAllSecrets -->
|
||||
```cpp
|
||||
// get all the versions of a secret
|
||||
for (auto secretsVersion = secretClient.GetPropertiesOfSecretsVersions(secret1.Name);
|
||||
secretsVersion.HasPage();
|
||||
secretsVersion.MoveToNextPage())
|
||||
{ // go through each version of the secret
|
||||
// the number of results returned for in a page is not guaranteed
|
||||
// it can be anywhere from 0 to 25
|
||||
for (auto const& secret : secretsVersion.Items)
|
||||
{
|
||||
std::cout << "Found Secret with name: " << secret.Name
|
||||
<< " and with version: " << secret.Version << std::endl;
|
||||
}
|
||||
}
|
||||
// get all the versions of a secret
|
||||
for (auto secretsVersion = secretClient.GetPropertiesOfSecretsVersions(secret1.Name);
|
||||
secretsVersion.HasPage();
|
||||
secretsVersion.MoveToNextPage())
|
||||
{ // go through each version of the secret
|
||||
// the number of results returned for in a page is not guaranteed
|
||||
// it can be anywhere from 0 to 25
|
||||
for (auto const& secret : secretsVersion.Items)
|
||||
{
|
||||
std::cout << "Found Secret with name: " << secret.Name
|
||||
<< " and with version: " << secret.Version << std::endl;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
@ -12,7 +12,7 @@ Key Vault Secrets client for C++ currently supports any `TokenCredential` for au
|
||||
In the sample below, you can create a credential by setting the Tenant ID, Client ID and Client Secret as environment variables.
|
||||
|
||||
```cpp Snippet:SecretSample1CreateCredential
|
||||
auto credential = std::make_shared<Azure::Identity::DefaultAzureCredential>();
|
||||
auto credential = std::make_shared<Azure::Identity::DefaultAzureCredential>();
|
||||
```
|
||||
|
||||
Then, in the sample below, you can set `keyVaultUrl` based on an environment variable, configuration setting, or any way that works for your application.
|
||||
@ -38,23 +38,25 @@ Call GetSecret to retrieve a secret from Key Vault.
|
||||
|
||||
```cpp Snippet:SecretSample1GetSecret
|
||||
// get secret
|
||||
Secret secret = secretClient.GetSecret(secretName).Value;
|
||||
std::cout << "Secret is returned with name " << secret.Name << " and value " << secret.Value
|
||||
<< std::endl;
|
||||
KeyVaultSecret secret = secretClient.GetSecret(secretName).Value;
|
||||
|
||||
std::string valueString = secret.Value.HasValue() ? secret.Value.Value() : "NONE RETURNED";
|
||||
std::cout << "Secret is returned with name " << secret.Name << " and value "
|
||||
<< valueString << std::endl;
|
||||
```
|
||||
|
||||
## Updating secret properties
|
||||
|
||||
Call UpdateSecretProperties to change on of the secret properties.
|
||||
|
||||
|
||||
```cpp Snippet:SecretSample1UpdateSecretProperties
|
||||
// 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;
|
||||
std::cout << "Secret's content type is now " << updatedSecret.Properties.ContentType.Value()
|
||||
KeyVaultSecret updatedSecret = secretClient.UpdateSecretProperties(secret.Properties).Value;
|
||||
std::string updatedValueString = updatedSecret.Value.HasValue() ? updatedSecret.Value.Value()
|
||||
: "NONE RETURNED";
|
||||
std::cout << "Secret's content type is now " << updatedValueString
|
||||
<< std::endl;
|
||||
```
|
||||
|
||||
|
||||
@ -12,7 +12,7 @@ Key Vault Secrets client for C++ currently supports any `TokenCredential` for au
|
||||
In the sample below, you can create a credential by setting the Tenant ID, Client ID and Client Secret as environment variables.
|
||||
|
||||
```cpp Snippet:SecretSample2CreateCredential
|
||||
auto credential = std::make_shared<Azure::Identity::DefaultAzureCredential>();
|
||||
auto credential = std::make_shared<Azure::Identity::DefaultAzureCredential>();
|
||||
```
|
||||
|
||||
Then, in the sample below, you can set `keyVaultUrl` based on an environment variable, configuration setting, or any way that works for your application.
|
||||
@ -38,9 +38,11 @@ Call GetSecret to retrieve a secret from Key Vault.
|
||||
|
||||
```cpp Snippet:SecretSample2GetSecret
|
||||
// get secret
|
||||
Secret secret = secretClient.GetSecret(secretName).Value;
|
||||
std::cout << "Secret is returned with name " << secret.Name << " and value " << secret.Value
|
||||
<< std::endl;
|
||||
KeyVaultSecret secret = secretClient.GetSecret(secretName).Value;
|
||||
|
||||
std::string valueString = secret.Value.HasValue() ? secret.Value.Value() : "NONE RETURNED";
|
||||
std::cout << "Secret is returned with name " << secret.Name << " and value "
|
||||
<< valueString << std::endl;
|
||||
```
|
||||
|
||||
## Creating a Backup for the secret properties
|
||||
|
||||
@ -11,7 +11,7 @@ Key Vault Secrets client for C++ currently supports any `TokenCredential` for au
|
||||
In the sample below, you can create a credential by setting the Tenant ID, Client ID and Client Secret as environment variables.
|
||||
|
||||
```cpp Snippet:SecretSample3CreateCredential
|
||||
auto credential = std::make_shared<Azure::Identity::DefaultAzureCredential>();
|
||||
auto credential = std::make_shared<Azure::Identity::DefaultAzureCredential>();
|
||||
```
|
||||
|
||||
Then, in the sample below, you can set `keyVaultUrl` based on an environment variable, configuration setting, or any way that works for your application.
|
||||
@ -37,9 +37,11 @@ Call GetSecret to retrieve a secret from Key Vault.
|
||||
|
||||
```cpp Snippet:SecretSample3GetSecret
|
||||
// get secret
|
||||
Secret secret = secretClient.GetSecret(secretName).Value;
|
||||
std::cout << "Secret is returned with name " << secret.Name << " and value " << secret.Value
|
||||
<< std::endl;
|
||||
KeyVaultSecret secret = secretClient.GetSecret(secretName).Value;
|
||||
|
||||
std::string valueString = secret.Value.HasValue() ? secret.Value.Value() : "NONE RETURNED";
|
||||
std::cout << "Secret is returned with name " << secret.Name << " and value "
|
||||
<< valueString << std::endl;
|
||||
```
|
||||
|
||||
## Deleting a secret
|
||||
|
||||
@ -10,13 +10,13 @@ Key Vault Secrets client for C++ currently supports any `TokenCredential` for au
|
||||
|
||||
In the sample below, you can create a credential by setting the Tenant ID, Client ID and Client Secret as environment variables.
|
||||
|
||||
```cpp Snippet:SecretSample4CreateCredential
|
||||
auto credential = std::make_shared<Azure::Identity::DefaultAzureCredential>();
|
||||
```cpp
|
||||
auto credential = std::make_shared<Azure::Identity::DefaultAzureCredential>();
|
||||
```
|
||||
|
||||
Then, in the sample below, you can set `keyVaultUrl` based on an environment variable, configuration setting, or any way that works for your application.
|
||||
|
||||
```cpp Snippet:SecretSample4SecretClient
|
||||
```cpp
|
||||
SecretClient secretClient(std::getenv("AZURE_KEYVAULT_URL"), credential);
|
||||
```
|
||||
|
||||
@ -24,7 +24,7 @@ SecretClient secretClient(std::getenv("AZURE_KEYVAULT_URL"), credential);
|
||||
|
||||
Call SetSecret to create a couple of new secret with names and secret values.
|
||||
|
||||
```cpp Snippet:SecretSample4SetSecret
|
||||
```cpp
|
||||
std::string secretName("MySampleSecret");
|
||||
std::string secretName2("MySampleSecret2");
|
||||
std::string secretValue("my secret value");
|
||||
@ -37,7 +37,7 @@ Secret secret2 = secretClient.SetSecret(secretName2, secretValue).Value;
|
||||
|
||||
Call GetPropertiesOfSecrets to get the properties of all the secrets in the key vault. The results of this call are paged to a maximum of 25 SecretProperties per page.
|
||||
|
||||
```cpp Snippet:SecretSample4ListAllSecrets
|
||||
```cpp
|
||||
// get properties of secrets
|
||||
for (auto secrets = secretClient.GetPropertiesOfSecrets(); secrets.HasPage(); secrets.MoveToNextPage())
|
||||
{ // go through every secret of each page returned
|
||||
|
||||
@ -42,8 +42,9 @@ int main()
|
||||
// get secret
|
||||
KeyVaultSecret secret = secretClient.GetSecret(secretName).Value;
|
||||
|
||||
std::cout << "Secret is returned with name " << secret.Name << " and value "
|
||||
<< secret.Value.Value() << std::endl;
|
||||
std::string valueString = secret.Value.HasValue() ? secret.Value.Value() : "NONE RETURNED";
|
||||
std::cout << "Secret is returned with name " << secret.Name << " and value " << valueString
|
||||
<< std::endl;
|
||||
// @end_snippet
|
||||
|
||||
// @begin_snippet: SecretSample1UpdateSecretProperties
|
||||
@ -51,8 +52,9 @@ int main()
|
||||
secret.Properties.ContentType = "my content";
|
||||
// update the secret
|
||||
KeyVaultSecret updatedSecret = secretClient.UpdateSecretProperties(secret.Properties).Value;
|
||||
std::cout << "Secret's content type is now " << updatedSecret.Properties.ContentType.Value()
|
||||
<< std::endl;
|
||||
std::string updatedValueString
|
||||
= updatedSecret.Value.HasValue() ? updatedSecret.Value.Value() : "NONE RETURNED";
|
||||
std::cout << "Secret's content type is now " << updatedValueString << std::endl;
|
||||
// @end_snippet
|
||||
|
||||
// @begin_snippet: SecretSample1DeleteSecret
|
||||
|
||||
@ -40,8 +40,9 @@ int main()
|
||||
// get secret
|
||||
KeyVaultSecret secret = secretClient.GetSecret(secretName).Value;
|
||||
|
||||
std::cout << "Secret is returned with name " << secret.Name << " and value "
|
||||
<< secret.Value.Value() << std::endl;
|
||||
std::string valueString = secret.Value.HasValue() ? secret.Value.Value() : "NONE RETURNED";
|
||||
std::cout << "Secret is returned with name " << secret.Name << " and value " << valueString
|
||||
<< std::endl;
|
||||
|
||||
size_t backUpSize = 0;
|
||||
{
|
||||
|
||||
@ -40,9 +40,9 @@ int main()
|
||||
// get secret
|
||||
KeyVaultSecret secret = secretClient.GetSecret(secretName).Value;
|
||||
|
||||
std::cout << "Secret is returned with name " << secret.Name << " and value "
|
||||
<< secret.Value.Value() << std::endl;
|
||||
|
||||
std::string valueString = secret.Value.HasValue() ? secret.Value.Value() : "NONE RETURNED";
|
||||
std::cout << "Secret is returned with name " << secret.Name << " and value " << valueString
|
||||
<< std::endl;
|
||||
// start deleting the secret
|
||||
DeleteSecretOperation operation = secretClient.StartDeleteSecret(secret.Name);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user