< Summary

Class:Azure.Security.KeyVault.Administration.BackupRestoreRestClient
Assembly:Azure.Security.KeyVault.Administration
File(s):C:\Git\azure-sdk-for-net\sdk\keyvault\Azure.Security.KeyVault.Administration\src\Generated\BackupRestoreRestClient.cs
Covered lines:102
Uncovered lines:77
Coverable lines:179
Total lines:416
Line coverage:56.9% (102 of 179)
Covered branches:19
Total branches:60
Branch coverage:31.6% (19 of 60)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-85.71%50%
CreateFullBackupRequest(...)-100%100%
FullBackupAsync()-77.78%50%
FullBackup(...)-77.78%50%
CreateFullBackupStatusRequest(...)-100%100%
FullBackupStatusAsync()-75%50%
FullBackupStatus(...)-0%0%
CreateFullRestoreOperationRequest(...)-100%100%
FullRestoreOperationAsync()-77.78%50%
FullRestoreOperation(...)-77.78%50%
CreateRestoreStatusRequest(...)-100%100%
RestoreStatusAsync()-75%50%
RestoreStatus(...)-0%0%
CreateSelectiveKeyRestoreOperationRequest(...)-0%0%
SelectiveKeyRestoreOperationAsync()-0%0%
SelectiveKeyRestoreOperation(...)-0%0%

File(s)

C:\Git\azure-sdk-for-net\sdk\keyvault\Azure.Security.KeyVault.Administration\src\Generated\BackupRestoreRestClient.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4// <auto-generated/>
 5
 6#nullable disable
 7
 8using System;
 9using System.Text.Json;
 10using System.Threading;
 11using System.Threading.Tasks;
 12using Azure;
 13using Azure.Core;
 14using Azure.Core.Pipeline;
 15using Azure.Security.KeyVault.Administration.Models;
 16
 17namespace Azure.Security.KeyVault.Administration
 18{
 19    internal partial class BackupRestoreRestClient
 20    {
 21        private string apiVersion;
 22        private ClientDiagnostics _clientDiagnostics;
 23        private HttpPipeline _pipeline;
 24
 25        /// <summary> Initializes a new instance of BackupRestoreRestClient. </summary>
 26        /// <param name="clientDiagnostics"> The handler for diagnostic messaging in the client. </param>
 27        /// <param name="pipeline"> The HTTP pipeline for sending and receiving REST requests and responses. </param>
 28        /// <param name="apiVersion"> Api Version. </param>
 29        /// <exception cref="ArgumentNullException"> <paramref name="apiVersion"/> is null. </exception>
 830        public BackupRestoreRestClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string apiVersion = "
 31        {
 832            if (apiVersion == null)
 33            {
 034                throw new ArgumentNullException(nameof(apiVersion));
 35            }
 36
 837            this.apiVersion = apiVersion;
 838            _clientDiagnostics = clientDiagnostics;
 839            _pipeline = pipeline;
 840        }
 41
 42        internal HttpMessage CreateFullBackupRequest(string vaultBaseUrl, SASTokenParameter azureStorageBlobContainerUri
 43        {
 444            var message = _pipeline.CreateMessage();
 445            var request = message.Request;
 446            request.Method = RequestMethod.Post;
 447            var uri = new RawRequestUriBuilder();
 448            uri.AppendRaw(vaultBaseUrl, false);
 449            uri.AppendPath("/backup", false);
 450            uri.AppendQuery("api-version", apiVersion, true);
 451            request.Uri = uri;
 452            request.Headers.Add("Content-Type", "application/json");
 453            if (azureStorageBlobContainerUri != null)
 54            {
 455                var content = new Utf8JsonRequestContent();
 456                content.JsonWriter.WriteObjectValue(azureStorageBlobContainerUri);
 457                request.Content = content;
 58            }
 459            return message;
 60        }
 61
 62        /// <summary> Creates a full backup using a user-provided SAS token to an Azure blob storage container. </summar
 63        /// <param name="vaultBaseUrl"> The vault name, for example https://myvault.vault.azure.net. </param>
 64        /// <param name="azureStorageBlobContainerUri"> Azure blob shared access signature token pointing to a valid Azu
 65        /// <param name="cancellationToken"> The cancellation token to use. </param>
 66        /// <exception cref="ArgumentNullException"> <paramref name="vaultBaseUrl"/> is null. </exception>
 67        public async Task<ResponseWithHeaders<ServiceFullBackupHeaders>> FullBackupAsync(string vaultBaseUrl, SASTokenPa
 68        {
 269            if (vaultBaseUrl == null)
 70            {
 071                throw new ArgumentNullException(nameof(vaultBaseUrl));
 72            }
 73
 274            using var message = CreateFullBackupRequest(vaultBaseUrl, azureStorageBlobContainerUri);
 275            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 276            var headers = new ServiceFullBackupHeaders(message.Response);
 277            switch (message.Response.Status)
 78            {
 79                case 202:
 280                    return ResponseWithHeaders.FromValue(headers, message.Response);
 81                default:
 082                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 83            }
 284        }
 85
 86        /// <summary> Creates a full backup using a user-provided SAS token to an Azure blob storage container. </summar
 87        /// <param name="vaultBaseUrl"> The vault name, for example https://myvault.vault.azure.net. </param>
 88        /// <param name="azureStorageBlobContainerUri"> Azure blob shared access signature token pointing to a valid Azu
 89        /// <param name="cancellationToken"> The cancellation token to use. </param>
 90        /// <exception cref="ArgumentNullException"> <paramref name="vaultBaseUrl"/> is null. </exception>
 91        public ResponseWithHeaders<ServiceFullBackupHeaders> FullBackup(string vaultBaseUrl, SASTokenParameter azureStor
 92        {
 293            if (vaultBaseUrl == null)
 94            {
 095                throw new ArgumentNullException(nameof(vaultBaseUrl));
 96            }
 97
 298            using var message = CreateFullBackupRequest(vaultBaseUrl, azureStorageBlobContainerUri);
 299            _pipeline.Send(message, cancellationToken);
 2100            var headers = new ServiceFullBackupHeaders(message.Response);
 2101            switch (message.Response.Status)
 102            {
 103                case 202:
 2104                    return ResponseWithHeaders.FromValue(headers, message.Response);
 105                default:
 0106                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 107            }
 2108        }
 109
 110        internal HttpMessage CreateFullBackupStatusRequest(string vaultBaseUrl, string jobId)
 111        {
 10112            var message = _pipeline.CreateMessage();
 10113            var request = message.Request;
 10114            request.Method = RequestMethod.Get;
 10115            var uri = new RawRequestUriBuilder();
 10116            uri.AppendRaw(vaultBaseUrl, false);
 10117            uri.AppendPath("/backup/", false);
 10118            uri.AppendPath(jobId, true);
 10119            uri.AppendPath("/pending", false);
 10120            uri.AppendQuery("api-version", apiVersion, true);
 10121            request.Uri = uri;
 10122            return message;
 123        }
 124
 125        /// <summary> Returns the status of full backup operation. </summary>
 126        /// <param name="vaultBaseUrl"> The vault name, for example https://myvault.vault.azure.net. </param>
 127        /// <param name="jobId"> The id returned as part of the backup request. </param>
 128        /// <param name="cancellationToken"> The cancellation token to use. </param>
 129        /// <exception cref="ArgumentNullException"> <paramref name="vaultBaseUrl"/> or <paramref name="jobId"/> is null
 130        public async Task<Response<FullBackupDetailsInternal>> FullBackupStatusAsync(string vaultBaseUrl, string jobId, 
 131        {
 10132            if (vaultBaseUrl == null)
 133            {
 0134                throw new ArgumentNullException(nameof(vaultBaseUrl));
 135            }
 10136            if (jobId == null)
 137            {
 0138                throw new ArgumentNullException(nameof(jobId));
 139            }
 140
 10141            using var message = CreateFullBackupStatusRequest(vaultBaseUrl, jobId);
 10142            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 10143            switch (message.Response.Status)
 144            {
 145                case 200:
 146                    {
 147                        FullBackupDetailsInternal value = default;
 10148                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 10149                        value = FullBackupDetailsInternal.DeserializeFullBackupDetailsInternal(document.RootElement);
 10150                        return Response.FromValue(value, message.Response);
 151                    }
 152                default:
 0153                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 154            }
 10155        }
 156
 157        /// <summary> Returns the status of full backup operation. </summary>
 158        /// <param name="vaultBaseUrl"> The vault name, for example https://myvault.vault.azure.net. </param>
 159        /// <param name="jobId"> The id returned as part of the backup request. </param>
 160        /// <param name="cancellationToken"> The cancellation token to use. </param>
 161        /// <exception cref="ArgumentNullException"> <paramref name="vaultBaseUrl"/> or <paramref name="jobId"/> is null
 162        public Response<FullBackupDetailsInternal> FullBackupStatus(string vaultBaseUrl, string jobId, CancellationToken
 163        {
 0164            if (vaultBaseUrl == null)
 165            {
 0166                throw new ArgumentNullException(nameof(vaultBaseUrl));
 167            }
 0168            if (jobId == null)
 169            {
 0170                throw new ArgumentNullException(nameof(jobId));
 171            }
 172
 0173            using var message = CreateFullBackupStatusRequest(vaultBaseUrl, jobId);
 0174            _pipeline.Send(message, cancellationToken);
 0175            switch (message.Response.Status)
 176            {
 177                case 200:
 178                    {
 179                        FullBackupDetailsInternal value = default;
 0180                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 0181                        value = FullBackupDetailsInternal.DeserializeFullBackupDetailsInternal(document.RootElement);
 0182                        return Response.FromValue(value, message.Response);
 183                    }
 184                default:
 0185                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 186            }
 0187        }
 188
 189        internal HttpMessage CreateFullRestoreOperationRequest(string vaultBaseUrl, RestoreOperationParameters restoreBl
 190        {
 4191            var message = _pipeline.CreateMessage();
 4192            var request = message.Request;
 4193            request.Method = RequestMethod.Put;
 4194            var uri = new RawRequestUriBuilder();
 4195            uri.AppendRaw(vaultBaseUrl, false);
 4196            uri.AppendPath("/restore", false);
 4197            uri.AppendQuery("api-version", apiVersion, true);
 4198            request.Uri = uri;
 4199            request.Headers.Add("Content-Type", "application/json");
 4200            if (restoreBlobDetails != null)
 201            {
 4202                var content = new Utf8JsonRequestContent();
 4203                content.JsonWriter.WriteObjectValue(restoreBlobDetails);
 4204                request.Content = content;
 205            }
 4206            return message;
 207        }
 208
 209        /// <summary> Restores all key materials using the SAS token pointing to a previously stored Azure Blob storage 
 210        /// <param name="vaultBaseUrl"> The vault name, for example https://myvault.vault.azure.net. </param>
 211        /// <param name="restoreBlobDetails"> The Azure blob SAS token pointing to a folder where the previous successfu
 212        /// <param name="cancellationToken"> The cancellation token to use. </param>
 213        /// <exception cref="ArgumentNullException"> <paramref name="vaultBaseUrl"/> is null. </exception>
 214        public async Task<ResponseWithHeaders<ServiceFullRestoreOperationHeaders>> FullRestoreOperationAsync(string vaul
 215        {
 2216            if (vaultBaseUrl == null)
 217            {
 0218                throw new ArgumentNullException(nameof(vaultBaseUrl));
 219            }
 220
 2221            using var message = CreateFullRestoreOperationRequest(vaultBaseUrl, restoreBlobDetails);
 2222            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 2223            var headers = new ServiceFullRestoreOperationHeaders(message.Response);
 2224            switch (message.Response.Status)
 225            {
 226                case 202:
 2227                    return ResponseWithHeaders.FromValue(headers, message.Response);
 228                default:
 0229                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 230            }
 2231        }
 232
 233        /// <summary> Restores all key materials using the SAS token pointing to a previously stored Azure Blob storage 
 234        /// <param name="vaultBaseUrl"> The vault name, for example https://myvault.vault.azure.net. </param>
 235        /// <param name="restoreBlobDetails"> The Azure blob SAS token pointing to a folder where the previous successfu
 236        /// <param name="cancellationToken"> The cancellation token to use. </param>
 237        /// <exception cref="ArgumentNullException"> <paramref name="vaultBaseUrl"/> is null. </exception>
 238        public ResponseWithHeaders<ServiceFullRestoreOperationHeaders> FullRestoreOperation(string vaultBaseUrl, Restore
 239        {
 2240            if (vaultBaseUrl == null)
 241            {
 0242                throw new ArgumentNullException(nameof(vaultBaseUrl));
 243            }
 244
 2245            using var message = CreateFullRestoreOperationRequest(vaultBaseUrl, restoreBlobDetails);
 2246            _pipeline.Send(message, cancellationToken);
 2247            var headers = new ServiceFullRestoreOperationHeaders(message.Response);
 2248            switch (message.Response.Status)
 249            {
 250                case 202:
 2251                    return ResponseWithHeaders.FromValue(headers, message.Response);
 252                default:
 0253                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 254            }
 2255        }
 256
 257        internal HttpMessage CreateRestoreStatusRequest(string vaultBaseUrl, string jobId)
 258        {
 12259            var message = _pipeline.CreateMessage();
 12260            var request = message.Request;
 12261            request.Method = RequestMethod.Get;
 12262            var uri = new RawRequestUriBuilder();
 12263            uri.AppendRaw(vaultBaseUrl, false);
 12264            uri.AppendPath("/restore/", false);
 12265            uri.AppendPath(jobId, true);
 12266            uri.AppendPath("/pending", false);
 12267            uri.AppendQuery("api-version", apiVersion, true);
 12268            request.Uri = uri;
 12269            return message;
 270        }
 271
 272        /// <summary> Returns the status of restore operation. </summary>
 273        /// <param name="vaultBaseUrl"> The vault name, for example https://myvault.vault.azure.net. </param>
 274        /// <param name="jobId"> The Job Id returned part of the restore operation. </param>
 275        /// <param name="cancellationToken"> The cancellation token to use. </param>
 276        /// <exception cref="ArgumentNullException"> <paramref name="vaultBaseUrl"/> or <paramref name="jobId"/> is null
 277        public async Task<Response<RestoreDetailsInternal>> RestoreStatusAsync(string vaultBaseUrl, string jobId, Cancel
 278        {
 12279            if (vaultBaseUrl == null)
 280            {
 0281                throw new ArgumentNullException(nameof(vaultBaseUrl));
 282            }
 12283            if (jobId == null)
 284            {
 0285                throw new ArgumentNullException(nameof(jobId));
 286            }
 287
 12288            using var message = CreateRestoreStatusRequest(vaultBaseUrl, jobId);
 12289            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 12290            switch (message.Response.Status)
 291            {
 292                case 200:
 293                    {
 294                        RestoreDetailsInternal value = default;
 12295                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 12296                        value = RestoreDetailsInternal.DeserializeRestoreDetailsInternal(document.RootElement);
 12297                        return Response.FromValue(value, message.Response);
 298                    }
 299                default:
 0300                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 301            }
 12302        }
 303
 304        /// <summary> Returns the status of restore operation. </summary>
 305        /// <param name="vaultBaseUrl"> The vault name, for example https://myvault.vault.azure.net. </param>
 306        /// <param name="jobId"> The Job Id returned part of the restore operation. </param>
 307        /// <param name="cancellationToken"> The cancellation token to use. </param>
 308        /// <exception cref="ArgumentNullException"> <paramref name="vaultBaseUrl"/> or <paramref name="jobId"/> is null
 309        public Response<RestoreDetailsInternal> RestoreStatus(string vaultBaseUrl, string jobId, CancellationToken cance
 310        {
 0311            if (vaultBaseUrl == null)
 312            {
 0313                throw new ArgumentNullException(nameof(vaultBaseUrl));
 314            }
 0315            if (jobId == null)
 316            {
 0317                throw new ArgumentNullException(nameof(jobId));
 318            }
 319
 0320            using var message = CreateRestoreStatusRequest(vaultBaseUrl, jobId);
 0321            _pipeline.Send(message, cancellationToken);
 0322            switch (message.Response.Status)
 323            {
 324                case 200:
 325                    {
 326                        RestoreDetailsInternal value = default;
 0327                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 0328                        value = RestoreDetailsInternal.DeserializeRestoreDetailsInternal(document.RootElement);
 0329                        return Response.FromValue(value, message.Response);
 330                    }
 331                default:
 0332                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 333            }
 0334        }
 335
 336        internal HttpMessage CreateSelectiveKeyRestoreOperationRequest(string vaultBaseUrl, string keyName, SelectiveKey
 337        {
 0338            var message = _pipeline.CreateMessage();
 0339            var request = message.Request;
 0340            request.Method = RequestMethod.Put;
 0341            var uri = new RawRequestUriBuilder();
 0342            uri.AppendRaw(vaultBaseUrl, false);
 0343            uri.AppendPath("/keys/", false);
 0344            uri.AppendPath(keyName, true);
 0345            uri.AppendPath("/restore", false);
 0346            uri.AppendQuery("api-version", apiVersion, true);
 0347            request.Uri = uri;
 0348            request.Headers.Add("Content-Type", "application/json");
 0349            if (restoreBlobDetails != null)
 350            {
 0351                var content = new Utf8JsonRequestContent();
 0352                content.JsonWriter.WriteObjectValue(restoreBlobDetails);
 0353                request.Content = content;
 354            }
 0355            return message;
 356        }
 357
 358        /// <summary> Restores all key versions of a given key using user supplied SAS token pointing to a previously st
 359        /// <param name="vaultBaseUrl"> The vault name, for example https://myvault.vault.azure.net. </param>
 360        /// <param name="keyName"> The name of the key to be restored from the user supplied backup. </param>
 361        /// <param name="restoreBlobDetails"> The Azure blob SAS token pointing to a folder where the previous successfu
 362        /// <param name="cancellationToken"> The cancellation token to use. </param>
 363        /// <exception cref="ArgumentNullException"> <paramref name="vaultBaseUrl"/> or <paramref name="keyName"/> is nu
 364        public async Task<ResponseWithHeaders<ServiceSelectiveKeyRestoreOperationHeaders>> SelectiveKeyRestoreOperationA
 365        {
 0366            if (vaultBaseUrl == null)
 367            {
 0368                throw new ArgumentNullException(nameof(vaultBaseUrl));
 369            }
 0370            if (keyName == null)
 371            {
 0372                throw new ArgumentNullException(nameof(keyName));
 373            }
 374
 0375            using var message = CreateSelectiveKeyRestoreOperationRequest(vaultBaseUrl, keyName, restoreBlobDetails);
 0376            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 0377            var headers = new ServiceSelectiveKeyRestoreOperationHeaders(message.Response);
 0378            switch (message.Response.Status)
 379            {
 380                case 202:
 0381                    return ResponseWithHeaders.FromValue(headers, message.Response);
 382                default:
 0383                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 384            }
 0385        }
 386
 387        /// <summary> Restores all key versions of a given key using user supplied SAS token pointing to a previously st
 388        /// <param name="vaultBaseUrl"> The vault name, for example https://myvault.vault.azure.net. </param>
 389        /// <param name="keyName"> The name of the key to be restored from the user supplied backup. </param>
 390        /// <param name="restoreBlobDetails"> The Azure blob SAS token pointing to a folder where the previous successfu
 391        /// <param name="cancellationToken"> The cancellation token to use. </param>
 392        /// <exception cref="ArgumentNullException"> <paramref name="vaultBaseUrl"/> or <paramref name="keyName"/> is nu
 393        public ResponseWithHeaders<ServiceSelectiveKeyRestoreOperationHeaders> SelectiveKeyRestoreOperation(string vault
 394        {
 0395            if (vaultBaseUrl == null)
 396            {
 0397                throw new ArgumentNullException(nameof(vaultBaseUrl));
 398            }
 0399            if (keyName == null)
 400            {
 0401                throw new ArgumentNullException(nameof(keyName));
 402            }
 403
 0404            using var message = CreateSelectiveKeyRestoreOperationRequest(vaultBaseUrl, keyName, restoreBlobDetails);
 0405            _pipeline.Send(message, cancellationToken);
 0406            var headers = new ServiceSelectiveKeyRestoreOperationHeaders(message.Response);
 0407            switch (message.Response.Status)
 408            {
 409                case 202:
 0410                    return ResponseWithHeaders.FromValue(headers, message.Response);
 411                default:
 0412                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 413            }
 0414        }
 415    }
 416}