| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | // <auto-generated/> |
| | 5 | |
|
| | 6 | | #nullable disable |
| | 7 | |
|
| | 8 | | using System; |
| | 9 | | using System.Text.Json; |
| | 10 | | using System.Threading; |
| | 11 | | using System.Threading.Tasks; |
| | 12 | | using Azure; |
| | 13 | | using Azure.Core; |
| | 14 | | using Azure.Core.Pipeline; |
| | 15 | | using Azure.Template.Models; |
| | 16 | |
|
| | 17 | | namespace Azure.Template |
| | 18 | | { |
| | 19 | | internal partial class ServiceRestClient |
| | 20 | | { |
| | 21 | | private string vaultBaseUrl; |
| | 22 | | private string apiVersion; |
| | 23 | | private ClientDiagnostics _clientDiagnostics; |
| | 24 | | private HttpPipeline _pipeline; |
| | 25 | |
|
| | 26 | | /// <summary> Initializes a new instance of ServiceRestClient. </summary> |
| | 27 | | /// <param name="clientDiagnostics"> The handler for diagnostic messaging in the client. </param> |
| | 28 | | /// <param name="pipeline"> The HTTP pipeline for sending and receiving REST requests and responses. </param> |
| | 29 | | /// <param name="vaultBaseUrl"> The vault name, for example https://myvault.vault.azure.net. </param> |
| | 30 | | /// <param name="apiVersion"> Api Version. </param> |
| | 31 | | /// <exception cref="ArgumentNullException"> <paramref name="vaultBaseUrl"/> or <paramref name="apiVersion"/> is |
| 4 | 32 | | public ServiceRestClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string vaultBaseUrl, string |
| | 33 | | { |
| 4 | 34 | | if (vaultBaseUrl == null) |
| | 35 | | { |
| 0 | 36 | | throw new ArgumentNullException(nameof(vaultBaseUrl)); |
| | 37 | | } |
| 4 | 38 | | if (apiVersion == null) |
| | 39 | | { |
| 0 | 40 | | throw new ArgumentNullException(nameof(apiVersion)); |
| | 41 | | } |
| | 42 | |
|
| 4 | 43 | | this.vaultBaseUrl = vaultBaseUrl; |
| 4 | 44 | | this.apiVersion = apiVersion; |
| 4 | 45 | | _clientDiagnostics = clientDiagnostics; |
| 4 | 46 | | _pipeline = pipeline; |
| 4 | 47 | | } |
| | 48 | |
|
| | 49 | | internal HttpMessage CreateGetSecretRequest(string secretName) |
| | 50 | | { |
| 4 | 51 | | var message = _pipeline.CreateMessage(); |
| 4 | 52 | | var request = message.Request; |
| 4 | 53 | | request.Method = RequestMethod.Get; |
| 4 | 54 | | var uri = new RawRequestUriBuilder(); |
| 4 | 55 | | uri.AppendRaw(vaultBaseUrl, false); |
| 4 | 56 | | uri.AppendPath("/secrets/", false); |
| 4 | 57 | | uri.AppendPath(secretName, true); |
| 4 | 58 | | uri.AppendQuery("api-version", apiVersion, true); |
| 4 | 59 | | request.Uri = uri; |
| 4 | 60 | | return message; |
| | 61 | | } |
| | 62 | |
|
| | 63 | | /// <summary> The GET operation is applicable to any secret stored in Azure Key Vault. This operation requires t |
| | 64 | | /// <param name="secretName"> The name of the secret. </param> |
| | 65 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 66 | | /// <exception cref="ArgumentNullException"> <paramref name="secretName"/> is null. </exception> |
| | 67 | | public async Task<Response<SecretBundle>> GetSecretAsync(string secretName, CancellationToken cancellationToken |
| | 68 | | { |
| 2 | 69 | | if (secretName == null) |
| | 70 | | { |
| 0 | 71 | | throw new ArgumentNullException(nameof(secretName)); |
| | 72 | | } |
| | 73 | |
|
| 2 | 74 | | using var message = CreateGetSecretRequest(secretName); |
| 2 | 75 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 2 | 76 | | switch (message.Response.Status) |
| | 77 | | { |
| | 78 | | case 200: |
| | 79 | | { |
| | 80 | | SecretBundle value = default; |
| 2 | 81 | | using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc |
| 2 | 82 | | value = SecretBundle.DeserializeSecretBundle(document.RootElement); |
| 2 | 83 | | return Response.FromValue(value, message.Response); |
| | 84 | | } |
| | 85 | | default: |
| 0 | 86 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 87 | | } |
| 2 | 88 | | } |
| | 89 | |
|
| | 90 | | /// <summary> The GET operation is applicable to any secret stored in Azure Key Vault. This operation requires t |
| | 91 | | /// <param name="secretName"> The name of the secret. </param> |
| | 92 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 93 | | /// <exception cref="ArgumentNullException"> <paramref name="secretName"/> is null. </exception> |
| | 94 | | public Response<SecretBundle> GetSecret(string secretName, CancellationToken cancellationToken = default) |
| | 95 | | { |
| 2 | 96 | | if (secretName == null) |
| | 97 | | { |
| 0 | 98 | | throw new ArgumentNullException(nameof(secretName)); |
| | 99 | | } |
| | 100 | |
|
| 2 | 101 | | using var message = CreateGetSecretRequest(secretName); |
| 2 | 102 | | _pipeline.Send(message, cancellationToken); |
| 2 | 103 | | switch (message.Response.Status) |
| | 104 | | { |
| | 105 | | case 200: |
| | 106 | | { |
| | 107 | | SecretBundle value = default; |
| 2 | 108 | | using var document = JsonDocument.Parse(message.Response.ContentStream); |
| 2 | 109 | | value = SecretBundle.DeserializeSecretBundle(document.RootElement); |
| 2 | 110 | | return Response.FromValue(value, message.Response); |
| | 111 | | } |
| | 112 | | default: |
| 0 | 113 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 114 | | } |
| 2 | 115 | | } |
| | 116 | | } |
| | 117 | | } |