| | 1 | | // <auto-generated> |
| | 2 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 3 | | // Licensed under the MIT License. See License.txt in the project root for |
| | 4 | | // license information. |
| | 5 | | // |
| | 6 | | // Code generated by Microsoft (R) AutoRest Code Generator. |
| | 7 | | // Changes may cause incorrect behavior and will be lost if the code is |
| | 8 | | // regenerated. |
| | 9 | | // </auto-generated> |
| | 10 | |
|
| | 11 | | namespace Microsoft.Azure.Attestation |
| | 12 | | { |
| | 13 | | using Microsoft.Rest; |
| | 14 | | using Microsoft.Rest.Azure; |
| | 15 | | using Models; |
| | 16 | | using Newtonsoft.Json; |
| | 17 | | using System.Collections; |
| | 18 | | using System.Collections.Generic; |
| | 19 | | using System.Linq; |
| | 20 | | using System.Net; |
| | 21 | | using System.Net.Http; |
| | 22 | | using System.Threading; |
| | 23 | | using System.Threading.Tasks; |
| | 24 | |
|
| | 25 | | /// <summary> |
| | 26 | | /// MetadataConfigurationOperations operations. |
| | 27 | | /// </summary> |
| | 28 | | internal partial class MetadataConfigurationOperations : IServiceOperations<AttestationClient>, IMetadataConfigurati |
| | 29 | | { |
| | 30 | | /// <summary> |
| | 31 | | /// Initializes a new instance of the MetadataConfigurationOperations class. |
| | 32 | | /// </summary> |
| | 33 | | /// <param name='client'> |
| | 34 | | /// Reference to the service client. |
| | 35 | | /// </param> |
| | 36 | | /// <exception cref="System.ArgumentNullException"> |
| | 37 | | /// Thrown when a required parameter is null |
| | 38 | | /// </exception> |
| 8 | 39 | | internal MetadataConfigurationOperations(AttestationClient client) |
| | 40 | | { |
| 8 | 41 | | if (client == null) |
| | 42 | | { |
| 0 | 43 | | throw new System.ArgumentNullException("client"); |
| | 44 | | } |
| 8 | 45 | | Client = client; |
| 8 | 46 | | } |
| | 47 | |
|
| | 48 | | /// <summary> |
| | 49 | | /// Gets a reference to the AttestationClient |
| | 50 | | /// </summary> |
| 26 | 51 | | public AttestationClient Client { get; private set; } |
| | 52 | |
|
| | 53 | | /// <summary> |
| | 54 | | /// Retrieves the OpenID Configuration data for the Azure Attestation Service |
| | 55 | | /// </summary> |
| | 56 | | /// <remarks> |
| | 57 | | /// Retrieves metadata about the attestation signing keys in use by the |
| | 58 | | /// attestation service |
| | 59 | | /// </remarks> |
| | 60 | | /// <param name='tenantBaseUrl'> |
| | 61 | | /// The tenant name, for example https://mytenant.attest.azure.net. |
| | 62 | | /// </param> |
| | 63 | | /// <param name='customHeaders'> |
| | 64 | | /// Headers that will be added to request. |
| | 65 | | /// </param> |
| | 66 | | /// <param name='cancellationToken'> |
| | 67 | | /// The cancellation token. |
| | 68 | | /// </param> |
| | 69 | | /// <exception cref="CloudException"> |
| | 70 | | /// Thrown when the operation returned an invalid status code |
| | 71 | | /// </exception> |
| | 72 | | /// <exception cref="SerializationException"> |
| | 73 | | /// Thrown when unable to deserialize the response |
| | 74 | | /// </exception> |
| | 75 | | /// <exception cref="ValidationException"> |
| | 76 | | /// Thrown when a required parameter is null |
| | 77 | | /// </exception> |
| | 78 | | /// <exception cref="System.ArgumentNullException"> |
| | 79 | | /// Thrown when a required parameter is null |
| | 80 | | /// </exception> |
| | 81 | | /// <return> |
| | 82 | | /// A response object containing the response body and response headers. |
| | 83 | | /// </return> |
| | 84 | | public async Task<AzureOperationResponse<object>> GetWithHttpMessagesAsync(string tenantBaseUrl, Dictionary<stri |
| | 85 | | { |
| 2 | 86 | | if (tenantBaseUrl == null) |
| | 87 | | { |
| 0 | 88 | | throw new ValidationException(ValidationRules.CannotBeNull, "tenantBaseUrl"); |
| | 89 | | } |
| | 90 | | // Tracing |
| 2 | 91 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 2 | 92 | | string _invocationId = null; |
| 2 | 93 | | if (_shouldTrace) |
| | 94 | | { |
| 0 | 95 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 96 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 97 | | tracingParameters.Add("tenantBaseUrl", tenantBaseUrl); |
| 0 | 98 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 99 | | ServiceClientTracing.Enter(_invocationId, this, "Get", tracingParameters); |
| | 100 | | } |
| | 101 | | // Construct URL |
| 2 | 102 | | var _baseUrl = Client.BaseUri; |
| 2 | 103 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + ".well-known/openid-configuration"; |
| 2 | 104 | | _url = _url.Replace("{tenantBaseUrl}", tenantBaseUrl); |
| 2 | 105 | | List<string> _queryParameters = new List<string>(); |
| 2 | 106 | | if (_queryParameters.Count > 0) |
| | 107 | | { |
| 0 | 108 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 109 | | } |
| | 110 | | // Create HTTP transport objects |
| 2 | 111 | | var _httpRequest = new HttpRequestMessage(); |
| 2 | 112 | | HttpResponseMessage _httpResponse = null; |
| 2 | 113 | | _httpRequest.Method = new HttpMethod("GET"); |
| 2 | 114 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 115 | | // Set Headers |
| 2 | 116 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 117 | | { |
| 2 | 118 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 119 | | } |
| 2 | 120 | | if (Client.AcceptLanguage != null) |
| | 121 | | { |
| 2 | 122 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 123 | | { |
| 0 | 124 | | _httpRequest.Headers.Remove("accept-language"); |
| | 125 | | } |
| 2 | 126 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 127 | | } |
| | 128 | |
|
| | 129 | |
|
| 2 | 130 | | if (customHeaders != null) |
| | 131 | | { |
| 0 | 132 | | foreach(var _header in customHeaders) |
| | 133 | | { |
| 0 | 134 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 135 | | { |
| 0 | 136 | | _httpRequest.Headers.Remove(_header.Key); |
| | 137 | | } |
| 0 | 138 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 139 | | } |
| | 140 | | } |
| | 141 | |
|
| | 142 | | // Serialize Request |
| 2 | 143 | | string _requestContent = null; |
| | 144 | | // Set Credentials |
| 2 | 145 | | if (Client.Credentials != null) |
| | 146 | | { |
| 2 | 147 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 148 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 149 | | } |
| | 150 | | // Send Request |
| 2 | 151 | | if (_shouldTrace) |
| | 152 | | { |
| 0 | 153 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 154 | | } |
| 2 | 155 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 156 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 2 | 157 | | if (_shouldTrace) |
| | 158 | | { |
| 0 | 159 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 160 | | } |
| 2 | 161 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 2 | 162 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 163 | | string _responseContent = null; |
| 2 | 164 | | if ((int)_statusCode != 200 && (int)_statusCode != 400) |
| | 165 | | { |
| 0 | 166 | | var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode |
| | 167 | | try |
| | 168 | | { |
| 0 | 169 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 170 | | CloudError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC |
| 0 | 171 | | if (_errorBody != null) |
| | 172 | | { |
| 0 | 173 | | ex = new CloudException(_errorBody.Message); |
| 0 | 174 | | ex.Body = _errorBody; |
| | 175 | | } |
| 0 | 176 | | } |
| 0 | 177 | | catch (JsonException) |
| | 178 | | { |
| | 179 | | // Ignore the exception |
| 0 | 180 | | } |
| 0 | 181 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 182 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 183 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 184 | | { |
| 0 | 185 | | ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 186 | | } |
| 0 | 187 | | if (_shouldTrace) |
| | 188 | | { |
| 0 | 189 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 190 | | } |
| 0 | 191 | | _httpRequest.Dispose(); |
| 0 | 192 | | if (_httpResponse != null) |
| | 193 | | { |
| 0 | 194 | | _httpResponse.Dispose(); |
| | 195 | | } |
| 0 | 196 | | throw ex; |
| | 197 | | } |
| | 198 | | // Create Result |
| 2 | 199 | | var _result = new AzureOperationResponse<object>(); |
| 2 | 200 | | _result.Request = _httpRequest; |
| 2 | 201 | | _result.Response = _httpResponse; |
| 2 | 202 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 203 | | { |
| 0 | 204 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 205 | | } |
| | 206 | | // Deserialize Response |
| 2 | 207 | | if ((int)_statusCode == 200) |
| | 208 | | { |
| 2 | 209 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 210 | | try |
| | 211 | | { |
| 2 | 212 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<object>(_responseContent, Client |
| 2 | 213 | | } |
| 0 | 214 | | catch (JsonException ex) |
| | 215 | | { |
| 0 | 216 | | _httpRequest.Dispose(); |
| 0 | 217 | | if (_httpResponse != null) |
| | 218 | | { |
| 0 | 219 | | _httpResponse.Dispose(); |
| | 220 | | } |
| 0 | 221 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 222 | | } |
| | 223 | | } |
| | 224 | | // Deserialize Response |
| 2 | 225 | | if ((int)_statusCode == 400) |
| | 226 | | { |
| 0 | 227 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 228 | | try |
| | 229 | | { |
| 0 | 230 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseContent, Cl |
| 0 | 231 | | } |
| 0 | 232 | | catch (JsonException ex) |
| | 233 | | { |
| 0 | 234 | | _httpRequest.Dispose(); |
| 0 | 235 | | if (_httpResponse != null) |
| | 236 | | { |
| 0 | 237 | | _httpResponse.Dispose(); |
| | 238 | | } |
| 0 | 239 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 240 | | } |
| | 241 | | } |
| 2 | 242 | | if (_shouldTrace) |
| | 243 | | { |
| 0 | 244 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 245 | | } |
| 2 | 246 | | return _result; |
| 2 | 247 | | } |
| | 248 | |
|
| | 249 | | } |
| | 250 | | } |