some updates (#2760)
* some updates * keyvault->key vault * Update sdk/keyvault/azure-security-keyvault-secrets/test/samples/sample2-backup-restore/sample2-backup-restore.md Co-authored-by: Rick Winter <rick.winter@microsoft.com> * Update sdk/keyvault/azure-security-keyvault-secrets/test/samples/sample2-backup-restore/sample2-backup-restore.md Co-authored-by: Rick Winter <rick.winter@microsoft.com> * Update sdk/keyvault/azure-security-keyvault-secrets/test/samples/sample1-basic-operations/sample1-basic-operations.md Co-authored-by: Rick Winter <rick.winter@microsoft.com> * final updates Co-authored-by: Rick Winter <rick.winter@microsoft.com>
This commit is contained in:
parent
ae4a41cfbd
commit
66422c2841
@ -25,27 +25,27 @@ az keyvault create --resource-group <your-resource-group-name> --name <your-key-
|
||||
|
||||
## Key concepts
|
||||
|
||||
### KeyVaultSecret
|
||||
A `Secret` is the fundamental resource within Azure Key Vault. From a developer's perspective, Azure Key Vault APIs accept and return secret values as strings.
|
||||
|
||||
### SecretClient
|
||||
`SecretClient` provides synchronous operations exists in the SDK. Once you've initialized a `SecretClient`, you can interact with the primary resource types in Azure Key Vault.
|
||||
|
||||
### Thread safety
|
||||
|
||||
We guarantee that all client instance methods are thread-safe and independent of each other ([guideline](https://azure.github.io/azure-sdk/cpp_introduction.html#thread-safety)). This ensures that the recommendation of reusing client instances is always safe, even across threads.
|
||||
|
||||
### Additional concepts
|
||||
|
||||
<!-- CLIENT COMMON BAR -->
|
||||
|
||||
[Replaceable HTTP transport adapter](https://github.com/Azure/azure-sdk-for-cpp/tree/main/sdk/core/azure-core#http-transport-adapter) |
|
||||
[Long-running operations](https://github.com/Azure/azure-sdk-for-cpp/tree/main/sdk/core/azure-core#long-running-operations) |
|
||||
|
||||
<!-- CLIENT COMMON BAR -->
|
||||
|
||||
## Examples
|
||||
|
||||
For detailed samples please review the samples provided.
|
||||
For detailed samples please review the samples provided.
|
||||
|
||||
### Create a client
|
||||
### Create a client
|
||||
|
||||
First step is to create a SecretClient.
|
||||
|
||||
@ -55,8 +55,8 @@ auto clientId = std::getenv("AZURE_CLIENT_ID");
|
||||
auto clientSecret = std::getenv("AZURE_CLIENT_SECRET");
|
||||
auto credential = std::make_shared<Azure::Identity::ClientSecretCredential>(tenantId, clientId, clientSecret);
|
||||
|
||||
// create client
|
||||
SecretClient secretClient(std::getenv("AZURE_KEYVAULT_URL"), credential);
|
||||
// create client
|
||||
SecretClient secretClient(std::getenv("AZURE_KEYVAULT_URL"), credential);
|
||||
```
|
||||
|
||||
### Create a secret
|
||||
@ -157,21 +157,21 @@ You will notice that additional information is logged, like the client request I
|
||||
|
||||
Several Azure Key Vault secrets client library samples are available to you in this GitHub repository. These samples provide example code for additional scenarios commonly encountered while working with Azure Key Vault:
|
||||
|
||||
* Sample1-Basic-Operations:
|
||||
* [Sample1-Basic-Operations](https://github.com/Azure/azure-sdk-for-cpp/tree/main/sdk/keyvault/azure-security-keyvault-secrets/test/samples/sample1-basic-operations):
|
||||
* Create a secret
|
||||
* Get a secret
|
||||
* Update a secret
|
||||
* Delete and Purge a secret
|
||||
|
||||
* Sample2-Backup-Restore
|
||||
* [Sample2-Backup-Restore](https://github.com/Azure/azure-sdk-for-cpp/tree/main/sdk/keyvault/azure-security-keyvault-secrets/test/samples/sample2-backup-restore):
|
||||
* Backup a secret
|
||||
* Restore a deleted secret
|
||||
|
||||
* Sample3-Delete-Recover
|
||||
* [Sample3-Delete-Recover](https://github.com/Azure/azure-sdk-for-cpp/tree/main/sdk/keyvault/azure-security-keyvault-secrets/test/samples/sample3-delete-recover):
|
||||
* Delete a secret
|
||||
* Recover a deleted Secret
|
||||
|
||||
* Sample4-Get-Secrets-Deleted
|
||||
* [Sample4-Get-Secrets-Deleted](https://github.com/Azure/azure-sdk-for-cpp/tree/main/sdk/keyvault/azure-security-keyvault-secrets/test/samples/sample4-get-secrets-deleted):
|
||||
* List all secrets
|
||||
* List all of a secrets versions
|
||||
* List all deletes secrets
|
||||
@ -214,10 +214,4 @@ Azure SDK for C++ is licensed under the [MIT](https://github.com/Azure/azure-sdk
|
||||
[azure_sdk_for_cpp_contributing_developer_guide]: https://github.com/Azure/azure-sdk-for-cpp/blob/main/CONTRIBUTING.md#developer-guide
|
||||
[azure_sdk_for_cpp_contributing_pull_requests]: https://github.com/Azure/azure-sdk-for-cpp/blob/main/CONTRIBUTING.md#pull-requests
|
||||
[azure_cli]: https://docs.microsoft.com/cli/azure
|
||||
[azure_pattern_circuit_breaker]: https://docs.microsoft.com/azure/architecture/patterns/circuit-breaker
|
||||
[azure_pattern_retry]: https://docs.microsoft.com/azure/architecture/patterns/retry
|
||||
[azure_portal]: https://portal.azure.com
|
||||
[azure_sub]: https://azure.microsoft.com/free/
|
||||
[c_compiler]: https://visualstudio.microsoft.com/vs/features/cplusplus/
|
||||
[cloud_shell]: https://docs.microsoft.com/azure/cloud-shell/overview
|
||||
[cloud_shell_bash]: https://shell.azure.com/bash
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
# Creating, getting, updating, and deleting secrets
|
||||
|
||||
This sample demonstrates how to create, get, update, and delete and purge a secret in Azure Key Vault.
|
||||
To get started, you'll need a URI to an Azure Key Vault.
|
||||
To get started, you'll need a URI to an Azure Key Vault.
|
||||
|
||||
## Creating a SecretClient
|
||||
|
||||
@ -26,7 +26,7 @@ SecretClient secretClient(std::getenv("AZURE_KEYVAULT_URL"), credential);
|
||||
|
||||
## Creating a Secret
|
||||
|
||||
To create a secret all you need to set id the name and secret value.
|
||||
Call SetSecret to create a new secret with name and secret value.
|
||||
|
||||
```cpp Snippet:SecretSample1SetSecret
|
||||
std::string secretName("MySampleSecret");
|
||||
@ -37,7 +37,7 @@ secretClient.SetSecret(secretName, secretValue);
|
||||
|
||||
## Getting a Secret
|
||||
|
||||
To get a secret from the keyvault you will need to call GetSecret.
|
||||
Call GetSecret to retrieve a secret from Key Vault.
|
||||
|
||||
```cpp Snippet:SecretSample1GetSecret
|
||||
// get secret
|
||||
@ -48,7 +48,7 @@ std::cout << "Secret is returned with name " << secret.Name << " and value " <<
|
||||
|
||||
## Updating secret properties
|
||||
|
||||
We forgot to set the content type for the secret we created, we can do that using the UpdateSecretProperties method.
|
||||
Call UpdateSecretProperties to change on of the secret properties.
|
||||
|
||||
|
||||
```cpp Snippet:SecretSample1UpdateSecretProperties
|
||||
@ -63,14 +63,14 @@ std::cout << "Secret's content type is now " << updatedSecret.Properties.Content
|
||||
|
||||
## Deleting a secret
|
||||
|
||||
The secret is no longer needed so we need to delete it.
|
||||
Call StartDeleteSecret to delete a secret. This is a long running operation.
|
||||
|
||||
```cpp Snippet:SecretSample1DeleteSecret
|
||||
// start deleting the secret
|
||||
DeleteSecretOperation operation = secretClient.StartDeleteSecret(secret.Name);
|
||||
```
|
||||
|
||||
## Purging a deleted key
|
||||
## Purging a deleted secret
|
||||
|
||||
If the Azure Key Vault is soft delete-enabled and you want to permanently delete the secret before its `ScheduledPurgeDate`, the secret needs to be purged.
|
||||
|
||||
@ -55,7 +55,7 @@ int main()
|
||||
|
||||
size_t backUpSize = 0;
|
||||
{
|
||||
std::cout << "\t-Backup Key" << std::endl;
|
||||
std::cout << "\t-Backup Secret" << std::endl;
|
||||
auto backupSecretResult = secretClient.BackupSecret(secret.Name).Value;
|
||||
auto const& backedupSecret = backupSecretResult.Secret;
|
||||
backUpSize = backedupSecret.size();
|
||||
@ -78,10 +78,10 @@ int main()
|
||||
// purge the deleted secret
|
||||
secretClient.PurgeDeletedSecret(secret.Name);
|
||||
|
||||
// let's wait for one minute so we know the key was purged.
|
||||
// let's wait for one minute so we know the secret was purged.
|
||||
std::this_thread::sleep_for(60s);
|
||||
|
||||
// Restore the key from the file backup
|
||||
// Restore the secret from the file backup
|
||||
std::cout << "\t-Read from file." << std::endl;
|
||||
std::ifstream inFile;
|
||||
inFile.open("backup.dat");
|
||||
@ -89,13 +89,13 @@ int main()
|
||||
inFile >> inMemoryBackup.data();
|
||||
inFile.close();
|
||||
|
||||
std::cout << "\t-Restore Key" << std::endl;
|
||||
std::cout << "\t-Restore Secret" << std::endl;
|
||||
auto restoredSecret = secretClient.RestoreSecretBackup(inMemoryBackup).Value;
|
||||
|
||||
AssertSecretsEqual(secret, restoredSecret);
|
||||
|
||||
operation = secretClient.StartDeleteSecret(restoredSecret.Name);
|
||||
// You only need to wait for completion if you want to purge or recover the key.
|
||||
// You only need to wait for completion if you want to purge or recover the secret.
|
||||
operation.PollUntilDone(2s);
|
||||
secretClient.PurgeDeletedSecret(restoredSecret.Name);
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
# Backup and Restore secrets
|
||||
|
||||
This sample demonstrates how to backup and restore in Azure Key Vault.
|
||||
To get started, you'll need a URI to an Azure Key Vault.
|
||||
To get started, you'll need a URI to an Azure Key Vault.
|
||||
|
||||
## Creating a SecretClient
|
||||
|
||||
@ -26,7 +26,7 @@ SecretClient secretClient(std::getenv("AZURE_KEYVAULT_URL"), credential);
|
||||
|
||||
## Creating a Secret
|
||||
|
||||
To create a secret all you need to set id the name and secret value.
|
||||
Call SetSecret to create a secret with the name and secret value.
|
||||
|
||||
```cpp Snippet:SecretSample2SetSecret
|
||||
std::string secretName("MySampleSecret");
|
||||
@ -37,7 +37,7 @@ secretClient.SetSecret(secretName, secretValue);
|
||||
|
||||
## Getting a Secret
|
||||
|
||||
To get a secret from the keyvault you will need to call GetSecret.
|
||||
Call GetSecret to retrieve a secret from Key Vault.
|
||||
|
||||
```cpp Snippet:SecretSample2GetSecret
|
||||
// get secret
|
||||
@ -48,25 +48,25 @@ std::cout << "Secret is returned with name " << secret.Name << " and value " <<
|
||||
|
||||
## Creating a Backup for the secret properties
|
||||
|
||||
In order to get the backup of the secret we need to call BackupSecret, which will return a vector of bytes representing the backed up content.
|
||||
Call BackupSecret to retrieve the secret backup. BackupSecret will will return a vector of bytes representing the backed up content.
|
||||
|
||||
|
||||
```cpp Snippet:SecretSample2BackupSecret
|
||||
std::cout << "\t-Backup Key" << std::endl;
|
||||
std::vector<uint8_t> backupKey(secretClient.BackupSecret(secret.Name).Value.Secret);
|
||||
backUpSize = backupKey.size();
|
||||
std::cout << "\t-Backup secret" << std::endl;
|
||||
std::vector<uint8_t> backupSecret(secretClient.BackupSecret(secret.Name).Value.Secret);
|
||||
backUpSize = backupSecret.size();
|
||||
```
|
||||
|
||||
## Deleting the secret in order to later restore it
|
||||
|
||||
The secret is no longer needed so we need to delete it.
|
||||
Call StartDeleteSecret to delete a secret. This is a long running operation.
|
||||
|
||||
```cpp Snippet:SecretSample2DeleteSecret
|
||||
// start deleting the secret
|
||||
DeleteSecretOperation operation = secretClient.StartDeleteSecret(secret.Name);
|
||||
```
|
||||
|
||||
## Purging a deleted key
|
||||
## Purging a deleted secret
|
||||
|
||||
If the Azure Key Vault is soft delete-enabled and you want to permanently delete the secret before its `ScheduledPurgeDate`, the secret needs to be purged.
|
||||
|
||||
@ -78,12 +78,12 @@ operation.PollUntilDone(2s);
|
||||
secretClient.PurgeDeletedSecret(secret.Name);
|
||||
```
|
||||
|
||||
## Restoring a secret
|
||||
## Restoring a secret
|
||||
|
||||
In order to restore a secret we need to call RestoreSecretBackup api passing in the byte vector obtained at the previous(backup) step.
|
||||
Call RestoreSecretBackup to restore a secret from a backup obtained at the previous(backup) step.
|
||||
|
||||
```cpp Snippet:SecretSample2RestoreSecret
|
||||
std::cout << "\t-Restore Key" << std::endl;
|
||||
std::cout << "\t-Restore Secret" << std::endl;
|
||||
auto restoredSecret = secretClient.RestoreSecretBackup(inMemoryBackup).Value;
|
||||
```
|
||||
|
||||
|
||||
@ -25,7 +25,7 @@ SecretClient secretClient(std::getenv("AZURE_KEYVAULT_URL"), credential);
|
||||
|
||||
## Creating a Secret
|
||||
|
||||
To create a secret all you need to set id the name and secret value.
|
||||
Call SetSecret to create a new secret with name and secret value.
|
||||
|
||||
```cpp Snippet:SecretSample3SetSecret
|
||||
std::string secretName("MySampleSecret");
|
||||
@ -36,7 +36,7 @@ secretClient.SetSecret(secretName, secretValue);
|
||||
|
||||
## Getting a Secret
|
||||
|
||||
To get a secret from the keyvault you will need to call GetSecret.
|
||||
Call GetSecret to retrieve a secret from Key Vault.
|
||||
|
||||
```cpp Snippet:SecretSample3GetSecret
|
||||
// get secret
|
||||
@ -47,7 +47,7 @@ std::cout << "Secret is returned with name " << secret.Name << " and value " <<
|
||||
|
||||
## Deleting a secret
|
||||
|
||||
The secret is no longer needed so we need to delete it.
|
||||
Call StartDeleteSecret to delete a secret. This is a long running operation.
|
||||
|
||||
```cpp Snippet:SecretSample3DeleteSecret
|
||||
// start deleting the secret
|
||||
@ -56,7 +56,7 @@ DeleteSecretOperation operation = secretClient.StartDeleteSecret(secret.Name);
|
||||
|
||||
## Recover a Deleted secret
|
||||
|
||||
To recover a deleted secret we need to call StartRecoverDeletedSecret and then poll untill the operation is done.
|
||||
Call StartRecoverDeletedSecret to recover a deleted secret and then poll until the operation is done.
|
||||
|
||||
```cpp Snippet:SecretSample3RecoverSecret
|
||||
// call restore secret
|
||||
|
||||
@ -25,7 +25,7 @@ SecretClient secretClient(std::getenv("AZURE_KEYVAULT_URL"), credential);
|
||||
|
||||
## Creating a couple of Secrets
|
||||
|
||||
To create a secret all you need to set id the name and secret value.
|
||||
Call SetSecret to create a couple of new secret with names and secret values.
|
||||
|
||||
```cpp Snippet:SecretSample4SetSecret
|
||||
std::string secretName("MySampleSecret");
|
||||
@ -36,9 +36,9 @@ Secret secret1 = secretClient.SetSecret(secretName, secretValue).Value;
|
||||
Secret secret2 = secretClient.SetSecret(secretName2, secretValue).Value;
|
||||
```
|
||||
|
||||
## Getting the properties of all the secrets in the keyvault
|
||||
## Getting the properties of all the secrets in the key vault
|
||||
|
||||
To get the properties of the secrets in the keyvault we will call GetPropertiesOfSecrets. The results of this call are paged to a maximum of 25 SecretProperties per page.
|
||||
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
|
||||
// get properties of secrets
|
||||
@ -53,8 +53,7 @@ for (auto secrets = secretClient.GetPropertiesOfSecrets(); secrets.HasPage(); se
|
||||
|
||||
## Get the versions of a Secret
|
||||
|
||||
in order to list all the versions of a secret we need to call GetPropertiesOfSecretsVersions, which responds similarly with a paged response of up to 25 versions of the secret per page.
|
||||
|
||||
Call GetPropertiesOfSecretsVersions in order to list all the versions of a secret. Responds similarly with a paged response of up to 25 versions of the secret per page.
|
||||
|
||||
```cpp Snippet:SecretSample4GetVersions
|
||||
// get all the versions of a secret
|
||||
@ -72,7 +71,7 @@ for (auto secretsVersion = secretClient.GetPropertiesOfSecretsVersions(secret1.N
|
||||
|
||||
## Delete both secrets
|
||||
|
||||
The secrets is no longer needed so we need to delete them, in order to demonstrate the delete related operations. We shall not purge the secrets yet.
|
||||
Call StartDeleteSecret to delete a secret. This is a long running operation. We shall not purge the secrets yet.
|
||||
|
||||
```cpp Snippet:SecretSample4DeleteSecrets
|
||||
// start deleting the secret
|
||||
@ -88,7 +87,7 @@ operation.PollUntilDone(2s);
|
||||
|
||||
## Get Deleted Secrets
|
||||
|
||||
To get a list of preprties of all deleted secrets we will call GetDeletedSecrets, similarly to the previous calls this is a paged response with the same limit of 25 items per response.
|
||||
Call GetDeletedSecrets to get a list of properties of all deleted secrets. This is a paged response with the same limit of 25 items per response.
|
||||
|
||||
```cpp Snippet:SecretSample4GetDeletedSecrets
|
||||
// get all the versions of a secret
|
||||
@ -104,7 +103,7 @@ for (auto deletedSecrets = secretClient.GetDeletedSecrets(); deletedSecrets.HasP
|
||||
|
||||
## Get Deleted Secret
|
||||
|
||||
To get information about a specific deleted secret we will call GetDeletedSecret passing the secret name as a parameter.
|
||||
Call GetDeletedSecret to get information about a specific deleted secret.
|
||||
|
||||
```cpp Snippet:SecretSample4GetDeletedSecret
|
||||
// get one deleted secret
|
||||
@ -114,7 +113,7 @@ std::cout << "Deleted Secret with name: " << deletedSecret.Value.Name;
|
||||
|
||||
## Purge the secrets to cleanup
|
||||
|
||||
Since the secrets were deleted previously now we need to call purge to finish cleaning up.
|
||||
Call PurgeDeletedSecret to finish cleaning up.
|
||||
|
||||
```cpp Snippet:SecretSample4PurgeSecrets
|
||||
// cleanup
|
||||
|
||||
Loading…
Reference in New Issue
Block a user