Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reorder backup and restore operation ctor args and add sample #15205

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace Azure.Security.KeyVault.Administration
{
public partial class BackupOperation : Azure.Operation<System.Uri>
{
public BackupOperation(string id, Azure.Security.KeyVault.Administration.KeyVaultBackupClient client) { }
public BackupOperation(Azure.Security.KeyVault.Administration.KeyVaultBackupClient client, string id) { }
public System.DateTimeOffset? EndTime { get { throw null; } }
public override bool HasCompleted { get { throw null; } }
public override bool HasValue { get { throw null; } }
Expand Down Expand Up @@ -84,7 +84,7 @@ public enum ServiceVersion
}
public partial class RestoreOperation : Azure.Operation<Azure.Response>
{
public RestoreOperation(string id, Azure.Security.KeyVault.Administration.KeyVaultBackupClient client) { }
public RestoreOperation(Azure.Security.KeyVault.Administration.KeyVaultBackupClient client, string id) { }
public System.DateTimeOffset? EndTime { get { throw null; } }
public override bool HasCompleted { get { throw null; } }
public override bool HasValue { get { throw null; } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ description: Samples for the Azure.Security.KeyVault.Administration client libra
- Creating, getting, and deleting role assignments [synchronously](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/keyvault/Azure.Security.KeyVault.Administration/samples/Sample1_RbacHelloWorldSync.md) or [asynchronously](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/keyvault/Azure.Security.KeyVault.Administration/samples/Sample1_RbacHelloWorldAsync.md)
- [Assigning roles for specific scopes](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/keyvault/Azure.Security.KeyVault.Administration/samples/Sample2_RbacScopeAssignment.md)
- Performing a full key backup and restore [synchronously](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/keyvault/Azure.Security.KeyVault.Administration/samples/Sample1_BackupHelloWorldSync.md) and [asynchronously](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/keyvault/Azure.Security.KeyVault.Administration/samples/Sample1_BackupHelloWorldAsync.md)
- [Checking the status of a previously started backup or restore](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/keyvault/Azure.Security.KeyVault.Administration/samples/Sample3_BackRestoreResume.md)
- [Performing selective key restore]
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Checking the status of a previously started full key backup and restore

This sample demonstrates how to a check the status and get the result of a previously started full key backup and restore in Azure Key Vault.
christothes marked this conversation as resolved.
Show resolved Hide resolved
To get started, you'll need a URI to an Azure Key Vault. See the [README](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/keyvault/Azure.Security.KeyVault.Administration/README.md) for links and instructions.

## Checking status of a full key backup
christothes marked this conversation as resolved.
Show resolved Hide resolved

Using the `KeyVaultBackupClient` and a `BackupOperation`, you can check the status and retrieve the result of a previously started `BackupOperation`.
For example the `Id` from a started operation on one client can be saved to persistent storage instead of waiting for completion immediately.
At some later time, another client can retrieve the persisted operation Id and construct a `BackupOperation` using a `KeyVaultBackupClient` and the Id
and check for status or wait for completion.

```C# Snippet:ResumeBackupAsync
// Construct a new KeyVaultBackupClient or use an existing one.
KeyVaultBackupClient Client = new KeyVaultBackupClient(new Uri(keyVaultUrl), new DefaultAzureCredential());

// Construct a BackupOperation using a KeyVaultBackupClient and the Id from a previously started operation.
BackupOperation backupOperation = new BackupOperation(client, backupOperationId);

// Wait for completion of the BackupOperation.
Response<Uri> backupResult = await backupOperation.WaitForCompletionAsync();
christothes marked this conversation as resolved.
Show resolved Hide resolved

// Get the Uri for the location of you backup blob.
Uri backupBlobUri = backupResult.Value;
```

## Checking status of a full key restore
christothes marked this conversation as resolved.
Show resolved Hide resolved

Using the `KeyVaultBackupClient` and a `RestoreOperation`, you can check the status and retrieve the result of a previously started `RestoreOperation`.
For example the `Id` from a started operation on one client can be saved to persistent storage instead of waiting for completion immediately.
At some later time, another client can retrieve the persisted operation Id and construct a `RestoreOperation` using a `KeyVaultBackupClient` and the Id
and check for status or wait for completion.

```C# Snippet:ResumeRestoreAsync
// Construct a new KeyVaultBackupClient or use an existing one.
KeyVaultBackupClient Client = new KeyVaultBackupClient(new Uri(keyVaultUrl), new DefaultAzureCredential());

// Construct a RestoreOperation using a KeyVaultBackupClient and the Id from a previously started operation.
RestoreOperation restoreOperation = new RestoreOperation(client, restoreOperationId);

// Wait for completion of the RestoreOperation.
Response restoreResult = await restoreOperation.WaitForCompletionAsync();
```

<!-- LINKS -->
[DefaultAzureCredential]: ../../../identity/Azure.Identity/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ public class BackupOperation : Operation<Uri>
/// <see cref="WaitForCompletionAsync(CancellationToken)"/>, or <see cref="WaitForCompletionAsync(TimeSpan, CancellationToken)"/> must be called
/// to re-populate the details of this operation.
/// </summary>
/// <param name="id">The <see cref="Id" /> from a previous <see cref="BackupOperation" />.</param>
/// <param name="client">An instance of <see cref="KeyVaultBackupClient" />.</param>
/// <param name="id">The <see cref="Id" /> from a previous <see cref="BackupOperation" />.</param>
/// <exception cref="ArgumentNullException"><paramref name="id"/> or <paramref name="client"/> is null.</exception>
public BackupOperation(string id, KeyVaultBackupClient client)
public BackupOperation(KeyVaultBackupClient client, string id)
{
Argument.AssertNotNull(id, nameof(id));
Argument.AssertNotNull(client, nameof(client));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ public class RestoreOperation : Operation<Response>
/// <see cref="WaitForCompletionAsync(CancellationToken)"/>, or <see cref="WaitForCompletionAsync(TimeSpan, CancellationToken)"/> must be called
/// to re-populate the details of this operation.
/// </summary>
/// <param name="id">The <see cref="Id" /> from a previous <see cref="BackupOperation" />.</param>
/// <param name="client">An instance of <see cref="KeyVaultBackupClient" />.</param>
/// <param name="id">The <see cref="Id" /> from a previous <see cref="BackupOperation" />.</param>
/// <exception cref="ArgumentNullException"><paramref name="id"/> or <paramref name="client"/> is null.</exception>
public RestoreOperation(string id, KeyVaultBackupClient client)
public RestoreOperation(KeyVaultBackupClient client, string id)
{
Argument.AssertNotNull(id, nameof(id));
Argument.AssertNotNull(client, nameof(client));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,15 @@ public BackupRestoreTestBase(bool isAsync) : base(isAsync)
Sanitizer = new BackupRestoreRecordedTestSanitizer();
}

private KeyVaultBackupClient GetClient(TestRecording recording = null)
internal KeyVaultBackupClient GetClient(TestRecording recording = null, bool isInstrumented = true)
{
recording ??= Recording;

return InstrumentClient
(new KeyVaultBackupClient(
new Uri(TestEnvironment.KeyVaultUrl),
TestEnvironment.Credential,
recording.InstrumentClientOptions(new KeyVaultBackupClientOptions())));

var client = new KeyVaultBackupClient(
new Uri(TestEnvironment.KeyVaultUrl),
TestEnvironment.Credential,
recording.InstrumentClientOptions(new KeyVaultBackupClientOptions()));
return isInstrumented ? InstrumentClient(client) : client;
}


Expand Down
Loading