| | | 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 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 | | /// OAuth2PermissionGrantOperations operations. |
| | | 27 | | /// </summary> |
| | | 28 | | internal partial class OAuth2PermissionGrantOperations : IServiceOperations<GraphRbacManagementClient>, IOAuth2Permi |
| | | 29 | | { |
| | | 30 | | /// <summary> |
| | | 31 | | /// Initializes a new instance of the OAuth2PermissionGrantOperations 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> |
| | 46 | 39 | | internal OAuth2PermissionGrantOperations(GraphRbacManagementClient client) |
| | | 40 | | { |
| | 46 | 41 | | if (client == null) |
| | | 42 | | { |
| | 0 | 43 | | throw new System.ArgumentNullException("client"); |
| | | 44 | | } |
| | 46 | 45 | | Client = client; |
| | 46 | 46 | | } |
| | | 47 | | |
| | | 48 | | /// <summary> |
| | | 49 | | /// Gets a reference to the GraphRbacManagementClient |
| | | 50 | | /// </summary> |
| | 0 | 51 | | public GraphRbacManagementClient Client { get; private set; } |
| | | 52 | | |
| | | 53 | | /// <summary> |
| | | 54 | | /// Queries OAuth2 permissions grants for the relevant SP ObjectId of an app. |
| | | 55 | | /// </summary> |
| | | 56 | | /// <param name='filter'> |
| | | 57 | | /// This is the Service Principal ObjectId associated with the app |
| | | 58 | | /// </param> |
| | | 59 | | /// <param name='customHeaders'> |
| | | 60 | | /// Headers that will be added to request. |
| | | 61 | | /// </param> |
| | | 62 | | /// <param name='cancellationToken'> |
| | | 63 | | /// The cancellation token. |
| | | 64 | | /// </param> |
| | | 65 | | /// <exception cref="CloudException"> |
| | | 66 | | /// Thrown when the operation returned an invalid status code |
| | | 67 | | /// </exception> |
| | | 68 | | /// <exception cref="SerializationException"> |
| | | 69 | | /// Thrown when unable to deserialize the response |
| | | 70 | | /// </exception> |
| | | 71 | | /// <exception cref="ValidationException"> |
| | | 72 | | /// Thrown when a required parameter is null |
| | | 73 | | /// </exception> |
| | | 74 | | /// <exception cref="System.ArgumentNullException"> |
| | | 75 | | /// Thrown when a required parameter is null |
| | | 76 | | /// </exception> |
| | | 77 | | /// <return> |
| | | 78 | | /// A response object containing the response body and response headers. |
| | | 79 | | /// </return> |
| | | 80 | | public async Task<AzureOperationResponse<IPage<OAuth2PermissionGrant>>> ListWithHttpMessagesAsync(string filter |
| | | 81 | | { |
| | 0 | 82 | | if (Client.ApiVersion == null) |
| | | 83 | | { |
| | 0 | 84 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | | 85 | | } |
| | 0 | 86 | | if (Client.TenantID == null) |
| | | 87 | | { |
| | 0 | 88 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.TenantID"); |
| | | 89 | | } |
| | | 90 | | // Tracing |
| | 0 | 91 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| | 0 | 92 | | string _invocationId = null; |
| | 0 | 93 | | if (_shouldTrace) |
| | | 94 | | { |
| | 0 | 95 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| | 0 | 96 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| | 0 | 97 | | tracingParameters.Add("filter", filter); |
| | 0 | 98 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| | 0 | 99 | | ServiceClientTracing.Enter(_invocationId, this, "List", tracingParameters); |
| | | 100 | | } |
| | | 101 | | // Construct URL |
| | 0 | 102 | | var _baseUrl = Client.BaseUri.AbsoluteUri; |
| | 0 | 103 | | var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "{tenantID}/oauth2 |
| | 0 | 104 | | _url = _url.Replace("{tenantID}", System.Uri.EscapeDataString(Client.TenantID)); |
| | 0 | 105 | | List<string> _queryParameters = new List<string>(); |
| | 0 | 106 | | if (filter != null) |
| | | 107 | | { |
| | 0 | 108 | | _queryParameters.Add(string.Format("$filter={0}", System.Uri.EscapeDataString(filter))); |
| | | 109 | | } |
| | 0 | 110 | | if (Client.ApiVersion != null) |
| | | 111 | | { |
| | 0 | 112 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | | 113 | | } |
| | 0 | 114 | | if (_queryParameters.Count > 0) |
| | | 115 | | { |
| | 0 | 116 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | | 117 | | } |
| | | 118 | | // Create HTTP transport objects |
| | 0 | 119 | | var _httpRequest = new HttpRequestMessage(); |
| | 0 | 120 | | HttpResponseMessage _httpResponse = null; |
| | 0 | 121 | | _httpRequest.Method = new HttpMethod("GET"); |
| | 0 | 122 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | | 123 | | // Set Headers |
| | 0 | 124 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | | 125 | | { |
| | 0 | 126 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | | 127 | | } |
| | 0 | 128 | | if (Client.AcceptLanguage != null) |
| | | 129 | | { |
| | 0 | 130 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | | 131 | | { |
| | 0 | 132 | | _httpRequest.Headers.Remove("accept-language"); |
| | | 133 | | } |
| | 0 | 134 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | | 135 | | } |
| | | 136 | | |
| | | 137 | | |
| | 0 | 138 | | if (customHeaders != null) |
| | | 139 | | { |
| | 0 | 140 | | foreach(var _header in customHeaders) |
| | | 141 | | { |
| | 0 | 142 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | | 143 | | { |
| | 0 | 144 | | _httpRequest.Headers.Remove(_header.Key); |
| | | 145 | | } |
| | 0 | 146 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | | 147 | | } |
| | | 148 | | } |
| | | 149 | | |
| | | 150 | | // Serialize Request |
| | 0 | 151 | | string _requestContent = null; |
| | | 152 | | // Set Credentials |
| | 0 | 153 | | if (Client.Credentials != null) |
| | | 154 | | { |
| | 0 | 155 | | cancellationToken.ThrowIfCancellationRequested(); |
| | 0 | 156 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | | 157 | | } |
| | | 158 | | // Send Request |
| | 0 | 159 | | if (_shouldTrace) |
| | | 160 | | { |
| | 0 | 161 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | | 162 | | } |
| | 0 | 163 | | cancellationToken.ThrowIfCancellationRequested(); |
| | 0 | 164 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 0 | 165 | | if (_shouldTrace) |
| | | 166 | | { |
| | 0 | 167 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | | 168 | | } |
| | 0 | 169 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| | 0 | 170 | | cancellationToken.ThrowIfCancellationRequested(); |
| | 0 | 171 | | string _responseContent = null; |
| | 0 | 172 | | if ((int)_statusCode != 200) |
| | | 173 | | { |
| | 0 | 174 | | var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode |
| | | 175 | | try |
| | | 176 | | { |
| | 0 | 177 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 0 | 178 | | CloudError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC |
| | 0 | 179 | | if (_errorBody != null) |
| | | 180 | | { |
| | 0 | 181 | | ex = new CloudException(_errorBody.Message); |
| | 0 | 182 | | ex.Body = _errorBody; |
| | | 183 | | } |
| | 0 | 184 | | } |
| | 0 | 185 | | catch (JsonException) |
| | | 186 | | { |
| | | 187 | | // Ignore the exception |
| | 0 | 188 | | } |
| | 0 | 189 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| | 0 | 190 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| | 0 | 191 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | | 192 | | { |
| | 0 | 193 | | ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | | 194 | | } |
| | 0 | 195 | | if (_shouldTrace) |
| | | 196 | | { |
| | 0 | 197 | | ServiceClientTracing.Error(_invocationId, ex); |
| | | 198 | | } |
| | 0 | 199 | | _httpRequest.Dispose(); |
| | 0 | 200 | | if (_httpResponse != null) |
| | | 201 | | { |
| | 0 | 202 | | _httpResponse.Dispose(); |
| | | 203 | | } |
| | 0 | 204 | | throw ex; |
| | | 205 | | } |
| | | 206 | | // Create Result |
| | 0 | 207 | | var _result = new AzureOperationResponse<IPage<OAuth2PermissionGrant>>(); |
| | 0 | 208 | | _result.Request = _httpRequest; |
| | 0 | 209 | | _result.Response = _httpResponse; |
| | 0 | 210 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | | 211 | | { |
| | 0 | 212 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | | 213 | | } |
| | | 214 | | // Deserialize Response |
| | 0 | 215 | | if ((int)_statusCode == 200) |
| | | 216 | | { |
| | 0 | 217 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | | 218 | | try |
| | | 219 | | { |
| | 0 | 220 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<Page<OAuth2PermissionGrant>>(_re |
| | 0 | 221 | | } |
| | 0 | 222 | | catch (JsonException ex) |
| | | 223 | | { |
| | 0 | 224 | | _httpRequest.Dispose(); |
| | 0 | 225 | | if (_httpResponse != null) |
| | | 226 | | { |
| | 0 | 227 | | _httpResponse.Dispose(); |
| | | 228 | | } |
| | 0 | 229 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | | 230 | | } |
| | | 231 | | } |
| | 0 | 232 | | if (_shouldTrace) |
| | | 233 | | { |
| | 0 | 234 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | | 235 | | } |
| | 0 | 236 | | return _result; |
| | 0 | 237 | | } |
| | | 238 | | |
| | | 239 | | /// <summary> |
| | | 240 | | /// Grants OAuth2 permissions for the relevant resource Ids of an app. |
| | | 241 | | /// </summary> |
| | | 242 | | /// <param name='body'> |
| | | 243 | | /// The relevant app Service Principal Object Id and the Service Principal |
| | | 244 | | /// Object Id you want to grant. |
| | | 245 | | /// </param> |
| | | 246 | | /// <param name='customHeaders'> |
| | | 247 | | /// Headers that will be added to request. |
| | | 248 | | /// </param> |
| | | 249 | | /// <param name='cancellationToken'> |
| | | 250 | | /// The cancellation token. |
| | | 251 | | /// </param> |
| | | 252 | | /// <exception cref="CloudException"> |
| | | 253 | | /// Thrown when the operation returned an invalid status code |
| | | 254 | | /// </exception> |
| | | 255 | | /// <exception cref="SerializationException"> |
| | | 256 | | /// Thrown when unable to deserialize the response |
| | | 257 | | /// </exception> |
| | | 258 | | /// <exception cref="ValidationException"> |
| | | 259 | | /// Thrown when a required parameter is null |
| | | 260 | | /// </exception> |
| | | 261 | | /// <exception cref="System.ArgumentNullException"> |
| | | 262 | | /// Thrown when a required parameter is null |
| | | 263 | | /// </exception> |
| | | 264 | | /// <return> |
| | | 265 | | /// A response object containing the response body and response headers. |
| | | 266 | | /// </return> |
| | | 267 | | public async Task<AzureOperationResponse<OAuth2PermissionGrant>> CreateWithHttpMessagesAsync(OAuth2PermissionGra |
| | | 268 | | { |
| | 0 | 269 | | if (Client.ApiVersion == null) |
| | | 270 | | { |
| | 0 | 271 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | | 272 | | } |
| | 0 | 273 | | if (Client.TenantID == null) |
| | | 274 | | { |
| | 0 | 275 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.TenantID"); |
| | | 276 | | } |
| | | 277 | | // Tracing |
| | 0 | 278 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| | 0 | 279 | | string _invocationId = null; |
| | 0 | 280 | | if (_shouldTrace) |
| | | 281 | | { |
| | 0 | 282 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| | 0 | 283 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| | 0 | 284 | | tracingParameters.Add("body", body); |
| | 0 | 285 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| | 0 | 286 | | ServiceClientTracing.Enter(_invocationId, this, "Create", tracingParameters); |
| | | 287 | | } |
| | | 288 | | // Construct URL |
| | 0 | 289 | | var _baseUrl = Client.BaseUri.AbsoluteUri; |
| | 0 | 290 | | var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "{tenantID}/oauth2 |
| | 0 | 291 | | _url = _url.Replace("{tenantID}", System.Uri.EscapeDataString(Client.TenantID)); |
| | 0 | 292 | | List<string> _queryParameters = new List<string>(); |
| | 0 | 293 | | if (Client.ApiVersion != null) |
| | | 294 | | { |
| | 0 | 295 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | | 296 | | } |
| | 0 | 297 | | if (_queryParameters.Count > 0) |
| | | 298 | | { |
| | 0 | 299 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | | 300 | | } |
| | | 301 | | // Create HTTP transport objects |
| | 0 | 302 | | var _httpRequest = new HttpRequestMessage(); |
| | 0 | 303 | | HttpResponseMessage _httpResponse = null; |
| | 0 | 304 | | _httpRequest.Method = new HttpMethod("POST"); |
| | 0 | 305 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | | 306 | | // Set Headers |
| | 0 | 307 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | | 308 | | { |
| | 0 | 309 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | | 310 | | } |
| | 0 | 311 | | if (Client.AcceptLanguage != null) |
| | | 312 | | { |
| | 0 | 313 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | | 314 | | { |
| | 0 | 315 | | _httpRequest.Headers.Remove("accept-language"); |
| | | 316 | | } |
| | 0 | 317 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | | 318 | | } |
| | | 319 | | |
| | | 320 | | |
| | 0 | 321 | | if (customHeaders != null) |
| | | 322 | | { |
| | 0 | 323 | | foreach(var _header in customHeaders) |
| | | 324 | | { |
| | 0 | 325 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | | 326 | | { |
| | 0 | 327 | | _httpRequest.Headers.Remove(_header.Key); |
| | | 328 | | } |
| | 0 | 329 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | | 330 | | } |
| | | 331 | | } |
| | | 332 | | |
| | | 333 | | // Serialize Request |
| | 0 | 334 | | string _requestContent = null; |
| | 0 | 335 | | if(body != null) |
| | | 336 | | { |
| | 0 | 337 | | _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(body, Client.SerializationSettings) |
| | 0 | 338 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| | 0 | 339 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | | 340 | | } |
| | | 341 | | // Set Credentials |
| | 0 | 342 | | if (Client.Credentials != null) |
| | | 343 | | { |
| | 0 | 344 | | cancellationToken.ThrowIfCancellationRequested(); |
| | 0 | 345 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | | 346 | | } |
| | | 347 | | // Send Request |
| | 0 | 348 | | if (_shouldTrace) |
| | | 349 | | { |
| | 0 | 350 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | | 351 | | } |
| | 0 | 352 | | cancellationToken.ThrowIfCancellationRequested(); |
| | 0 | 353 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 0 | 354 | | if (_shouldTrace) |
| | | 355 | | { |
| | 0 | 356 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | | 357 | | } |
| | 0 | 358 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| | 0 | 359 | | cancellationToken.ThrowIfCancellationRequested(); |
| | 0 | 360 | | string _responseContent = null; |
| | 0 | 361 | | if ((int)_statusCode != 201) |
| | | 362 | | { |
| | 0 | 363 | | var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode |
| | | 364 | | try |
| | | 365 | | { |
| | 0 | 366 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 0 | 367 | | CloudError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC |
| | 0 | 368 | | if (_errorBody != null) |
| | | 369 | | { |
| | 0 | 370 | | ex = new CloudException(_errorBody.Message); |
| | 0 | 371 | | ex.Body = _errorBody; |
| | | 372 | | } |
| | 0 | 373 | | } |
| | 0 | 374 | | catch (JsonException) |
| | | 375 | | { |
| | | 376 | | // Ignore the exception |
| | 0 | 377 | | } |
| | 0 | 378 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| | 0 | 379 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| | 0 | 380 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | | 381 | | { |
| | 0 | 382 | | ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | | 383 | | } |
| | 0 | 384 | | if (_shouldTrace) |
| | | 385 | | { |
| | 0 | 386 | | ServiceClientTracing.Error(_invocationId, ex); |
| | | 387 | | } |
| | 0 | 388 | | _httpRequest.Dispose(); |
| | 0 | 389 | | if (_httpResponse != null) |
| | | 390 | | { |
| | 0 | 391 | | _httpResponse.Dispose(); |
| | | 392 | | } |
| | 0 | 393 | | throw ex; |
| | | 394 | | } |
| | | 395 | | // Create Result |
| | 0 | 396 | | var _result = new AzureOperationResponse<OAuth2PermissionGrant>(); |
| | 0 | 397 | | _result.Request = _httpRequest; |
| | 0 | 398 | | _result.Response = _httpResponse; |
| | 0 | 399 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | | 400 | | { |
| | 0 | 401 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | | 402 | | } |
| | | 403 | | // Deserialize Response |
| | 0 | 404 | | if ((int)_statusCode == 201) |
| | | 405 | | { |
| | 0 | 406 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | | 407 | | try |
| | | 408 | | { |
| | 0 | 409 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<OAuth2PermissionGrant>(_response |
| | 0 | 410 | | } |
| | 0 | 411 | | catch (JsonException ex) |
| | | 412 | | { |
| | 0 | 413 | | _httpRequest.Dispose(); |
| | 0 | 414 | | if (_httpResponse != null) |
| | | 415 | | { |
| | 0 | 416 | | _httpResponse.Dispose(); |
| | | 417 | | } |
| | 0 | 418 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | | 419 | | } |
| | | 420 | | } |
| | 0 | 421 | | if (_shouldTrace) |
| | | 422 | | { |
| | 0 | 423 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | | 424 | | } |
| | 0 | 425 | | return _result; |
| | 0 | 426 | | } |
| | | 427 | | |
| | | 428 | | /// <summary> |
| | | 429 | | /// Delete a OAuth2 permission grant for the relevant resource Ids of an app. |
| | | 430 | | /// </summary> |
| | | 431 | | /// <param name='objectId'> |
| | | 432 | | /// The object ID of a permission grant. |
| | | 433 | | /// </param> |
| | | 434 | | /// <param name='customHeaders'> |
| | | 435 | | /// Headers that will be added to request. |
| | | 436 | | /// </param> |
| | | 437 | | /// <param name='cancellationToken'> |
| | | 438 | | /// The cancellation token. |
| | | 439 | | /// </param> |
| | | 440 | | /// <exception cref="GraphErrorException"> |
| | | 441 | | /// Thrown when the operation returned an invalid status code |
| | | 442 | | /// </exception> |
| | | 443 | | /// <exception cref="ValidationException"> |
| | | 444 | | /// Thrown when a required parameter is null |
| | | 445 | | /// </exception> |
| | | 446 | | /// <exception cref="System.ArgumentNullException"> |
| | | 447 | | /// Thrown when a required parameter is null |
| | | 448 | | /// </exception> |
| | | 449 | | /// <return> |
| | | 450 | | /// A response object containing the response body and response headers. |
| | | 451 | | /// </return> |
| | | 452 | | public async Task<AzureOperationResponse> DeleteWithHttpMessagesAsync(string objectId, Dictionary<string, List<s |
| | | 453 | | { |
| | 0 | 454 | | if (objectId == null) |
| | | 455 | | { |
| | 0 | 456 | | throw new ValidationException(ValidationRules.CannotBeNull, "objectId"); |
| | | 457 | | } |
| | 0 | 458 | | if (Client.ApiVersion == null) |
| | | 459 | | { |
| | 0 | 460 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | | 461 | | } |
| | 0 | 462 | | if (Client.TenantID == null) |
| | | 463 | | { |
| | 0 | 464 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.TenantID"); |
| | | 465 | | } |
| | | 466 | | // Tracing |
| | 0 | 467 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| | 0 | 468 | | string _invocationId = null; |
| | 0 | 469 | | if (_shouldTrace) |
| | | 470 | | { |
| | 0 | 471 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| | 0 | 472 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| | 0 | 473 | | tracingParameters.Add("objectId", objectId); |
| | 0 | 474 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| | 0 | 475 | | ServiceClientTracing.Enter(_invocationId, this, "Delete", tracingParameters); |
| | | 476 | | } |
| | | 477 | | // Construct URL |
| | 0 | 478 | | var _baseUrl = Client.BaseUri.AbsoluteUri; |
| | 0 | 479 | | var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "{tenantID}/oauth2 |
| | 0 | 480 | | _url = _url.Replace("{objectId}", System.Uri.EscapeDataString(objectId)); |
| | 0 | 481 | | _url = _url.Replace("{tenantID}", System.Uri.EscapeDataString(Client.TenantID)); |
| | 0 | 482 | | List<string> _queryParameters = new List<string>(); |
| | 0 | 483 | | if (Client.ApiVersion != null) |
| | | 484 | | { |
| | 0 | 485 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | | 486 | | } |
| | 0 | 487 | | if (_queryParameters.Count > 0) |
| | | 488 | | { |
| | 0 | 489 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | | 490 | | } |
| | | 491 | | // Create HTTP transport objects |
| | 0 | 492 | | var _httpRequest = new HttpRequestMessage(); |
| | 0 | 493 | | HttpResponseMessage _httpResponse = null; |
| | 0 | 494 | | _httpRequest.Method = new HttpMethod("DELETE"); |
| | 0 | 495 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | | 496 | | // Set Headers |
| | 0 | 497 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | | 498 | | { |
| | 0 | 499 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | | 500 | | } |
| | 0 | 501 | | if (Client.AcceptLanguage != null) |
| | | 502 | | { |
| | 0 | 503 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | | 504 | | { |
| | 0 | 505 | | _httpRequest.Headers.Remove("accept-language"); |
| | | 506 | | } |
| | 0 | 507 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | | 508 | | } |
| | | 509 | | |
| | | 510 | | |
| | 0 | 511 | | if (customHeaders != null) |
| | | 512 | | { |
| | 0 | 513 | | foreach(var _header in customHeaders) |
| | | 514 | | { |
| | 0 | 515 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | | 516 | | { |
| | 0 | 517 | | _httpRequest.Headers.Remove(_header.Key); |
| | | 518 | | } |
| | 0 | 519 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | | 520 | | } |
| | | 521 | | } |
| | | 522 | | |
| | | 523 | | // Serialize Request |
| | 0 | 524 | | string _requestContent = null; |
| | | 525 | | // Set Credentials |
| | 0 | 526 | | if (Client.Credentials != null) |
| | | 527 | | { |
| | 0 | 528 | | cancellationToken.ThrowIfCancellationRequested(); |
| | 0 | 529 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | | 530 | | } |
| | | 531 | | // Send Request |
| | 0 | 532 | | if (_shouldTrace) |
| | | 533 | | { |
| | 0 | 534 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | | 535 | | } |
| | 0 | 536 | | cancellationToken.ThrowIfCancellationRequested(); |
| | 0 | 537 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 0 | 538 | | if (_shouldTrace) |
| | | 539 | | { |
| | 0 | 540 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | | 541 | | } |
| | 0 | 542 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| | 0 | 543 | | cancellationToken.ThrowIfCancellationRequested(); |
| | 0 | 544 | | string _responseContent = null; |
| | 0 | 545 | | if ((int)_statusCode != 204) |
| | | 546 | | { |
| | 0 | 547 | | var ex = new GraphErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | | 548 | | try |
| | | 549 | | { |
| | 0 | 550 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 0 | 551 | | GraphError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<GraphError>(_responseC |
| | 0 | 552 | | if (_errorBody != null) |
| | | 553 | | { |
| | 0 | 554 | | ex.Body = _errorBody; |
| | | 555 | | } |
| | 0 | 556 | | } |
| | 0 | 557 | | catch (JsonException) |
| | | 558 | | { |
| | | 559 | | // Ignore the exception |
| | 0 | 560 | | } |
| | 0 | 561 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| | 0 | 562 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| | 0 | 563 | | if (_shouldTrace) |
| | | 564 | | { |
| | 0 | 565 | | ServiceClientTracing.Error(_invocationId, ex); |
| | | 566 | | } |
| | 0 | 567 | | _httpRequest.Dispose(); |
| | 0 | 568 | | if (_httpResponse != null) |
| | | 569 | | { |
| | 0 | 570 | | _httpResponse.Dispose(); |
| | | 571 | | } |
| | 0 | 572 | | throw ex; |
| | | 573 | | } |
| | | 574 | | // Create Result |
| | 0 | 575 | | var _result = new AzureOperationResponse(); |
| | 0 | 576 | | _result.Request = _httpRequest; |
| | 0 | 577 | | _result.Response = _httpResponse; |
| | 0 | 578 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | | 579 | | { |
| | 0 | 580 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | | 581 | | } |
| | 0 | 582 | | if (_shouldTrace) |
| | | 583 | | { |
| | 0 | 584 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | | 585 | | } |
| | 0 | 586 | | return _result; |
| | 0 | 587 | | } |
| | | 588 | | |
| | | 589 | | /// <summary> |
| | | 590 | | /// Gets the next page of OAuth2 permission grants |
| | | 591 | | /// </summary> |
| | | 592 | | /// <param name='nextLink'> |
| | | 593 | | /// Next link for the list operation. |
| | | 594 | | /// </param> |
| | | 595 | | /// <param name='customHeaders'> |
| | | 596 | | /// Headers that will be added to request. |
| | | 597 | | /// </param> |
| | | 598 | | /// <param name='cancellationToken'> |
| | | 599 | | /// The cancellation token. |
| | | 600 | | /// </param> |
| | | 601 | | /// <exception cref="GraphErrorException"> |
| | | 602 | | /// Thrown when the operation returned an invalid status code |
| | | 603 | | /// </exception> |
| | | 604 | | /// <exception cref="SerializationException"> |
| | | 605 | | /// Thrown when unable to deserialize the response |
| | | 606 | | /// </exception> |
| | | 607 | | /// <exception cref="ValidationException"> |
| | | 608 | | /// Thrown when a required parameter is null |
| | | 609 | | /// </exception> |
| | | 610 | | /// <exception cref="System.ArgumentNullException"> |
| | | 611 | | /// Thrown when a required parameter is null |
| | | 612 | | /// </exception> |
| | | 613 | | /// <return> |
| | | 614 | | /// A response object containing the response body and response headers. |
| | | 615 | | /// </return> |
| | | 616 | | public async Task<AzureOperationResponse<IPage<OAuth2PermissionGrant>>> ListNextWithHttpMessagesAsync(string nex |
| | | 617 | | { |
| | 0 | 618 | | if (nextLink == null) |
| | | 619 | | { |
| | 0 | 620 | | throw new ValidationException(ValidationRules.CannotBeNull, "nextLink"); |
| | | 621 | | } |
| | 0 | 622 | | if (Client.ApiVersion == null) |
| | | 623 | | { |
| | 0 | 624 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | | 625 | | } |
| | 0 | 626 | | if (Client.TenantID == null) |
| | | 627 | | { |
| | 0 | 628 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.TenantID"); |
| | | 629 | | } |
| | | 630 | | // Tracing |
| | 0 | 631 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| | 0 | 632 | | string _invocationId = null; |
| | 0 | 633 | | if (_shouldTrace) |
| | | 634 | | { |
| | 0 | 635 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| | 0 | 636 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| | 0 | 637 | | tracingParameters.Add("nextLink", nextLink); |
| | 0 | 638 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| | 0 | 639 | | ServiceClientTracing.Enter(_invocationId, this, "ListNext", tracingParameters); |
| | | 640 | | } |
| | | 641 | | // Construct URL |
| | 0 | 642 | | var _baseUrl = Client.BaseUri.AbsoluteUri; |
| | 0 | 643 | | var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "{tenantID}/{nextL |
| | 0 | 644 | | _url = _url.Replace("{nextLink}", nextLink); |
| | 0 | 645 | | _url = _url.Replace("{tenantID}", System.Uri.EscapeDataString(Client.TenantID)); |
| | 0 | 646 | | List<string> _queryParameters = new List<string>(); |
| | 0 | 647 | | if (Client.ApiVersion != null) |
| | | 648 | | { |
| | 0 | 649 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | | 650 | | } |
| | 0 | 651 | | if (_queryParameters.Count > 0) |
| | | 652 | | { |
| | 0 | 653 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | | 654 | | } |
| | | 655 | | // Create HTTP transport objects |
| | 0 | 656 | | var _httpRequest = new HttpRequestMessage(); |
| | 0 | 657 | | HttpResponseMessage _httpResponse = null; |
| | 0 | 658 | | _httpRequest.Method = new HttpMethod("GET"); |
| | 0 | 659 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | | 660 | | // Set Headers |
| | 0 | 661 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | | 662 | | { |
| | 0 | 663 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | | 664 | | } |
| | 0 | 665 | | if (Client.AcceptLanguage != null) |
| | | 666 | | { |
| | 0 | 667 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | | 668 | | { |
| | 0 | 669 | | _httpRequest.Headers.Remove("accept-language"); |
| | | 670 | | } |
| | 0 | 671 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | | 672 | | } |
| | | 673 | | |
| | | 674 | | |
| | 0 | 675 | | if (customHeaders != null) |
| | | 676 | | { |
| | 0 | 677 | | foreach(var _header in customHeaders) |
| | | 678 | | { |
| | 0 | 679 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | | 680 | | { |
| | 0 | 681 | | _httpRequest.Headers.Remove(_header.Key); |
| | | 682 | | } |
| | 0 | 683 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | | 684 | | } |
| | | 685 | | } |
| | | 686 | | |
| | | 687 | | // Serialize Request |
| | 0 | 688 | | string _requestContent = null; |
| | | 689 | | // Set Credentials |
| | 0 | 690 | | if (Client.Credentials != null) |
| | | 691 | | { |
| | 0 | 692 | | cancellationToken.ThrowIfCancellationRequested(); |
| | 0 | 693 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | | 694 | | } |
| | | 695 | | // Send Request |
| | 0 | 696 | | if (_shouldTrace) |
| | | 697 | | { |
| | 0 | 698 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | | 699 | | } |
| | 0 | 700 | | cancellationToken.ThrowIfCancellationRequested(); |
| | 0 | 701 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 0 | 702 | | if (_shouldTrace) |
| | | 703 | | { |
| | 0 | 704 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | | 705 | | } |
| | 0 | 706 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| | 0 | 707 | | cancellationToken.ThrowIfCancellationRequested(); |
| | 0 | 708 | | string _responseContent = null; |
| | 0 | 709 | | if ((int)_statusCode != 200) |
| | | 710 | | { |
| | 0 | 711 | | var ex = new GraphErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | | 712 | | try |
| | | 713 | | { |
| | 0 | 714 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 0 | 715 | | GraphError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<GraphError>(_responseC |
| | 0 | 716 | | if (_errorBody != null) |
| | | 717 | | { |
| | 0 | 718 | | ex.Body = _errorBody; |
| | | 719 | | } |
| | 0 | 720 | | } |
| | 0 | 721 | | catch (JsonException) |
| | | 722 | | { |
| | | 723 | | // Ignore the exception |
| | 0 | 724 | | } |
| | 0 | 725 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| | 0 | 726 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| | 0 | 727 | | if (_shouldTrace) |
| | | 728 | | { |
| | 0 | 729 | | ServiceClientTracing.Error(_invocationId, ex); |
| | | 730 | | } |
| | 0 | 731 | | _httpRequest.Dispose(); |
| | 0 | 732 | | if (_httpResponse != null) |
| | | 733 | | { |
| | 0 | 734 | | _httpResponse.Dispose(); |
| | | 735 | | } |
| | 0 | 736 | | throw ex; |
| | | 737 | | } |
| | | 738 | | // Create Result |
| | 0 | 739 | | var _result = new AzureOperationResponse<IPage<OAuth2PermissionGrant>>(); |
| | 0 | 740 | | _result.Request = _httpRequest; |
| | 0 | 741 | | _result.Response = _httpResponse; |
| | 0 | 742 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | | 743 | | { |
| | 0 | 744 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | | 745 | | } |
| | | 746 | | // Deserialize Response |
| | 0 | 747 | | if ((int)_statusCode == 200) |
| | | 748 | | { |
| | 0 | 749 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | | 750 | | try |
| | | 751 | | { |
| | 0 | 752 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<Page<OAuth2PermissionGrant>>(_re |
| | 0 | 753 | | } |
| | 0 | 754 | | catch (JsonException ex) |
| | | 755 | | { |
| | 0 | 756 | | _httpRequest.Dispose(); |
| | 0 | 757 | | if (_httpResponse != null) |
| | | 758 | | { |
| | 0 | 759 | | _httpResponse.Dispose(); |
| | | 760 | | } |
| | 0 | 761 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | | 762 | | } |
| | | 763 | | } |
| | 0 | 764 | | if (_shouldTrace) |
| | | 765 | | { |
| | 0 | 766 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | | 767 | | } |
| | 0 | 768 | | return _result; |
| | 0 | 769 | | } |
| | | 770 | | |
| | | 771 | | } |
| | | 772 | | } |