| | 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.Graph.RBAC |
| | 12 | | { |
| | 13 | | using Microsoft.Rest; |
| | 14 | | using Microsoft.Rest.Azure; |
| | 15 | | using Microsoft.Rest.Azure.OData; |
| | 16 | | using Models; |
| | 17 | | using Newtonsoft.Json; |
| | 18 | | using System.Collections; |
| | 19 | | using System.Collections.Generic; |
| | 20 | | using System.Linq; |
| | 21 | | using System.Net; |
| | 22 | | using System.Net.Http; |
| | 23 | | using System.Threading; |
| | 24 | | using System.Threading.Tasks; |
| | 25 | |
|
| | 26 | | /// <summary> |
| | 27 | | /// DomainsOperations operations. |
| | 28 | | /// </summary> |
| | 29 | | internal partial class DomainsOperations : IServiceOperations<GraphRbacManagementClient>, IDomainsOperations |
| | 30 | | { |
| | 31 | | /// <summary> |
| | 32 | | /// Initializes a new instance of the DomainsOperations class. |
| | 33 | | /// </summary> |
| | 34 | | /// <param name='client'> |
| | 35 | | /// Reference to the service client. |
| | 36 | | /// </param> |
| | 37 | | /// <exception cref="System.ArgumentNullException"> |
| | 38 | | /// Thrown when a required parameter is null |
| | 39 | | /// </exception> |
| 46 | 40 | | internal DomainsOperations(GraphRbacManagementClient client) |
| | 41 | | { |
| 46 | 42 | | if (client == null) |
| | 43 | | { |
| 0 | 44 | | throw new System.ArgumentNullException("client"); |
| | 45 | | } |
| 46 | 46 | | Client = client; |
| 46 | 47 | | } |
| | 48 | |
|
| | 49 | | /// <summary> |
| | 50 | | /// Gets a reference to the GraphRbacManagementClient |
| | 51 | | /// </summary> |
| 0 | 52 | | public GraphRbacManagementClient Client { get; private set; } |
| | 53 | |
|
| | 54 | | /// <summary> |
| | 55 | | /// Gets a list of domains for the current tenant. |
| | 56 | | /// </summary> |
| | 57 | | /// <param name='odataQuery'> |
| | 58 | | /// OData parameters to apply to the operation. |
| | 59 | | /// </param> |
| | 60 | | /// <param name='customHeaders'> |
| | 61 | | /// Headers that will be added to request. |
| | 62 | | /// </param> |
| | 63 | | /// <param name='cancellationToken'> |
| | 64 | | /// The cancellation token. |
| | 65 | | /// </param> |
| | 66 | | /// <exception cref="CloudException"> |
| | 67 | | /// Thrown when the operation returned an invalid status code |
| | 68 | | /// </exception> |
| | 69 | | /// <exception cref="SerializationException"> |
| | 70 | | /// Thrown when unable to deserialize the response |
| | 71 | | /// </exception> |
| | 72 | | /// <exception cref="ValidationException"> |
| | 73 | | /// Thrown when a required parameter is null |
| | 74 | | /// </exception> |
| | 75 | | /// <exception cref="System.ArgumentNullException"> |
| | 76 | | /// Thrown when a required parameter is null |
| | 77 | | /// </exception> |
| | 78 | | /// <return> |
| | 79 | | /// A response object containing the response body and response headers. |
| | 80 | | /// </return> |
| | 81 | | public async Task<AzureOperationResponse<IEnumerable<Domain>>> ListWithHttpMessagesAsync(ODataQuery<User> odataQ |
| | 82 | | { |
| 0 | 83 | | if (Client.ApiVersion == null) |
| | 84 | | { |
| 0 | 85 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 86 | | } |
| 0 | 87 | | if (Client.TenantID == null) |
| | 88 | | { |
| 0 | 89 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.TenantID"); |
| | 90 | | } |
| | 91 | | // Tracing |
| 0 | 92 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 93 | | string _invocationId = null; |
| 0 | 94 | | if (_shouldTrace) |
| | 95 | | { |
| 0 | 96 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 97 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 98 | | tracingParameters.Add("odataQuery", odataQuery); |
| 0 | 99 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 100 | | ServiceClientTracing.Enter(_invocationId, this, "List", tracingParameters); |
| | 101 | | } |
| | 102 | | // Construct URL |
| 0 | 103 | | var _baseUrl = Client.BaseUri.AbsoluteUri; |
| 0 | 104 | | var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "{tenantID}/domain |
| 0 | 105 | | _url = _url.Replace("{tenantID}", System.Uri.EscapeDataString(Client.TenantID)); |
| 0 | 106 | | List<string> _queryParameters = new List<string>(); |
| 0 | 107 | | if (odataQuery != null) |
| | 108 | | { |
| 0 | 109 | | var _odataFilter = odataQuery.ToString(); |
| 0 | 110 | | if (!string.IsNullOrEmpty(_odataFilter)) |
| | 111 | | { |
| 0 | 112 | | _queryParameters.Add(_odataFilter); |
| | 113 | | } |
| | 114 | | } |
| 0 | 115 | | if (Client.ApiVersion != null) |
| | 116 | | { |
| 0 | 117 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 118 | | } |
| 0 | 119 | | if (_queryParameters.Count > 0) |
| | 120 | | { |
| 0 | 121 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 122 | | } |
| | 123 | | // Create HTTP transport objects |
| 0 | 124 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 125 | | HttpResponseMessage _httpResponse = null; |
| 0 | 126 | | _httpRequest.Method = new HttpMethod("GET"); |
| 0 | 127 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 128 | | // Set Headers |
| 0 | 129 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 130 | | { |
| 0 | 131 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 132 | | } |
| 0 | 133 | | if (Client.AcceptLanguage != null) |
| | 134 | | { |
| 0 | 135 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 136 | | { |
| 0 | 137 | | _httpRequest.Headers.Remove("accept-language"); |
| | 138 | | } |
| 0 | 139 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 140 | | } |
| | 141 | |
|
| | 142 | |
|
| 0 | 143 | | if (customHeaders != null) |
| | 144 | | { |
| 0 | 145 | | foreach(var _header in customHeaders) |
| | 146 | | { |
| 0 | 147 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 148 | | { |
| 0 | 149 | | _httpRequest.Headers.Remove(_header.Key); |
| | 150 | | } |
| 0 | 151 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 152 | | } |
| | 153 | | } |
| | 154 | |
|
| | 155 | | // Serialize Request |
| 0 | 156 | | string _requestContent = null; |
| | 157 | | // Set Credentials |
| 0 | 158 | | if (Client.Credentials != null) |
| | 159 | | { |
| 0 | 160 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 161 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 162 | | } |
| | 163 | | // Send Request |
| 0 | 164 | | if (_shouldTrace) |
| | 165 | | { |
| 0 | 166 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 167 | | } |
| 0 | 168 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 169 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 170 | | if (_shouldTrace) |
| | 171 | | { |
| 0 | 172 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 173 | | } |
| 0 | 174 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 175 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 176 | | string _responseContent = null; |
| 0 | 177 | | if ((int)_statusCode != 200) |
| | 178 | | { |
| 0 | 179 | | var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode |
| | 180 | | try |
| | 181 | | { |
| 0 | 182 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 183 | | CloudError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC |
| 0 | 184 | | if (_errorBody != null) |
| | 185 | | { |
| 0 | 186 | | ex = new CloudException(_errorBody.Message); |
| 0 | 187 | | ex.Body = _errorBody; |
| | 188 | | } |
| 0 | 189 | | } |
| 0 | 190 | | catch (JsonException) |
| | 191 | | { |
| | 192 | | // Ignore the exception |
| 0 | 193 | | } |
| 0 | 194 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 195 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 196 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 197 | | { |
| 0 | 198 | | ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 199 | | } |
| 0 | 200 | | if (_shouldTrace) |
| | 201 | | { |
| 0 | 202 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 203 | | } |
| 0 | 204 | | _httpRequest.Dispose(); |
| 0 | 205 | | if (_httpResponse != null) |
| | 206 | | { |
| 0 | 207 | | _httpResponse.Dispose(); |
| | 208 | | } |
| 0 | 209 | | throw ex; |
| | 210 | | } |
| | 211 | | // Create Result |
| 0 | 212 | | var _result = new AzureOperationResponse<IEnumerable<Domain>>(); |
| 0 | 213 | | _result.Request = _httpRequest; |
| 0 | 214 | | _result.Response = _httpResponse; |
| 0 | 215 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 216 | | { |
| 0 | 217 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 218 | | } |
| | 219 | | // Deserialize Response |
| 0 | 220 | | if ((int)_statusCode == 200) |
| | 221 | | { |
| 0 | 222 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 223 | | try |
| | 224 | | { |
| 0 | 225 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<Page1<Domain>>(_responseContent, |
| 0 | 226 | | } |
| 0 | 227 | | catch (JsonException ex) |
| | 228 | | { |
| 0 | 229 | | _httpRequest.Dispose(); |
| 0 | 230 | | if (_httpResponse != null) |
| | 231 | | { |
| 0 | 232 | | _httpResponse.Dispose(); |
| | 233 | | } |
| 0 | 234 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 235 | | } |
| | 236 | | } |
| 0 | 237 | | if (_shouldTrace) |
| | 238 | | { |
| 0 | 239 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 240 | | } |
| 0 | 241 | | return _result; |
| 0 | 242 | | } |
| | 243 | |
|
| | 244 | | /// <summary> |
| | 245 | | /// Gets a specific domain in the current tenant. |
| | 246 | | /// </summary> |
| | 247 | | /// <param name='domainName'> |
| | 248 | | /// name of the domain. |
| | 249 | | /// </param> |
| | 250 | | /// <param name='customHeaders'> |
| | 251 | | /// Headers that will be added to request. |
| | 252 | | /// </param> |
| | 253 | | /// <param name='cancellationToken'> |
| | 254 | | /// The cancellation token. |
| | 255 | | /// </param> |
| | 256 | | /// <exception cref="CloudException"> |
| | 257 | | /// Thrown when the operation returned an invalid status code |
| | 258 | | /// </exception> |
| | 259 | | /// <exception cref="SerializationException"> |
| | 260 | | /// Thrown when unable to deserialize the response |
| | 261 | | /// </exception> |
| | 262 | | /// <exception cref="ValidationException"> |
| | 263 | | /// Thrown when a required parameter is null |
| | 264 | | /// </exception> |
| | 265 | | /// <exception cref="System.ArgumentNullException"> |
| | 266 | | /// Thrown when a required parameter is null |
| | 267 | | /// </exception> |
| | 268 | | /// <return> |
| | 269 | | /// A response object containing the response body and response headers. |
| | 270 | | /// </return> |
| | 271 | | public async Task<AzureOperationResponse<Domain>> GetWithHttpMessagesAsync(string domainName, Dictionary<string, |
| | 272 | | { |
| 0 | 273 | | if (domainName == null) |
| | 274 | | { |
| 0 | 275 | | throw new ValidationException(ValidationRules.CannotBeNull, "domainName"); |
| | 276 | | } |
| 0 | 277 | | if (Client.ApiVersion == null) |
| | 278 | | { |
| 0 | 279 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 280 | | } |
| 0 | 281 | | if (Client.TenantID == null) |
| | 282 | | { |
| 0 | 283 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.TenantID"); |
| | 284 | | } |
| | 285 | | // Tracing |
| 0 | 286 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 287 | | string _invocationId = null; |
| 0 | 288 | | if (_shouldTrace) |
| | 289 | | { |
| 0 | 290 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 291 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 292 | | tracingParameters.Add("domainName", domainName); |
| 0 | 293 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 294 | | ServiceClientTracing.Enter(_invocationId, this, "Get", tracingParameters); |
| | 295 | | } |
| | 296 | | // Construct URL |
| 0 | 297 | | var _baseUrl = Client.BaseUri.AbsoluteUri; |
| 0 | 298 | | var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "{tenantID}/domain |
| 0 | 299 | | _url = _url.Replace("{domainName}", System.Uri.EscapeDataString(domainName)); |
| 0 | 300 | | _url = _url.Replace("{tenantID}", System.Uri.EscapeDataString(Client.TenantID)); |
| 0 | 301 | | List<string> _queryParameters = new List<string>(); |
| 0 | 302 | | if (Client.ApiVersion != null) |
| | 303 | | { |
| 0 | 304 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 305 | | } |
| 0 | 306 | | if (_queryParameters.Count > 0) |
| | 307 | | { |
| 0 | 308 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 309 | | } |
| | 310 | | // Create HTTP transport objects |
| 0 | 311 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 312 | | HttpResponseMessage _httpResponse = null; |
| 0 | 313 | | _httpRequest.Method = new HttpMethod("GET"); |
| 0 | 314 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 315 | | // Set Headers |
| 0 | 316 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 317 | | { |
| 0 | 318 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 319 | | } |
| 0 | 320 | | if (Client.AcceptLanguage != null) |
| | 321 | | { |
| 0 | 322 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 323 | | { |
| 0 | 324 | | _httpRequest.Headers.Remove("accept-language"); |
| | 325 | | } |
| 0 | 326 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 327 | | } |
| | 328 | |
|
| | 329 | |
|
| 0 | 330 | | if (customHeaders != null) |
| | 331 | | { |
| 0 | 332 | | foreach(var _header in customHeaders) |
| | 333 | | { |
| 0 | 334 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 335 | | { |
| 0 | 336 | | _httpRequest.Headers.Remove(_header.Key); |
| | 337 | | } |
| 0 | 338 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 339 | | } |
| | 340 | | } |
| | 341 | |
|
| | 342 | | // Serialize Request |
| 0 | 343 | | string _requestContent = null; |
| | 344 | | // Set Credentials |
| 0 | 345 | | if (Client.Credentials != null) |
| | 346 | | { |
| 0 | 347 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 348 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 349 | | } |
| | 350 | | // Send Request |
| 0 | 351 | | if (_shouldTrace) |
| | 352 | | { |
| 0 | 353 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 354 | | } |
| 0 | 355 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 356 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 357 | | if (_shouldTrace) |
| | 358 | | { |
| 0 | 359 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 360 | | } |
| 0 | 361 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 362 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 363 | | string _responseContent = null; |
| 0 | 364 | | if ((int)_statusCode != 200) |
| | 365 | | { |
| 0 | 366 | | var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode |
| | 367 | | try |
| | 368 | | { |
| 0 | 369 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 370 | | CloudError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC |
| 0 | 371 | | if (_errorBody != null) |
| | 372 | | { |
| 0 | 373 | | ex = new CloudException(_errorBody.Message); |
| 0 | 374 | | ex.Body = _errorBody; |
| | 375 | | } |
| 0 | 376 | | } |
| 0 | 377 | | catch (JsonException) |
| | 378 | | { |
| | 379 | | // Ignore the exception |
| 0 | 380 | | } |
| 0 | 381 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 382 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 383 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 384 | | { |
| 0 | 385 | | ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 386 | | } |
| 0 | 387 | | if (_shouldTrace) |
| | 388 | | { |
| 0 | 389 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 390 | | } |
| 0 | 391 | | _httpRequest.Dispose(); |
| 0 | 392 | | if (_httpResponse != null) |
| | 393 | | { |
| 0 | 394 | | _httpResponse.Dispose(); |
| | 395 | | } |
| 0 | 396 | | throw ex; |
| | 397 | | } |
| | 398 | | // Create Result |
| 0 | 399 | | var _result = new AzureOperationResponse<Domain>(); |
| 0 | 400 | | _result.Request = _httpRequest; |
| 0 | 401 | | _result.Response = _httpResponse; |
| 0 | 402 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 403 | | { |
| 0 | 404 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 405 | | } |
| | 406 | | // Deserialize Response |
| 0 | 407 | | if ((int)_statusCode == 200) |
| | 408 | | { |
| 0 | 409 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 410 | | try |
| | 411 | | { |
| 0 | 412 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<Domain>(_responseContent, Client |
| 0 | 413 | | } |
| 0 | 414 | | catch (JsonException ex) |
| | 415 | | { |
| 0 | 416 | | _httpRequest.Dispose(); |
| 0 | 417 | | if (_httpResponse != null) |
| | 418 | | { |
| 0 | 419 | | _httpResponse.Dispose(); |
| | 420 | | } |
| 0 | 421 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 422 | | } |
| | 423 | | } |
| 0 | 424 | | if (_shouldTrace) |
| | 425 | | { |
| 0 | 426 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 427 | | } |
| 0 | 428 | | return _result; |
| 0 | 429 | | } |
| | 430 | |
|
| | 431 | | } |
| | 432 | | } |