public async Task BackupAndRestoreMultiPartFolderName()
        {
            var source = new CancellationTokenSource(Timeout);

            UriBuilder builder = new UriBuilder(TestEnvironment.StorageUri);

            builder.Path = BlobContainerNameMultiPart;

            // Start the backup.
            KeyVaultBackupOperation backupOperation = await Client.StartBackupAsync(builder.Uri, "?" + SasToken, source.Token);

            // Wait for completion of the LRO.
            KeyVaultBackupResult backupResult = await backupOperation.WaitForCompletionAsync(source.Token);

            await WaitForOperationAsync();

            Assert.That(source.IsCancellationRequested, Is.False);
            Assert.That(backupResult, Is.Not.Null);
            Assert.That(backupOperation.HasValue, Is.True);

            // Start the restore.
            KeyVaultRestoreOperation restoreOperation = await Client.StartRestoreAsync(backupResult.FolderUri, "?" + SasToken, source.Token);

            // Wait for completion of the LRO
            var restoreResult = await restoreOperation.WaitForCompletionAsync(source.Token);

            await WaitForOperationAsync();

            Assert.That(source.IsCancellationRequested, Is.False);
            Assert.That(restoreResult, Is.Not.Null);
            Assert.That(restoreOperation.HasValue, Is.True);
        }
示例#2
0
        public void UpdateStatusThrowsOnError()
        {
            // setup the GetBackupDetailsAsync to return a failed response
            var mockClient = new Mock <KeyVaultBackupClient>();

            mockClient
            .Setup(m => m.GetBackupDetailsAsync(It.IsAny <string>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(failedResponse.Object);

            var operation = new KeyVaultBackupOperation(mockClient.Object, JobId);

            Assert.ThrowsAsync <RequestFailedException>(async() => await operation.UpdateStatusAsync(default));
示例#3
0
        public async Task BackupAndRestoreSampleAsync()
        {
            var blobStorageUrl    = TestEnvironment.StorageUri;
            var blobContainerName = BlobContainerName;
            var sasToken          = "?" + SasToken;

            // Create a Uri with the storage container.
            UriBuilder builder = new UriBuilder(blobStorageUrl)
            {
                Path = blobContainerName,
            };

            // Make sure we have a key to back up and restore.
            KeyVaultKey key = await KeyClient.CreateKeyAsync(Recording.GenerateId(), KeyType.Oct);

            string keyName = key.Name;

            RegisterKeyForCleanup(keyName);

            // Start the backup.
            KeyVaultBackupOperation backupOperation = await Client.StartBackupAsync(builder.Uri, sasToken);

            // Wait for completion of the BackupOperation.
            Response <KeyVaultBackupResult> backupResult = await backupOperation.WaitForCompletionAsync();

            await WaitForOperationAsync();

            // Get the Uri for the location of you backup blob.
            Uri folderUri = backupResult.Value.FolderUri;

            Assert.That(folderUri, Is.Not.Null);
            Assert.That(backupOperation.HasValue, Is.True);

            #region Snippet:SelectiveRestoreAsync
#if SNIPPET
            string keyName = "<key name to restore>";
#endif

            // Start the restore for a specific key that was previously backed up using the backupBlobUri returned from a previous BackupOperation.
            KeyVaultSelectiveKeyRestoreOperation restoreOperation = await Client.StartSelectiveRestoreAsync(keyName, folderUri, sasToken);

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

            #endregion

            Assert.That(restoreOperation.HasValue, Is.True);
            Assert.That(restoreResult.StartTime, Is.Not.EqualTo(default));
        public async Task BackupAndRestoreSampleAsync()
        {
            var blobStorageUrl    = TestEnvironment.StorageUri;
            var blobContainerName = BlobContainerName;
            var sasToken          = "?" + SasToken;

            #region Snippet:HelloFullBackupAsync
            // Create a Uri with the storage container
            UriBuilder builder = new UriBuilder(blobStorageUrl)
            {
                Path = blobContainerName,
            };

            // Start the backup.
            KeyVaultBackupOperation backupOperation = await Client.StartBackupAsync(builder.Uri, sasToken);

            // Wait for completion of the BackupOperation.
            Response <KeyVaultBackupResult> backupResult = await backupOperation.WaitForCompletionAsync();

            // Get the Uri for the location of your backup blob.
            Uri folderUri = backupResult.Value.FolderUri;
            #endregion

            Assert.That(folderUri, Is.Not.Null);
            Assert.That(backupOperation.HasValue, Is.True);

            await WaitForOperationAsync();

            #region Snippet:HelloFullRestoreAsync
            // Start the restore using the backupBlobUri returned from a previous BackupOperation.
            KeyVaultRestoreOperation restoreOperation = await Client.StartRestoreAsync(folderUri, sasToken);

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

            #endregion

            Assert.That(restoreOperation.HasValue, Is.True);
            Assert.That(restoreResult.Value.StartTime, Is.Not.EqualTo(default));
示例#5
0
        public async Task ResumeBackupRestore()
        {
            var blobStorageUrl    = TestEnvironment.StorageUri;
            var blobContainerName = BlobContainerName;
            var sasToken          = "?" + SasToken;
            var client            = GetClient(false);

            // Create a Uri with the storage container
            UriBuilder builder = new UriBuilder(blobStorageUrl)
            {
                Path = blobContainerName,
            };

            // Start the backup.
            KeyVaultBackupOperation originalBackupOperation = await Client.StartBackupAsync(builder.Uri, sasToken);

            var backupOperationId = originalBackupOperation.Id;

            #region Snippet:ResumeBackupAsync
#if SNIPPET
            // Construct a new KeyVaultBackupClient or use an existing one.
            KeyVaultBackupClient client = new KeyVaultBackupClient(new Uri(managedHsmUrl), new DefaultAzureCredential());
#endif

            // Construct a BackupOperation using a KeyVaultBackupClient and the Id from a previously started operation.
            KeyVaultBackupOperation backupOperation = new KeyVaultBackupOperation(client, backupOperationId);
#if !SNIPPET
            backupOperation._retryAfterSeconds = (int)PollingInterval.TotalSeconds;
#endif

            // Wait for completion of the BackupOperation.
            Response <KeyVaultBackupResult> backupResult = await backupOperation.WaitForCompletionAsync();

            // Get the Uri for the location of you backup blob.
            Uri folderUri = backupResult.Value.FolderUri;
            #endregion

            Assert.That(folderUri, Is.Not.Null);
            Assert.That(backupOperation.HasValue, Is.True);

            await WaitForOperationAsync();

            // Start the restore using the backupBlobUri returned from a previous BackupOperation.
            KeyVaultRestoreOperation originalRestoreOperation = await Client.StartRestoreAsync(folderUri, sasToken);

            var restoreOperationId = originalRestoreOperation.Id;

            #region Snippet:ResumeRestoreAsync
#if SNIPPET
            // Construct a new KeyVaultBackupClient or use an existing one.
            KeyVaultBackupClient Client = new KeyVaultBackupClient(new Uri(managedHsmUrl), new DefaultAzureCredential());
#endif

            // Construct a RestoreOperation using a KeyVaultBackupClient and the Id from a previously started operation.
            KeyVaultRestoreOperation restoreOperation = new KeyVaultRestoreOperation(client, restoreOperationId);
#if !SNIPPET
            restoreOperation._operationInternal._retryAfterSeconds = (int)PollingInterval.TotalSeconds;
#endif

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

            #endregion

            Assert.That(restoreOperation.HasValue, Is.True);
            Assert.That(restoreResult.StartTime, Is.Not.EqualTo(default));