/// <summary> /// Initiates a selective Restore of the Key Vault. /// </summary> /// <param name="keyName">The name of the key to be restored from the supplied backup.</param> /// <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 path 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 KeyVaultSelectiveKeyRestoreOperation StartSelectiveRestore(string keyName, Uri folderUri, string sasToken, CancellationToken cancellationToken = default) { using DiagnosticScope scope = _diagnostics.CreateScope($"{nameof(KeyVaultBackupClient)}.{nameof(StartSelectiveRestore)}"); scope.Start(); try { // Get the folder name from the backupBlobUri returned from a previous BackupOperation string[] uriSegments = folderUri.Segments; string folderName = uriSegments[uriSegments.Length - 1]; string containerUriString = folderUri.AbsoluteUri.Substring(0, folderUri.AbsoluteUri.LastIndexOf("/", StringComparison.OrdinalIgnoreCase)); var response = _restClient.SelectiveKeyRestoreOperation( VaultUri.AbsoluteUri, keyName, new SelectiveKeyRestoreOperationParameters( new SASTokenParameter( containerUriString, sasToken), folderName), cancellationToken); return(new KeyVaultSelectiveKeyRestoreOperation(this, response)); } catch (Exception ex) { scope.Failed(ex); throw; } }
/// <summary> /// Initiates a selective Restore of the Key Vault. /// </summary> /// <param name="keyName">The name of the key to be restored from the supplied backup.</param> /// <param name="blobStorageUri">The <see cref="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 name of 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 RestoreOperation StartSelectiveRestore(string keyName, Uri blobStorageUri, string sasToken, string folderName = default, CancellationToken cancellationToken = default) { using DiagnosticScope scope = _diagnostics.CreateScope($"{nameof(KeyVaultBackupClient)}.{nameof(StartSelectiveRestore)}"); scope.Start(); try { var response = _restClient.SelectiveKeyRestoreOperation( VaultUri.AbsoluteUri, keyName, new SelectiveKeyRestoreOperationParameters(new SASTokenParameter(blobStorageUri.AbsoluteUri, sasToken), folderName), cancellationToken); return(new RestoreOperation(this, response)); } catch (Exception ex) { scope.Failed(ex); throw; } }