示例#1
0
 /// <summary>
 /// Initializes a new instance of a FullRestoreOperation for mocking purposes.
 /// </summary>
 /// <param name="response">The <see cref="Response" /> that will be returned from <see cref="RestoreOperation.GetRawResponse" />.</param>
 /// <param name="client">An instance of <see cref="KeyVaultBackupClient" />.</param>
 /// <param name="id"> Identifier for the restore operation.</param>
 /// <param name="startTime"> The start time of the restore operation.</param>
 /// <param name="endTime"> The end time of the restore operation.</param>
 /// <param name="errorMessage">The error message generated from the operation, if any.</param>
 public static RestoreOperation RestoreOperation(Response response, KeyVaultBackupClient client, string id, DateTimeOffset?startTime = null, DateTimeOffset?endTime = null, string errorMessage = null) =>
 new RestoreOperation(new FullRestoreDetailsInternal(null,
                                                     null,
                                                     errorMessage == null ? null : new KeyVaultServiceError(string.Empty, errorMessage, null),
                                                     id,
                                                     startTime,
                                                     endTime), response, client);
        public void CreateClientSample()
        {
            var keyVaultUrl = TestEnvironment.KeyVaultUrl;

            #region Snippet:HelloCreateKeyVaultBackupClient
            KeyVaultBackupClient client = new KeyVaultBackupClient(new Uri(keyVaultUrl), new DefaultAzureCredential());
            #endregion
        }
示例#3
0
 /// <summary>
 /// Initializes a new instance of a FullBackupOperation for mocking purposes.
 /// </summary>
 /// <param name="response">The <see cref="Response" /> that will be returned from <see cref="BackupOperation.GetRawResponse" />.</param>
 /// <param name="client">An instance of <see cref="KeyVaultBackupClient" />.</param>
 /// <param name="id"> Identifier for the restore operation.</param>
 /// <param name="blobContainerUri">The Blob Container Uri containing the backup.</param>
 /// <param name="startTime"> The start time of the restore operation.</param>
 /// <param name="endTime"> The end time of the restore operation.</param>
 /// <param name="errorMessage">The error message generated from the operation, if any.</param>
 public static BackupOperation BackupOperation(Response response, KeyVaultBackupClient client, string id, Uri blobContainerUri, DateTimeOffset?startTime = null, DateTimeOffset?endTime = null, string errorMessage = null) =>
 new BackupOperation(new FullBackupDetailsInternal(null,
                                                   null,
                                                   errorMessage == null ? null : new KeyVaultServiceError(string.Empty, errorMessage, null),
                                                   startTime,
                                                   endTime,
                                                   id,
                                                   blobContainerUri.AbsoluteUri), response, client);
示例#4
0
        internal KeyVaultBackupClient GetClient(bool isInstrumented = true)
        {
            var client = new KeyVaultBackupClient(
                Uri,
                TestEnvironment.Credential,
                InstrumentClientOptions(new KeyVaultBackupClientOptions()));

            return(isInstrumented ? InstrumentClient(client) : client);
        }
        public void ParseFolderName(string uri, string expectedUri, string expectedFolder)
        {
            var folderUri = new Uri(uri);

            KeyVaultBackupClient.ParseFolderName(folderUri, out string containerUriString, out string folderName);

            Assert.That(containerUriString, Is.EqualTo(expectedUri));
            Assert.That(folderName, Is.EqualTo(expectedFolder));
        }
示例#6
0
        internal KeyVaultBackupClient GetClient(TestRecording recording = null, bool isInstrumented = true)
        {
            recording ??= Recording;

            var client = new KeyVaultBackupClient(
                new Uri(TestEnvironment.KeyVaultUrl),
                TestEnvironment.Credential,
                recording.InstrumentClientOptions(new KeyVaultBackupClientOptions()));

            return(isInstrumented ? InstrumentClient(client) : client);
        }
示例#7
0
        internal KeyVaultBackupClient GetClient(bool isInstrumented = true)
        {
            var client = new KeyVaultBackupClient(
                Uri,
                TestEnvironment.Credential,
                InstrumentClientOptions(new KeyVaultAdministrationClientOptions
            {
                Diagnostics =
                {
                    LoggedHeaderNames =
                    {
                        "x-ms-request-id",
                    },
                },
            }));

            return(isInstrumented ? InstrumentClient(client) : client);
        }
示例#8
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));