/// <summary> /// Initializes a new instance of a BackupOperation. /// </summary> /// <param name="client">An instance of <see cref="KeyVaultBackupClient" />.</param> /// <param name="response">The <see cref="ResponseWithHeaders{T, THeaders}" /> returned from <see cref="KeyVaultBackupClient.StartBackup(Uri, string, CancellationToken)"/> or <see cref="KeyVaultBackupClient.StartBackupAsync(Uri, string, CancellationToken)"/>.</param> internal BackupOperation(KeyVaultBackupClient client, ResponseWithHeaders <FullBackupDetailsInternal, ServiceFullBackupHeaders> response) { _client = client; _response = response; _retryAfterSeconds = response.Headers.RetryAfter; _value = response.Value ?? throw new InvalidOperationException("The response does not contain a value."); }
/// <summary> /// Initializes a new instance of a BackupOperation. /// </summary> /// <param name="client">An instance of <see cref="KeyVaultBackupClient" />.</param> /// <param name="response">The <see cref="ResponseWithHeaders{T, THeaders}" /> returned from <see cref="KeyVaultBackupClient.StartBackup(Uri, string, CancellationToken)"/> or <see cref="KeyVaultBackupClient.StartBackupAsync(Uri, string, CancellationToken)"/>.</param> internal BackupOperation(KeyVaultBackupClient client, ResponseWithHeaders <ServiceFullBackupHeaders> response) { _client = client; _response = response; _retryAfterSeconds = response.Headers.RetryAfter; _id = response.Headers.JobId() ?? throw new InvalidOperationException("The response does not contain an Id"); }
/// <summary> /// Creates an instance of a BackupOperation from a previously started operation. <see cref="UpdateStatus(CancellationToken)"/>, <see cref="UpdateStatusAsync(CancellationToken)"/>, /// <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> /// <exception cref="ArgumentNullException"><paramref name="id"/> or <paramref name="client"/> is null.</exception> public BackupOperation(string id, KeyVaultBackupClient client) { Argument.AssertNotNull(id, nameof(id)); Argument.AssertNotNull(client, nameof(client)); _client = client; _value = new FullBackupDetailsInternal(string.Empty, string.Empty, null, null, null, id, string.Empty); }
/// <summary> /// Creates an instance of a RestoreOperation from a previously started operation. /// <see cref="WaitForCompletionAsync(CancellationToken)"/>, or <see cref="WaitForCompletionAsync(TimeSpan, CancellationToken)"/> must be called /// to re-populate the details of this operation. /// </summary> /// <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 RestoreOperationInternal(KeyVaultBackupClient client, string id) { Argument.AssertNotNull(id, nameof(id)); Argument.AssertNotNull(client, nameof(client)); _client = client; _id = id; }
/// <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 RestoreDetailsInternal( null, null, errorMessage == null ? null : new KeyVaultServiceError(string.Empty, errorMessage, null), id, startTime, endTime), response, client);
/// <summary> /// Creates an instance of a BackupOperation from a previously started operation. <see cref="UpdateStatus(CancellationToken)"/>, <see cref="UpdateStatusAsync(CancellationToken)"/>, /// <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> /// <exception cref="ArgumentNullException"><paramref name="id"/> or <paramref name="client"/> is null.</exception> public BackupOperation(string id, KeyVaultBackupClient client) { Argument.AssertNotNull(id, nameof(id)); Argument.AssertNotNull(client, nameof(client)); _client = client; _id = id; }
/// <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);
/// <summary> /// Initializes a new instance of a RestoreOperation. /// </summary> /// <param name="client">An instance of <see cref="KeyVaultBackupClient" />.</param> /// <param name="response">The <see cref="ResponseWithHeaders{T, THeaders}" /> returned from <see cref="KeyVaultBackupClient.StartSelectiveRestore(string, Uri, string, string, CancellationToken)"/> or <see cref="KeyVaultBackupClient.StartSelectiveRestoreAsync(string, Uri, string, string, CancellationToken)"/>.</param> /// <exception cref="ArgumentNullException"><paramref name="client"/> or <paramref name="response"/> is null.</exception> internal RestoreOperation(KeyVaultBackupClient client, ResponseWithHeaders <ServiceSelectiveKeyRestoreOperationHeaders> response) { Argument.AssertNotNull(client, nameof(client)); Argument.AssertNotNull(response, nameof(response)); _id = response.Headers.JobId() ?? throw new InvalidOperationException("The response does not contain an Id"); _client = client; _response = response.GetRawResponse(); _retryAfterSeconds = response.Headers.RetryAfter; }
/// <summary> /// Initializes a new instance of a RestoreOperation. /// </summary> /// <param name="client">An instance of <see cref="KeyVaultBackupClient" />.</param> /// <param name="response">The <see cref="ResponseWithHeaders{T, THeaders}" /> returned from <see cref="KeyVaultBackupClient.StartRestore(Uri, string, string, CancellationToken)"/> or <see cref="KeyVaultBackupClient.StartRestoreAsync(Uri, string, string, CancellationToken)"/>.</param> internal RestoreOperation(KeyVaultBackupClient client, ResponseWithHeaders <FullRestoreDetailsInternal, ServiceFullRestoreOperationHeaders> response) { Argument.AssertNotNull(client, nameof(client)); Argument.AssertNotNull(response, nameof(response)); _value = response.Value ?? throw new InvalidOperationException("The response does not contain a value."); _client = client; _response = response.GetRawResponse(); _retryAfterSeconds = response.Headers.RetryAfter; }
/// <summary> /// Initializes a new instance of a BackupOperation for mocking purposes. /// </summary> /// <param name="value">The <see cref="FullBackupDetailsInternal" /> that will be returned from <see cref="Value" />.</param> /// <param name="response">The <see cref="Response" /> that will be returned from <see cref="GetRawResponse" />.</param> /// <param name="client">An instance of <see cref="KeyVaultBackupClient" />.</param> internal BackupOperation(FullBackupDetailsInternal value, Response response, KeyVaultBackupClient client) { Argument.AssertNotNull(value, nameof(value)); Argument.AssertNotNull(response, nameof(response)); Argument.AssertNotNull(client, nameof(client)); _response = response; _value = value; _client = client; }
/// <summary> /// Initializes a new instance of a RestoreOperation for mocking purposes. /// </summary> /// <param name="value">The <see cref="RestoreDetailsInternal" /> that will be used to populate various properties.</param> /// <param name="response">The <see cref="Response" /> that will be returned from <see cref="GetRawResponse" />.</param> /// <param name="client">An instance of <see cref="KeyVaultBackupClient" />.</param> /// <exception cref="ArgumentNullException"><paramref name="value"/> or <paramref name="response"/> or <paramref name="client"/> is null.</exception> internal RestoreOperation(RestoreDetailsInternal value, Response response, KeyVaultBackupClient client) { Argument.AssertNotNull(value, nameof(value)); Argument.AssertNotNull(response, nameof(response)); Argument.AssertNotNull(client, nameof(client)); _client = client; _response = response; _value = value; _id = value.JobId; }
/// <summary> /// Initializes a new instance of a RestoreOperation for mocking purposes. /// </summary> /// <param name="value">The response value that will be used to populate various properties.</param> /// <param name="response">The <see cref="Response" /> that will be returned from <see cref="GetRawResponse" />.</param> /// <param name="client">An instance of <see cref="KeyVaultBackupClient" />.</param> /// <exception cref="ArgumentNullException"><paramref name="value"/> or <paramref name="response"/> or <paramref name="client"/> is null.</exception> internal RestoreOperationInternal(TResponseType value, Response response, KeyVaultBackupClient client) { Argument.AssertNotNull(value, nameof(value)); Argument.AssertNotNull(response, nameof(response)); Argument.AssertNotNull(client, nameof(client)); _client = client; _response = response; _value = value; _id = value switch { SelectiveKeyRestoreDetailsInternal r => r.JobId, RestoreDetailsInternal r => r.JobId, null => default,
/// <summary> /// Initializes a new instance of a RestoreOperation. /// </summary> /// <param name="client">An instance of <see cref="KeyVaultBackupClient" />.</param> /// <param name="response">The <see cref="ResponseWithHeaders{T, THeaders}" /> returned from <see cref="KeyVaultBackupClient.StartRestore"/> or <see cref="KeyVaultBackupClient.StartRestoreAsync"/>.</param> /// <exception cref="ArgumentNullException"><paramref name="client"/> or <paramref name="response"/> is null.</exception> internal RestoreOperationInternal(KeyVaultBackupClient client, ResponseWithHeaders <THeaders> response) { Argument.AssertNotNull(client, nameof(client)); Argument.AssertNotNull(response, nameof(response)); _client = client; _response = response.GetRawResponse(); if (response is ResponseWithHeaders <AzureSecurityKeyVaultAdministrationFullRestoreOperationHeaders> fullRestoreHeaders) { _id = fullRestoreHeaders.Headers.JobId() ?? throw new InvalidOperationException("The response does not contain an Id"); _retryAfterSeconds = fullRestoreHeaders.Headers.RetryAfter; } else if (response is ResponseWithHeaders <AzureSecurityKeyVaultAdministrationSelectiveKeyRestoreOperationHeaders> selectiveRestoreHeaders) { _id = selectiveRestoreHeaders.Headers.JobId() ?? throw new InvalidOperationException("The response does not contain an Id"); _retryAfterSeconds = selectiveRestoreHeaders.Headers.RetryAfter; } else { throw new ArgumentException("Invalid header type", nameof(response)); } }
/// <summary> /// Initializes a new instance of a SelectiveKeyRestoreOperation. /// </summary> /// <param name="client">An instance of <see cref="KeyVaultBackupClient" />.</param> /// <param name="response">The <see cref="ResponseWithHeaders{T, THeaders}" /> returned from <see cref="KeyVaultBackupClient.StartRestore"/> or <see cref="KeyVaultBackupClient.StartRestoreAsync"/>.</param> /// <exception cref="ArgumentNullException"><paramref name="client"/> or <paramref name="response"/> is null.</exception> internal SelectiveKeyRestoreOperation(KeyVaultBackupClient client, ResponseWithHeaders <AzureSecurityKeyVaultAdministrationSelectiveKeyRestoreOperationHeaders> response) { _operationInternal = new RestoreOperationInternal <AzureSecurityKeyVaultAdministrationSelectiveKeyRestoreOperationHeaders, SelectiveKeyRestoreResult>(client, response); }
/// <summary> /// Initializes a new instance of a RestoreOperation for mocking purposes. /// </summary> /// <param name="value">The <see cref="RestoreDetailsInternal" /> that will be used to populate various properties.</param> /// <param name="response">The <see cref="Response" /> that will be returned from <see cref="GetRawResponse" />.</param> /// <param name="client">An instance of <see cref="KeyVaultBackupClient" />.</param> /// <exception cref="ArgumentNullException"><paramref name="value"/> or <paramref name="response"/> or <paramref name="client"/> is null.</exception> internal RestoreOperation(RestoreDetailsInternal value, Response response, KeyVaultBackupClient client) { _operationInternal = new RestoreOperationInternal <AzureSecurityKeyVaultAdministrationFullRestoreOperationHeaders, RestoreResult, RestoreDetailsInternal>(value, response, client); }
/// <summary> /// Initializes a new instance of a RestoreOperation. /// </summary> /// <param name="client">An instance of <see cref="KeyVaultBackupClient" />.</param> /// <param name="response">The <see cref="ResponseWithHeaders{T, THeaders}" /> returned from <see cref="KeyVaultBackupClient.StartRestore"/> or <see cref="KeyVaultBackupClient.StartRestoreAsync"/>.</param> /// <exception cref="ArgumentNullException"><paramref name="client"/> or <paramref name="response"/> is null.</exception> internal RestoreOperation(KeyVaultBackupClient client, ResponseWithHeaders <AzureSecurityKeyVaultAdministrationFullRestoreOperationHeaders> response) { _operationInternal = new RestoreOperationInternal <AzureSecurityKeyVaultAdministrationFullRestoreOperationHeaders, RestoreResult, RestoreDetailsInternal>(client, response); }
/// <summary> /// Creates an instance of a RestoreOperation from a previously started operation. <see cref="UpdateStatus(CancellationToken)"/>, <see cref="UpdateStatusAsync(CancellationToken)"/>, /// <see cref="WaitForCompletionAsync(CancellationToken)"/>, or <see cref="WaitForCompletionAsync(TimeSpan, CancellationToken)"/> must be called /// to re-populate the details of this operation. /// </summary> /// <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(KeyVaultBackupClient client, string id) { _operationInternal = new RestoreOperationInternal <AzureSecurityKeyVaultAdministrationFullRestoreOperationHeaders, RestoreResult, RestoreDetailsInternal>(client, id); }
/// <summary> /// Creates an instance of a SelectiveKeyRestoreOperation from a previously started operation. <see cref="UpdateStatus(CancellationToken)"/>, <see cref="UpdateStatusAsync(CancellationToken)"/>, /// <see cref="WaitForCompletionAsync(CancellationToken)"/>, or <see cref="WaitForCompletionAsync(TimeSpan, CancellationToken)"/> must be called /// to re-populate the details of this operation. /// </summary> /// <param name="client">An instance of <see cref="KeyVaultBackupClient" />.</param> /// <param name="id">The <see cref="Id" /> from a previous <see cref="KeyVaultBackupOperation" />.</param> /// <exception cref="ArgumentNullException"><paramref name="id"/> or <paramref name="client"/> is null.</exception> public KeyVaultSelectiveKeyRestoreOperation(KeyVaultBackupClient client, string id) { _operationInternal = new RestoreOperationInternal <AzureSecurityKeyVaultAdministrationSelectiveKeyRestoreOperationHeaders, KeyVaultSelectiveKeyRestoreResult, SelectiveKeyRestoreDetailsInternal>(client, id); }