Skip to content

Commit 821db2e

Browse files
authored
Add migration guides for KV certs and keys (Azure#15147)
* Add migration guides for KV certs and secrets Resolves Azure#12108 * Add README links to MigrationGuide.md docs For all services that currently have them.
1 parent d5f9b3f commit 821db2e

File tree

11 files changed

+1372
-38
lines changed

11 files changed

+1372
-38
lines changed

sdk/eventhub/Azure.Messaging.EventHubs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ The Azure Event Hubs client library allows for publishing and consuming of Azure
1212

1313
- Receive events from one or more publishers, transform them to better meet the needs of your ecosystem, then publish the transformed events to a new stream for consumers to observe.
1414

15-
[Source code](.) | [Package (NuGet)](https://www.nuget.org/packages/Azure.Messaging.EventHubs/) | [API reference documentation](https://aka.ms/azsdk-dotnet-eventhubs-docs) | [Product documentation](https://docs.microsoft.com/azure/event-hubs/)
15+
[Source code](.) | [Package (NuGet)](https://www.nuget.org/packages/Azure.Messaging.EventHubs/) | [API reference documentation](https://aka.ms/azsdk-dotnet-eventhubs-docs) | [Product documentation](https://docs.microsoft.com/azure/event-hubs/) | [Migration guide](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/eventhub/Azure.Messaging.EventHubs/MigrationGuide.md)
1616

1717
## Getting started
1818

sdk/keyvault/Azure.Security.KeyVault.Certificates/MigrationGuide.md

Lines changed: 399 additions & 0 deletions
Large diffs are not rendered by default.

sdk/keyvault/Azure.Security.KeyVault.Certificates/README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Azure Key Vault is a cloud service that provides secure storage and automated ma
33

44
The Azure Key Vault certificates client library enables programmatically managing certificates, offering methods to create, update, list, and delete certificates, policies, issuers, and contacts. The library also supports managing pending certificate operations and management of deleted certificates.
55

6-
[Source code][certificate_client_src] | [Package (NuGet)][certificate_client_nuget_package] | [API reference documentation][API_reference] | [Product documentation][keyvault_docs] | [Samples][certificate_client_samples]
6+
[Source code][certificate_client_src] | [Package (NuGet)][certificate_client_nuget_package] | [API reference documentation][API_reference] | [Product documentation][keyvault_docs] | [Samples][certificate_client_samples] | [Migration guide][migration_guide]
77

88
## Getting started
99

@@ -183,8 +183,8 @@ while (!operation.HasCompleted)
183183
operation.UpdateStatus();
184184
}
185185

186-
DeletedCertificate secret = operation.Value;
187-
client.PurgeDeletedCertificate(secret.Name);
186+
DeletedCertificate certificate = operation.Value;
187+
client.PurgeDeletedCertificate(certificate.Name);
188188
```
189189

190190
### Create a certificate asynchronously
@@ -222,8 +222,8 @@ DeleteCertificateOperation operation = await client.StartDeleteCertificateAsync(
222222
// You only need to wait for completion if you want to purge or recover the certificate.
223223
await operation.WaitForCompletionAsync();
224224

225-
DeletedCertificate secret = operation.Value;
226-
await client.PurgeDeletedCertificateAsync(secret.Name);
225+
DeletedCertificate certificate = operation.Value;
226+
await client.PurgeDeletedCertificateAsync(certificate.Name);
227227
```
228228

229229
## Troubleshooting
@@ -311,7 +311,7 @@ This project has adopted the [Microsoft Open Source Code of Conduct][code_of_con
311311
[azure_cli]: https://docs.microsoft.com/cli/azure
312312
[certificate_client_class]: src/CertificateClient.cs
313313
[soft_delete]: https://docs.microsoft.com/azure/key-vault/key-vault-ovw-soft-delete
314-
[azure_identity]: https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/identity/Azure.Identity
314+
[azure_identity]: https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/identity/Azure.Identity#defaultazurecredential
315315
[keyvault_rest]: https://docs.microsoft.com/rest/api/keyvault/
316316
[secrets_client_library]: https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/keyvault/Azure.Security.KeyVault.Secrets
317317
[keys_client_library]: https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/keyvault/Azure.Security.KeyVault.Keys
@@ -321,5 +321,6 @@ This project has adopted the [Microsoft Open Source Code of Conduct][code_of_con
321321
[DefaultAzureCredential]: https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/identity/Azure.Identity/README.md
322322
[contributing]: https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/keyvault/CONTRIBUTING.md
323323
[coc_faq]: https://opensource.microsoft.com/codeofconduct/faq/
324+
[migration_guide]: https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/keyvault/Azure.Security.KeyVault.Certificates/MigrationGuide.md
324325

325326
![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-net%2Fsdk%2Fkeyvault%2FAzure.Security.KeyVault.Certificates%2FREADME.png)

sdk/keyvault/Azure.Security.KeyVault.Certificates/tests/samples/SampleSnippets.cs

Lines changed: 125 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4+
using Azure.Core.Pipeline;
45
using Azure.Identity;
56
using NUnit.Framework;
67
using System;
8+
using System.IO;
9+
using System.Net.Http;
710
using System.Threading;
811
using System.Threading.Tasks;
912
using Azure.Security.KeyVault.Tests;
@@ -141,8 +144,8 @@ public async Task DeleteAndPurgeCertificateAsync()
141144
// You only need to wait for completion if you want to purge or recover the certificate.
142145
await operation.WaitForCompletionAsync();
143146

144-
DeletedCertificate secret = operation.Value;
145-
await client.PurgeDeletedCertificateAsync(secret.Name);
147+
DeletedCertificate certificate = operation.Value;
148+
await client.PurgeDeletedCertificateAsync(certificate.Name);
146149
#endregion
147150
}
148151

@@ -161,9 +164,127 @@ public void DeleteAndPurgeCertificate()
161164
operation.UpdateStatus();
162165
}
163166

164-
DeletedCertificate secret = operation.Value;
165-
client.PurgeDeletedCertificate(secret.Name);
167+
DeletedCertificate certificate = operation.Value;
168+
client.PurgeDeletedCertificate(certificate.Name);
166169
#endregion
167170
}
171+
172+
[Ignore("Used only for the migration guide")]
173+
private async Task MigrationGuide()
174+
{
175+
#region Snippet:Azure_Security_KeyVault_Certificates_Snippets_MigrationGuide_Create
176+
CertificateClient client = new CertificateClient(
177+
new Uri("https://myvault.vault.azure.net"),
178+
new DefaultAzureCredential());
179+
#endregion Snippet:Azure_Security_KeyVault_Certificates_Snippets_MigrationGuide_Create
180+
181+
#region Snippet:Azure_Security_KeyVault_Certificates_Snippets_MigrationGuide_CreateWithOptions
182+
using (HttpClient httpClient = new HttpClient())
183+
{
184+
CertificateClientOptions options = new CertificateClientOptions
185+
{
186+
Transport = new HttpClientTransport(httpClient)
187+
};
188+
189+
//@@CertificateClient client = new CertificateClient(
190+
/*@@*/ CertificateClient _ = new CertificateClient(
191+
new Uri("https://myvault.vault.azure.net"),
192+
new DefaultAzureCredential(),
193+
options);
194+
}
195+
#endregion Snippet:Azure_Security_KeyVault_Certificates_Snippets_MigrationGuide_CreateWithOptions
196+
197+
#region Snippet:Azure_Security_KeyVault_Certificates_Snippets_MigrationGuide_CreateCustomPolicy
198+
CertificatePolicy policy = new CertificatePolicy("issuer-name", "CN=customdomain.com")
199+
{
200+
ContentType = CertificateContentType.Pkcs12,
201+
KeyType = CertificateKeyType.Rsa,
202+
ReuseKey = true,
203+
KeyUsage =
204+
{
205+
CertificateKeyUsage.CrlSign,
206+
CertificateKeyUsage.DataEncipherment,
207+
CertificateKeyUsage.DigitalSignature,
208+
CertificateKeyUsage.KeyEncipherment,
209+
CertificateKeyUsage.KeyAgreement,
210+
CertificateKeyUsage.KeyCertSign
211+
},
212+
ValidityInMonths = 12,
213+
LifetimeActions =
214+
{
215+
new LifetimeAction(CertificatePolicyAction.AutoRenew)
216+
{
217+
DaysBeforeExpiry = 90,
218+
}
219+
}
220+
};
221+
#endregion Snippet:Azure_Security_KeyVault_Certificates_Snippets_MigrationGuide_CreateSelfSignedPolicy
222+
223+
#region Snippet:Azure_Security_KeyVault_Certificates_Snippets_MigrationGuide_CreateSelfSignedPolicy
224+
//@@CertificatePolicy policy = CertificatePolicy.Default;
225+
/*@@*/ policy = CertificatePolicy.Default;
226+
#endregion Snippet:Azure_Security_KeyVault_Certificates_Snippets_MigrationGuide_CreateSelfSignedPolicy
227+
228+
{
229+
#region Snippet:Azure_Security_KeyVault_Certificates_Snippets_MigrationGuide_CreateCertificate
230+
// Start certificate creation.
231+
// Depending on the policy and your business process, this could even take days for manual signing.
232+
CertificateOperation createOperation = await client.StartCreateCertificateAsync("certificate-name", policy);
233+
KeyVaultCertificateWithPolicy certificate = await createOperation.WaitForCompletionAsync(TimeSpan.FromSeconds(20), CancellationToken.None);
234+
235+
// If you need to restart the application you can recreate the operation and continue awaiting.
236+
createOperation = new CertificateOperation(client, "certificate-name");
237+
certificate = await createOperation.WaitForCompletionAsync(TimeSpan.FromSeconds(20), CancellationToken.None);
238+
#endregion Snippet:Azure_Security_KeyVault_Certificates_Snippets_MigrationGuide_CreateCertificate
239+
}
240+
241+
{
242+
#region Snippet:Azure_Security_KeyVault_Certificates_Snippets_MigrationGuide_ImportCertificate
243+
byte[] cer = File.ReadAllBytes("certificate.pfx");
244+
ImportCertificateOptions importCertificateOptions = new ImportCertificateOptions("certificate-name", cer)
245+
{
246+
Policy = policy
247+
};
248+
249+
KeyVaultCertificateWithPolicy certificate = await client.ImportCertificateAsync(importCertificateOptions);
250+
#endregion Snippet:Azure_Security_KeyVault_Certificates_Snippets_MigrationGuide_ImportCertificate
251+
}
252+
253+
{
254+
#region Snippet:Azure_Security_KeyVault_Certificates_Snippets_MigrationGuide_ListCertificates
255+
// List all certificates asynchronously.
256+
await foreach (CertificateProperties item in client.GetPropertiesOfCertificatesAsync())
257+
{
258+
KeyVaultCertificateWithPolicy certificate = await client.GetCertificateAsync(item.Name);
259+
}
260+
261+
// List all certificates synchronously.
262+
foreach (CertificateProperties item in client.GetPropertiesOfCertificates())
263+
{
264+
KeyVaultCertificateWithPolicy certificate = client.GetCertificate(item.Name);
265+
}
266+
#endregion Snippet:Azure_Security_KeyVault_Certificates_Snippets_MigrationGuide_ListCertificates
267+
}
268+
269+
{
270+
#region Snippet:Azure_Security_KeyVault_Certificates_Snippets_MigrationGuide_DeleteCertificate
271+
// Delete the certificate.
272+
DeleteCertificateOperation deleteOperation = await client.StartDeleteCertificateAsync("certificate-name");
273+
274+
// Purge or recover the deleted certificate if soft delete is enabled.
275+
if (deleteOperation.Value.RecoveryId != null)
276+
{
277+
// Deleting a certificate does not happen immediately. Wait for the certificate to be deleted.
278+
DeletedCertificate deletedCertificate = await deleteOperation.WaitForCompletionAsync();
279+
280+
// Purge the deleted certificate.
281+
await client.PurgeDeletedCertificateAsync(deletedCertificate.Name);
282+
283+
// You can also recover the deleted certificate using StartRecoverDeletedCertificateAsync,
284+
// which returns RecoverDeletedCertificateOperation you can await like DeleteCertificateOperation above.
285+
}
286+
#endregion Snippet:Azure_Security_KeyVault_Certificates_Snippets_MigrationGuide_DeleteCertificate
287+
}
288+
}
168289
}
169290
}

0 commit comments

Comments
 (0)