< Summary

Class:Microsoft.Azure.Attestation.PolicyOperations
Assembly:Microsoft.Azure.Attestation
File(s):C:\Git\azure-sdk-for-net\sdk\attestation\Microsoft.Azure.Attestation\src\Generated\PolicyOperations.cs
Covered lines:216
Uncovered lines:230
Coverable lines:446
Total lines:992
Line coverage:48.4% (216 of 446)
Covered branches:136
Total branches:274
Branch coverage:49.6% (136 of 274)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-80%50%
get_Client()-100%100%
PrepareToSetWithHttpMessagesAsync()-48.25%50%
GetWithHttpMessagesAsync()-46.73%48.48%
SetWithHttpMessagesAsync()-48.57%50%
ResetWithHttpMessagesAsync()-48.25%50%

File(s)

C:\Git\azure-sdk-for-net\sdk\attestation\Microsoft.Azure.Attestation\src\Generated\PolicyOperations.cs

#LineLine coverage
 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
 11namespace 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    /// PolicyOperations operations.
 27    /// </summary>
 28    internal partial class PolicyOperations : IServiceOperations<AttestationClient>, IPolicyOperations
 29    {
 30        /// <summary>
 31        /// Initializes a new instance of the PolicyOperations 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>
 839        internal PolicyOperations(AttestationClient client)
 40        {
 841            if (client == null)
 42            {
 043                throw new System.ArgumentNullException("client");
 44            }
 845            Client = client;
 846        }
 47
 48        /// <summary>
 49        /// Gets a reference to the AttestationClient
 50        /// </summary>
 10051        public AttestationClient Client { get; private set; }
 52
 53        /// <summary>
 54        /// Accepts a new policy document and returns a JWT which expresses  used in
 55        /// preparation to set attestation policy.
 56        /// </summary>
 57        /// <param name='tenantBaseUrl'>
 58        /// The tenant name, for example https://mytenant.attest.azure.net.
 59        /// </param>
 60        /// <param name='tee'>
 61        /// Specifies the trusted execution environment to be used to validate the
 62        /// evidence. Possible values include: 'SgxEnclave', 'OpenEnclave',
 63        /// 'CyResComponent', 'VSMEnclave'
 64        /// </param>
 65        /// <param name='policyJws'>
 66        /// JSON Web Signature (See RFC7515) expressing the new policy
 67        /// </param>
 68        /// <param name='customHeaders'>
 69        /// Headers that will be added to request.
 70        /// </param>
 71        /// <param name='cancellationToken'>
 72        /// The cancellation token.
 73        /// </param>
 74        /// <exception cref="CloudException">
 75        /// Thrown when the operation returned an invalid status code
 76        /// </exception>
 77        /// <exception cref="SerializationException">
 78        /// Thrown when unable to deserialize the response
 79        /// </exception>
 80        /// <exception cref="ValidationException">
 81        /// Thrown when a required parameter is null
 82        /// </exception>
 83        /// <exception cref="System.ArgumentNullException">
 84        /// Thrown when a required parameter is null
 85        /// </exception>
 86        /// <return>
 87        /// A response object containing the response body and response headers.
 88        /// </return>
 89        public async Task<AzureOperationResponse<object>> PrepareToSetWithHttpMessagesAsync(string tenantBaseUrl, string
 90        {
 291            if (tenantBaseUrl == null)
 92            {
 093                throw new ValidationException(ValidationRules.CannotBeNull, "tenantBaseUrl");
 94            }
 295            if (tee == null)
 96            {
 097                throw new ValidationException(ValidationRules.CannotBeNull, "tee");
 98            }
 299            if (policyJws == null)
 100            {
 0101                throw new ValidationException(ValidationRules.CannotBeNull, "policyJws");
 102            }
 103            // Tracing
 2104            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 2105            string _invocationId = null;
 2106            if (_shouldTrace)
 107            {
 0108                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0109                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0110                tracingParameters.Add("tenantBaseUrl", tenantBaseUrl);
 0111                tracingParameters.Add("tee", tee);
 0112                tracingParameters.Add("policyJws", policyJws);
 0113                tracingParameters.Add("cancellationToken", cancellationToken);
 0114                ServiceClientTracing.Enter(_invocationId, this, "PrepareToSet", tracingParameters);
 115            }
 116            // Construct URL
 2117            var _baseUrl = Client.BaseUri;
 2118            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "operations/policy/updatepolicy";
 2119            _url = _url.Replace("{tenantBaseUrl}", tenantBaseUrl);
 2120            List<string> _queryParameters = new List<string>();
 2121            if (Client.ApiVersion != null)
 122            {
 2123                _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion)));
 124            }
 2125            if (tee != null)
 126            {
 2127                _queryParameters.Add(string.Format("tee={0}", System.Uri.EscapeDataString(tee)));
 128            }
 2129            if (_queryParameters.Count > 0)
 130            {
 2131                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 132            }
 133            // Create HTTP transport objects
 2134            var _httpRequest = new HttpRequestMessage();
 2135            HttpResponseMessage _httpResponse = null;
 2136            _httpRequest.Method = new HttpMethod("POST");
 2137            _httpRequest.RequestUri = new System.Uri(_url);
 138            // Set Headers
 2139            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 140            {
 2141                _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString())
 142            }
 2143            if (Client.AcceptLanguage != null)
 144            {
 2145                if (_httpRequest.Headers.Contains("accept-language"))
 146                {
 0147                    _httpRequest.Headers.Remove("accept-language");
 148                }
 2149                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 150            }
 151
 152
 2153            if (customHeaders != null)
 154            {
 0155                foreach(var _header in customHeaders)
 156                {
 0157                    if (_httpRequest.Headers.Contains(_header.Key))
 158                    {
 0159                        _httpRequest.Headers.Remove(_header.Key);
 160                    }
 0161                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 162                }
 163            }
 164
 165            // Serialize Request
 2166            string _requestContent = null;
 2167            if(policyJws != null)
 168            {
 2169                _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(policyJws, Client.SerializationSett
 2170                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 2171                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("text/plain
 172            }
 173            // Set Credentials
 2174            if (Client.Credentials != null)
 175            {
 2176                cancellationToken.ThrowIfCancellationRequested();
 2177                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 178            }
 179            // Send Request
 2180            if (_shouldTrace)
 181            {
 0182                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 183            }
 2184            cancellationToken.ThrowIfCancellationRequested();
 2185            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 2186            if (_shouldTrace)
 187            {
 0188                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 189            }
 2190            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 2191            cancellationToken.ThrowIfCancellationRequested();
 2192            string _responseContent = null;
 2193            if ((int)_statusCode != 200 && (int)_statusCode != 400 && (int)_statusCode != 401)
 194            {
 0195                var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode
 196                try
 197                {
 0198                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0199                    CloudError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC
 0200                    if (_errorBody != null)
 201                    {
 0202                        ex = new CloudException(_errorBody.Message);
 0203                        ex.Body = _errorBody;
 204                    }
 0205                }
 0206                catch (JsonException)
 207                {
 208                    // Ignore the exception
 0209                }
 0210                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0211                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0212                if (_httpResponse.Headers.Contains("x-ms-request-id"))
 213                {
 0214                    ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 215                }
 0216                if (_shouldTrace)
 217                {
 0218                    ServiceClientTracing.Error(_invocationId, ex);
 219                }
 0220                _httpRequest.Dispose();
 0221                if (_httpResponse != null)
 222                {
 0223                    _httpResponse.Dispose();
 224                }
 0225                throw ex;
 226            }
 227            // Create Result
 2228            var _result = new AzureOperationResponse<object>();
 2229            _result.Request = _httpRequest;
 2230            _result.Response = _httpResponse;
 2231            if (_httpResponse.Headers.Contains("x-ms-request-id"))
 232            {
 0233                _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 234            }
 235            // Deserialize Response
 2236            if ((int)_statusCode == 200)
 237            {
 2238                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 239                try
 240                {
 2241                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<string>(_responseContent, Client
 2242                }
 0243                catch (JsonException ex)
 244                {
 0245                    _httpRequest.Dispose();
 0246                    if (_httpResponse != null)
 247                    {
 0248                        _httpResponse.Dispose();
 249                    }
 0250                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 251                }
 252            }
 253            // Deserialize Response
 2254            if ((int)_statusCode == 400)
 255            {
 0256                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 257                try
 258                {
 0259                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseContent, Cl
 0260                }
 0261                catch (JsonException ex)
 262                {
 0263                    _httpRequest.Dispose();
 0264                    if (_httpResponse != null)
 265                    {
 0266                        _httpResponse.Dispose();
 267                    }
 0268                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 269                }
 270            }
 271            // Deserialize Response
 2272            if ((int)_statusCode == 401)
 273            {
 0274                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 275                try
 276                {
 0277                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<string>(_responseContent, Client
 0278                }
 0279                catch (JsonException ex)
 280                {
 0281                    _httpRequest.Dispose();
 0282                    if (_httpResponse != null)
 283                    {
 0284                        _httpResponse.Dispose();
 285                    }
 0286                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 287                }
 288            }
 2289            if (_shouldTrace)
 290            {
 0291                ServiceClientTracing.Exit(_invocationId, _result);
 292            }
 2293            return _result;
 2294        }
 295
 296        /// <summary>
 297        /// Retrieves the current policy for a given kind of TEE.
 298        /// </summary>
 299        /// <param name='tenantBaseUrl'>
 300        /// The tenant name, for example https://mytenant.attest.azure.net.
 301        /// </param>
 302        /// <param name='tee'>
 303        /// Specifies the trusted execution environment to be used to validate the
 304        /// evidence. Possible values include: 'SgxEnclave', 'OpenEnclave',
 305        /// 'CyResComponent', 'VSMEnclave'
 306        /// </param>
 307        /// <param name='customHeaders'>
 308        /// Headers that will be added to request.
 309        /// </param>
 310        /// <param name='cancellationToken'>
 311        /// The cancellation token.
 312        /// </param>
 313        /// <exception cref="CloudException">
 314        /// Thrown when the operation returned an invalid status code
 315        /// </exception>
 316        /// <exception cref="SerializationException">
 317        /// Thrown when unable to deserialize the response
 318        /// </exception>
 319        /// <exception cref="ValidationException">
 320        /// Thrown when a required parameter is null
 321        /// </exception>
 322        /// <exception cref="System.ArgumentNullException">
 323        /// Thrown when a required parameter is null
 324        /// </exception>
 325        /// <return>
 326        /// A response object containing the response body and response headers.
 327        /// </return>
 328        public async Task<AzureOperationResponse<object>> GetWithHttpMessagesAsync(string tenantBaseUrl, string tee, Dic
 329        {
 2330            if (tenantBaseUrl == null)
 331            {
 0332                throw new ValidationException(ValidationRules.CannotBeNull, "tenantBaseUrl");
 333            }
 2334            if (tee == null)
 335            {
 0336                throw new ValidationException(ValidationRules.CannotBeNull, "tee");
 337            }
 338            // Tracing
 2339            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 2340            string _invocationId = null;
 2341            if (_shouldTrace)
 342            {
 0343                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0344                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0345                tracingParameters.Add("tenantBaseUrl", tenantBaseUrl);
 0346                tracingParameters.Add("tee", tee);
 0347                tracingParameters.Add("cancellationToken", cancellationToken);
 0348                ServiceClientTracing.Enter(_invocationId, this, "Get", tracingParameters);
 349            }
 350            // Construct URL
 2351            var _baseUrl = Client.BaseUri;
 2352            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "operations/policy/current";
 2353            _url = _url.Replace("{tenantBaseUrl}", tenantBaseUrl);
 2354            List<string> _queryParameters = new List<string>();
 2355            if (Client.ApiVersion != null)
 356            {
 2357                _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion)));
 358            }
 2359            if (tee != null)
 360            {
 2361                _queryParameters.Add(string.Format("tee={0}", System.Uri.EscapeDataString(tee)));
 362            }
 2363            if (_queryParameters.Count > 0)
 364            {
 2365                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 366            }
 367            // Create HTTP transport objects
 2368            var _httpRequest = new HttpRequestMessage();
 2369            HttpResponseMessage _httpResponse = null;
 2370            _httpRequest.Method = new HttpMethod("GET");
 2371            _httpRequest.RequestUri = new System.Uri(_url);
 372            // Set Headers
 2373            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 374            {
 2375                _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString())
 376            }
 2377            if (Client.AcceptLanguage != null)
 378            {
 2379                if (_httpRequest.Headers.Contains("accept-language"))
 380                {
 0381                    _httpRequest.Headers.Remove("accept-language");
 382                }
 2383                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 384            }
 385
 386
 2387            if (customHeaders != null)
 388            {
 0389                foreach(var _header in customHeaders)
 390                {
 0391                    if (_httpRequest.Headers.Contains(_header.Key))
 392                    {
 0393                        _httpRequest.Headers.Remove(_header.Key);
 394                    }
 0395                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 396                }
 397            }
 398
 399            // Serialize Request
 2400            string _requestContent = null;
 401            // Set Credentials
 2402            if (Client.Credentials != null)
 403            {
 2404                cancellationToken.ThrowIfCancellationRequested();
 2405                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 406            }
 407            // Send Request
 2408            if (_shouldTrace)
 409            {
 0410                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 411            }
 2412            cancellationToken.ThrowIfCancellationRequested();
 2413            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 2414            if (_shouldTrace)
 415            {
 0416                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 417            }
 2418            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 2419            cancellationToken.ThrowIfCancellationRequested();
 2420            string _responseContent = null;
 2421            if ((int)_statusCode != 200 && (int)_statusCode != 400 && (int)_statusCode != 401)
 422            {
 0423                var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode
 424                try
 425                {
 0426                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0427                    CloudError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC
 0428                    if (_errorBody != null)
 429                    {
 0430                        ex = new CloudException(_errorBody.Message);
 0431                        ex.Body = _errorBody;
 432                    }
 0433                }
 0434                catch (JsonException)
 435                {
 436                    // Ignore the exception
 0437                }
 0438                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0439                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0440                if (_httpResponse.Headers.Contains("x-ms-request-id"))
 441                {
 0442                    ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 443                }
 0444                if (_shouldTrace)
 445                {
 0446                    ServiceClientTracing.Error(_invocationId, ex);
 447                }
 0448                _httpRequest.Dispose();
 0449                if (_httpResponse != null)
 450                {
 0451                    _httpResponse.Dispose();
 452                }
 0453                throw ex;
 454            }
 455            // Create Result
 2456            var _result = new AzureOperationResponse<object>();
 2457            _result.Request = _httpRequest;
 2458            _result.Response = _httpResponse;
 2459            if (_httpResponse.Headers.Contains("x-ms-request-id"))
 460            {
 0461                _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 462            }
 463            // Deserialize Response
 2464            if ((int)_statusCode == 200)
 465            {
 2466                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 467                try
 468                {
 2469                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<AttestationPolicy>(_responseCont
 2470                }
 0471                catch (JsonException ex)
 472                {
 0473                    _httpRequest.Dispose();
 0474                    if (_httpResponse != null)
 475                    {
 0476                        _httpResponse.Dispose();
 477                    }
 0478                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 479                }
 480            }
 481            // Deserialize Response
 2482            if ((int)_statusCode == 400)
 483            {
 0484                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 485                try
 486                {
 0487                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseContent, Cl
 0488                }
 0489                catch (JsonException ex)
 490                {
 0491                    _httpRequest.Dispose();
 0492                    if (_httpResponse != null)
 493                    {
 0494                        _httpResponse.Dispose();
 495                    }
 0496                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 497                }
 498            }
 499            // Deserialize Response
 2500            if ((int)_statusCode == 401)
 501            {
 0502                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 503                try
 504                {
 0505                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<string>(_responseContent, Client
 0506                }
 0507                catch (JsonException ex)
 508                {
 0509                    _httpRequest.Dispose();
 0510                    if (_httpResponse != null)
 511                    {
 0512                        _httpResponse.Dispose();
 513                    }
 0514                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 515                }
 516            }
 2517            if (_shouldTrace)
 518            {
 0519                ServiceClientTracing.Exit(_invocationId, _result);
 520            }
 2521            return _result;
 2522        }
 523
 524        /// <summary>
 525        /// Sets the policy for a given kind of TEE.
 526        /// </summary>
 527        /// <param name='tenantBaseUrl'>
 528        /// The tenant name, for example https://mytenant.attest.azure.net.
 529        /// </param>
 530        /// <param name='tee'>
 531        /// Specifies the trusted execution environment to be used to validate the
 532        /// evidence. Possible values include: 'SgxEnclave', 'OpenEnclave',
 533        /// 'CyResComponent', 'VSMEnclave'
 534        /// </param>
 535        /// <param name='newAttestationPolicy'>
 536        /// JWT Expressing the new policy
 537        /// </param>
 538        /// <param name='customHeaders'>
 539        /// Headers that will be added to request.
 540        /// </param>
 541        /// <param name='cancellationToken'>
 542        /// The cancellation token.
 543        /// </param>
 544        /// <exception cref="CloudException">
 545        /// Thrown when the operation returned an invalid status code
 546        /// </exception>
 547        /// <exception cref="SerializationException">
 548        /// Thrown when unable to deserialize the response
 549        /// </exception>
 550        /// <exception cref="ValidationException">
 551        /// Thrown when a required parameter is null
 552        /// </exception>
 553        /// <exception cref="System.ArgumentNullException">
 554        /// Thrown when a required parameter is null
 555        /// </exception>
 556        /// <return>
 557        /// A response object containing the response body and response headers.
 558        /// </return>
 559        public async Task<AzureOperationResponse<object>> SetWithHttpMessagesAsync(string tenantBaseUrl, string tee, str
 560        {
 2561            if (tenantBaseUrl == null)
 562            {
 0563                throw new ValidationException(ValidationRules.CannotBeNull, "tenantBaseUrl");
 564            }
 2565            if (tee == null)
 566            {
 0567                throw new ValidationException(ValidationRules.CannotBeNull, "tee");
 568            }
 2569            if (newAttestationPolicy == null)
 570            {
 0571                throw new ValidationException(ValidationRules.CannotBeNull, "newAttestationPolicy");
 572            }
 573            // Tracing
 2574            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 2575            string _invocationId = null;
 2576            if (_shouldTrace)
 577            {
 0578                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0579                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0580                tracingParameters.Add("tenantBaseUrl", tenantBaseUrl);
 0581                tracingParameters.Add("tee", tee);
 0582                tracingParameters.Add("newAttestationPolicy", newAttestationPolicy);
 0583                tracingParameters.Add("cancellationToken", cancellationToken);
 0584                ServiceClientTracing.Enter(_invocationId, this, "Set", tracingParameters);
 585            }
 586            // Construct URL
 2587            var _baseUrl = Client.BaseUri;
 2588            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "operations/policy/current";
 2589            _url = _url.Replace("{tenantBaseUrl}", tenantBaseUrl);
 2590            List<string> _queryParameters = new List<string>();
 2591            if (Client.ApiVersion != null)
 592            {
 2593                _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion)));
 594            }
 2595            if (tee != null)
 596            {
 2597                _queryParameters.Add(string.Format("tee={0}", System.Uri.EscapeDataString(tee)));
 598            }
 2599            if (_queryParameters.Count > 0)
 600            {
 2601                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 602            }
 603            // Create HTTP transport objects
 2604            var _httpRequest = new HttpRequestMessage();
 2605            HttpResponseMessage _httpResponse = null;
 2606            _httpRequest.Method = new HttpMethod("PUT");
 2607            _httpRequest.RequestUri = new System.Uri(_url);
 608            // Set Headers
 2609            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 610            {
 2611                _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString())
 612            }
 2613            if (Client.AcceptLanguage != null)
 614            {
 2615                if (_httpRequest.Headers.Contains("accept-language"))
 616                {
 0617                    _httpRequest.Headers.Remove("accept-language");
 618                }
 2619                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 620            }
 621
 622
 2623            if (customHeaders != null)
 624            {
 0625                foreach(var _header in customHeaders)
 626                {
 0627                    if (_httpRequest.Headers.Contains(_header.Key))
 628                    {
 0629                        _httpRequest.Headers.Remove(_header.Key);
 630                    }
 0631                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 632                }
 633            }
 634
 635            // Serialize Request
 2636            string _requestContent = null;
 2637            if(newAttestationPolicy != null)
 638            {
 2639                _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(newAttestationPolicy, Client.Serial
 2640                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 2641                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("text/plain
 642            }
 643            // Set Credentials
 2644            if (Client.Credentials != null)
 645            {
 2646                cancellationToken.ThrowIfCancellationRequested();
 2647                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 648            }
 649            // Send Request
 2650            if (_shouldTrace)
 651            {
 0652                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 653            }
 2654            cancellationToken.ThrowIfCancellationRequested();
 2655            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 2656            if (_shouldTrace)
 657            {
 0658                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 659            }
 2660            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 2661            cancellationToken.ThrowIfCancellationRequested();
 2662            string _responseContent = null;
 2663            if ((int)_statusCode != 200 && (int)_statusCode != 400 && (int)_statusCode != 401)
 664            {
 0665                var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode
 666                try
 667                {
 0668                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0669                    CloudError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC
 0670                    if (_errorBody != null)
 671                    {
 0672                        ex = new CloudException(_errorBody.Message);
 0673                        ex.Body = _errorBody;
 674                    }
 0675                }
 0676                catch (JsonException)
 677                {
 678                    // Ignore the exception
 0679                }
 0680                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0681                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0682                if (_httpResponse.Headers.Contains("x-ms-request-id"))
 683                {
 0684                    ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 685                }
 0686                if (_shouldTrace)
 687                {
 0688                    ServiceClientTracing.Error(_invocationId, ex);
 689                }
 0690                _httpRequest.Dispose();
 0691                if (_httpResponse != null)
 692                {
 0693                    _httpResponse.Dispose();
 694                }
 0695                throw ex;
 696            }
 697            // Create Result
 2698            var _result = new AzureOperationResponse<object>();
 2699            _result.Request = _httpRequest;
 2700            _result.Response = _httpResponse;
 2701            if (_httpResponse.Headers.Contains("x-ms-request-id"))
 702            {
 0703                _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 704            }
 705            // Deserialize Response
 2706            if ((int)_statusCode == 400)
 707            {
 0708                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 709                try
 710                {
 0711                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseContent, Cl
 0712                }
 0713                catch (JsonException ex)
 714                {
 0715                    _httpRequest.Dispose();
 0716                    if (_httpResponse != null)
 717                    {
 0718                        _httpResponse.Dispose();
 719                    }
 0720                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 721                }
 722            }
 723            // Deserialize Response
 2724            if ((int)_statusCode == 401)
 725            {
 0726                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 727                try
 728                {
 0729                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<string>(_responseContent, Client
 0730                }
 0731                catch (JsonException ex)
 732                {
 0733                    _httpRequest.Dispose();
 0734                    if (_httpResponse != null)
 735                    {
 0736                        _httpResponse.Dispose();
 737                    }
 0738                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 739                }
 740            }
 2741            if (_shouldTrace)
 742            {
 0743                ServiceClientTracing.Exit(_invocationId, _result);
 744            }
 2745            return _result;
 2746        }
 747
 748        /// <summary>
 749        /// Resets the attestation policy for the specified tenant and reverts to the
 750        /// default policy.
 751        /// </summary>
 752        /// <param name='tenantBaseUrl'>
 753        /// The tenant name, for example https://mytenant.attest.azure.net.
 754        /// </param>
 755        /// <param name='tee'>
 756        /// Specifies the trusted execution environment to be used to validate the
 757        /// evidence. Possible values include: 'SgxEnclave', 'OpenEnclave',
 758        /// 'CyResComponent', 'VSMEnclave'
 759        /// </param>
 760        /// <param name='policyJws'>
 761        /// JSON Web Signature with an empty policy document
 762        /// </param>
 763        /// <param name='customHeaders'>
 764        /// Headers that will be added to request.
 765        /// </param>
 766        /// <param name='cancellationToken'>
 767        /// The cancellation token.
 768        /// </param>
 769        /// <exception cref="CloudException">
 770        /// Thrown when the operation returned an invalid status code
 771        /// </exception>
 772        /// <exception cref="SerializationException">
 773        /// Thrown when unable to deserialize the response
 774        /// </exception>
 775        /// <exception cref="ValidationException">
 776        /// Thrown when a required parameter is null
 777        /// </exception>
 778        /// <exception cref="System.ArgumentNullException">
 779        /// Thrown when a required parameter is null
 780        /// </exception>
 781        /// <return>
 782        /// A response object containing the response body and response headers.
 783        /// </return>
 784        public async Task<AzureOperationResponse<object>> ResetWithHttpMessagesAsync(string tenantBaseUrl, string tee, s
 785        {
 2786            if (tenantBaseUrl == null)
 787            {
 0788                throw new ValidationException(ValidationRules.CannotBeNull, "tenantBaseUrl");
 789            }
 2790            if (tee == null)
 791            {
 0792                throw new ValidationException(ValidationRules.CannotBeNull, "tee");
 793            }
 2794            if (policyJws == null)
 795            {
 0796                throw new ValidationException(ValidationRules.CannotBeNull, "policyJws");
 797            }
 798            // Tracing
 2799            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 2800            string _invocationId = null;
 2801            if (_shouldTrace)
 802            {
 0803                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0804                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0805                tracingParameters.Add("tenantBaseUrl", tenantBaseUrl);
 0806                tracingParameters.Add("tee", tee);
 0807                tracingParameters.Add("policyJws", policyJws);
 0808                tracingParameters.Add("cancellationToken", cancellationToken);
 0809                ServiceClientTracing.Enter(_invocationId, this, "Reset", tracingParameters);
 810            }
 811            // Construct URL
 2812            var _baseUrl = Client.BaseUri;
 2813            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "operations/policy/current";
 2814            _url = _url.Replace("{tenantBaseUrl}", tenantBaseUrl);
 2815            List<string> _queryParameters = new List<string>();
 2816            if (Client.ApiVersion != null)
 817            {
 2818                _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion)));
 819            }
 2820            if (tee != null)
 821            {
 2822                _queryParameters.Add(string.Format("tee={0}", System.Uri.EscapeDataString(tee)));
 823            }
 2824            if (_queryParameters.Count > 0)
 825            {
 2826                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 827            }
 828            // Create HTTP transport objects
 2829            var _httpRequest = new HttpRequestMessage();
 2830            HttpResponseMessage _httpResponse = null;
 2831            _httpRequest.Method = new HttpMethod("POST");
 2832            _httpRequest.RequestUri = new System.Uri(_url);
 833            // Set Headers
 2834            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 835            {
 2836                _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString())
 837            }
 2838            if (Client.AcceptLanguage != null)
 839            {
 2840                if (_httpRequest.Headers.Contains("accept-language"))
 841                {
 0842                    _httpRequest.Headers.Remove("accept-language");
 843                }
 2844                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 845            }
 846
 847
 2848            if (customHeaders != null)
 849            {
 0850                foreach(var _header in customHeaders)
 851                {
 0852                    if (_httpRequest.Headers.Contains(_header.Key))
 853                    {
 0854                        _httpRequest.Headers.Remove(_header.Key);
 855                    }
 0856                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 857                }
 858            }
 859
 860            // Serialize Request
 2861            string _requestContent = null;
 2862            if(policyJws != null)
 863            {
 2864                _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(policyJws, Client.SerializationSett
 2865                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 2866                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("text/plain
 867            }
 868            // Set Credentials
 2869            if (Client.Credentials != null)
 870            {
 2871                cancellationToken.ThrowIfCancellationRequested();
 2872                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 873            }
 874            // Send Request
 2875            if (_shouldTrace)
 876            {
 0877                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 878            }
 2879            cancellationToken.ThrowIfCancellationRequested();
 2880            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 2881            if (_shouldTrace)
 882            {
 0883                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 884            }
 2885            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 2886            cancellationToken.ThrowIfCancellationRequested();
 2887            string _responseContent = null;
 2888            if ((int)_statusCode != 200 && (int)_statusCode != 400 && (int)_statusCode != 401)
 889            {
 0890                var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode
 891                try
 892                {
 0893                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0894                    CloudError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC
 0895                    if (_errorBody != null)
 896                    {
 0897                        ex = new CloudException(_errorBody.Message);
 0898                        ex.Body = _errorBody;
 899                    }
 0900                }
 0901                catch (JsonException)
 902                {
 903                    // Ignore the exception
 0904                }
 0905                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0906                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0907                if (_httpResponse.Headers.Contains("x-ms-request-id"))
 908                {
 0909                    ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 910                }
 0911                if (_shouldTrace)
 912                {
 0913                    ServiceClientTracing.Error(_invocationId, ex);
 914                }
 0915                _httpRequest.Dispose();
 0916                if (_httpResponse != null)
 917                {
 0918                    _httpResponse.Dispose();
 919                }
 0920                throw ex;
 921            }
 922            // Create Result
 2923            var _result = new AzureOperationResponse<object>();
 2924            _result.Request = _httpRequest;
 2925            _result.Response = _httpResponse;
 2926            if (_httpResponse.Headers.Contains("x-ms-request-id"))
 927            {
 0928                _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 929            }
 930            // Deserialize Response
 2931            if ((int)_statusCode == 200)
 932            {
 2933                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 934                try
 935                {
 2936                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<string>(_responseContent, Client
 2937                }
 0938                catch (JsonException ex)
 939                {
 0940                    _httpRequest.Dispose();
 0941                    if (_httpResponse != null)
 942                    {
 0943                        _httpResponse.Dispose();
 944                    }
 0945                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 946                }
 947            }
 948            // Deserialize Response
 2949            if ((int)_statusCode == 400)
 950            {
 0951                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 952                try
 953                {
 0954                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseContent, Cl
 0955                }
 0956                catch (JsonException ex)
 957                {
 0958                    _httpRequest.Dispose();
 0959                    if (_httpResponse != null)
 960                    {
 0961                        _httpResponse.Dispose();
 962                    }
 0963                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 964                }
 965            }
 966            // Deserialize Response
 2967            if ((int)_statusCode == 401)
 968            {
 0969                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 970                try
 971                {
 0972                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<string>(_responseContent, Client
 0973                }
 0974                catch (JsonException ex)
 975                {
 0976                    _httpRequest.Dispose();
 0977                    if (_httpResponse != null)
 978                    {
 0979                        _httpResponse.Dispose();
 980                    }
 0981                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 982                }
 983            }
 2984            if (_shouldTrace)
 985            {
 0986                ServiceClientTracing.Exit(_invocationId, _result);
 987            }
 2988            return _result;
 2989        }
 990
 991    }
 992}