/// <summary> /// Initiates a full restore of the Key Vault. /// </summary> /// <param name="folderUri"> /// The <see cref="Uri"/> for the blob storage resource, including the path to the blob container where the backup resides. /// This would be the exact value that is returned as the result of a <see cref="KeyVaultBackupOperation"/>. /// An example Uri may look like the following: https://contoso.blob.core.windows.net/backup/mhsm-contoso-2020090117323313. /// </param> /// <param name="sasToken">A Shared Access Signature (SAS) token to authorize access to the blob.</param> /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> /// <exception cref="ArgumentNullException"><paramref name="folderUri"/> or <paramref name="sasToken"/> is null.</exception> /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> for details returned from the server.</exception> /// <returns>A <see cref="KeyVaultRestoreOperation"/> to wait on this long-running operation.</returns> public virtual async Task <KeyVaultRestoreOperation> StartRestoreAsync(Uri folderUri, string sasToken, CancellationToken cancellationToken = default) { using DiagnosticScope scope = _diagnostics.CreateScope($"{nameof(KeyVaultBackupClient)}.{nameof(StartRestore)}"); scope.Start(); try { // Get the folder name from the backupBlobUri returned from a previous BackupOperation ParseFolderName(folderUri, out string containerUriString, out string folderName); var response = await _restClient.FullRestoreOperationAsync( VaultUri.AbsoluteUri, new RestoreOperationParameters( new SASTokenParameter( containerUriString, sasToken), folderName), cancellationToken).ConfigureAwait(false); return(new KeyVaultRestoreOperation(this, response)); } catch (Exception ex) { scope.Failed(ex); throw; } }
/// <summary> /// Initiates a full restore of the Key Vault. /// </summary> /// <param name="backupFolderUri"> /// The <see cref="Uri"/> for the blob storage resource, including the path to the blob container where the backup resides. /// This would be the exact value that is returned as the result of a <see cref="BackupOperation"/>. /// An example Uri may look like the following: https://contoso.blob.core.windows.net/backup/mhsm-contoso-2020090117323313. /// </param> /// <param name="sasToken">A Shared Access Signature (SAS) token to authorize access to the blob.</param> /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> /// <exception cref="ArgumentNullException"><paramref name="backupFolderUri"/> or <paramref name="sasToken"/> is null.</exception> /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> for details returned from the server.</exception> /// <returns>A <see cref="RestoreOperation"/> to wait on this long-running operation.</returns> public virtual async Task <RestoreOperation> StartRestoreAsync(Uri backupFolderUri, string sasToken, CancellationToken cancellationToken = default) { using DiagnosticScope scope = _diagnostics.CreateScope($"{nameof(KeyVaultBackupClient)}.{nameof(StartRestore)}"); scope.Start(); try { // Get the folder name from the backupBlobUri returned from a previous BackupOperation string[] uriSegments = backupFolderUri.Segments; string folderName = uriSegments[uriSegments.Length - 1]; string containerUriString = backupFolderUri.AbsoluteUri.Substring(0, backupFolderUri.AbsoluteUri.LastIndexOf("/", StringComparison.OrdinalIgnoreCase)); var response = await _restClient.FullRestoreOperationAsync( VaultUri.AbsoluteUri, new RestoreOperationParameters( new SASTokenParameter( containerUriString, sasToken), folderName), cancellationToken).ConfigureAwait(false); return(new RestoreOperation(this, response)); } catch (Exception ex) { scope.Failed(ex); throw; } }
/// <summary> /// Initiates a full restore of the Key Vault. /// </summary> /// <param name="blobStorageUri">The Uri for the blob storage resource.</param> /// <param name="sasToken">A Shared Access Signature (SAS) token to authorize access to the blob.</param> /// <param name="folderName">The nameof the container containing the backup data to restore</param> /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> /// <exception cref="ArgumentNullException"><paramref name="blobStorageUri"/> or <paramref name="sasToken"/> is null.</exception> /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> for details returned from the server.</exception> /// <returns>A <see cref="RestoreOperation"/> to wait on this long-running operation.</returns> public virtual async Task <RestoreOperation> StartRestoreAsync(Uri blobStorageUri, string sasToken, string folderName, CancellationToken cancellationToken = default) { using DiagnosticScope scope = _diagnostics.CreateScope($"{nameof(KeyVaultBackupClient)}.{nameof(StartRestore)}"); scope.Start(); try { var response = await _restClient.FullRestoreOperationAsync( VaultUri.AbsoluteUri, new RestoreOperationParameters( new SASTokenParameter(blobStorageUri.AbsoluteUri, sasToken), folderName), cancellationToken).ConfigureAwait(false); return(new RestoreOperation(this, response)); } catch (Exception ex) { scope.Failed(ex); throw; } }