/// <summary>
 /// Update the specified secret
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.KeyVault.Internal.ISecretOperations.
 /// </param>
 /// <param name='secretIdentifier'>
 /// Required.
 /// </param>
 /// <param name='request'>
 /// Required.
 /// </param>
 /// <returns>
 /// Represents the response to a secret operation request.
 /// </returns>
 public static Task<SecretResponseMessageWithRawJsonContent> UpdateAsync(this ISecretOperations operations, string secretIdentifier, SecretRequestMessageWithRawJsonContent request)
 {
     return operations.UpdateAsync(secretIdentifier, request, CancellationToken.None);
 }
 /// <summary>
 /// Update the specified secret
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.KeyVault.Internal.ISecretOperations.
 /// </param>
 /// <param name='secretIdentifier'>
 /// Required.
 /// </param>
 /// <param name='request'>
 /// Required.
 /// </param>
 /// <returns>
 /// Represents the response to a secret operation request.
 /// </returns>
 public static SecretResponseMessageWithRawJsonContent Update(this ISecretOperations operations, string secretIdentifier, SecretRequestMessageWithRawJsonContent request)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((ISecretOperations)s).UpdateAsync(secretIdentifier, request);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }
Esempio n. 3
0
 /// <summary>
 /// Update the specified secret
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.KeyVault.Internal.ISecretOperations.
 /// </param>
 /// <param name='secretIdentifier'>
 /// Required.
 /// </param>
 /// <param name='request'>
 /// Required.
 /// </param>
 /// <returns>
 /// Represents the response to a secret operation request.
 /// </returns>
 public static SecretResponseMessageWithRawJsonContent Update(this ISecretOperations operations, string secretIdentifier, SecretRequestMessageWithRawJsonContent request)
 {
     return(Task.Factory.StartNew((object s) =>
     {
         return ((ISecretOperations)s).UpdateAsync(secretIdentifier, request);
     }
                                  , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }
Esempio n. 4
0
 /// <summary>
 /// Update the specified secret
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.KeyVault.Internal.ISecretOperations.
 /// </param>
 /// <param name='secretIdentifier'>
 /// Required.
 /// </param>
 /// <param name='request'>
 /// Required.
 /// </param>
 /// <returns>
 /// Represents the response to a secret operation request.
 /// </returns>
 public static Task <SecretResponseMessageWithRawJsonContent> UpdateAsync(this ISecretOperations operations, string secretIdentifier, SecretRequestMessageWithRawJsonContent request)
 {
     return(operations.UpdateAsync(secretIdentifier, request, CancellationToken.None));
 }
        /// <summary>
        /// Update the specified secret
        /// </summary>
        /// <param name='secretIdentifier'>
        /// Required.
        /// </param>
        /// <param name='request'>
        /// Required.
        /// </param>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </param>
        /// <returns>
        /// Represents the response to a secret operation request.
        /// </returns>
        public async Task <SecretResponseMessageWithRawJsonContent> UpdateAsync(string secretIdentifier, SecretRequestMessageWithRawJsonContent request, CancellationToken cancellationToken)
        {
            // Validate
            if (secretIdentifier == null)
            {
                throw new ArgumentNullException("secretIdentifier");
            }
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            // Tracing
            bool   shouldTrace  = TracingAdapter.IsEnabled;
            string invocationId = null;

            if (shouldTrace)
            {
                invocationId = TracingAdapter.NextInvocationId.ToString();
                Dictionary <string, object> tracingParameters = new Dictionary <string, object>();
                tracingParameters.Add("secretIdentifier", secretIdentifier);
                tracingParameters.Add("request", request);
                TracingAdapter.Enter(invocationId, this, "UpdateAsync", tracingParameters);
            }

            // Construct URL
            string url = "";

            url = url + secretIdentifier;
            List <string> queryParameters = new List <string>();

            queryParameters.Add("api-version=2015-02-01-preview");
            if (queryParameters.Count > 0)
            {
                url = url + "?" + string.Join("&", queryParameters);
            }
            url = url.Replace(" ", "%20");

            // Create HTTP transport objects
            HttpRequestMessage httpRequest = null;

            try
            {
                httpRequest            = new HttpRequestMessage();
                httpRequest.Method     = new HttpMethod("PATCH");
                httpRequest.RequestUri = new Uri(url);

                // Set Headers
                httpRequest.Headers.Add("Accept", "application/json");
                httpRequest.Headers.Add("client-request-id", Guid.NewGuid().ToString());

                // Set Credentials
                cancellationToken.ThrowIfCancellationRequested();
                await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);

                // Serialize Request
                string requestContent = request.RawJsonRequest;
                httpRequest.Content = new StringContent(requestContent, Encoding.UTF8);
                httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");

                // Send Request
                HttpResponseMessage httpResponse = null;
                try
                {
                    if (shouldTrace)
                    {
                        TracingAdapter.SendRequest(invocationId, httpRequest);
                    }
                    cancellationToken.ThrowIfCancellationRequested();
                    httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);

                    if (shouldTrace)
                    {
                        TracingAdapter.ReceiveResponse(invocationId, httpResponse);
                    }
                    HttpStatusCode statusCode = httpResponse.StatusCode;
                    if (statusCode >= HttpStatusCode.BadRequest)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        CloudException ex = CloudException.Create(httpRequest, requestContent, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
                        if (shouldTrace)
                        {
                            TracingAdapter.Error(invocationId, ex);
                        }
                        throw ex;
                    }

                    // Create Result
                    SecretResponseMessageWithRawJsonContent result = null;
                    // Deserialize Response
                    cancellationToken.ThrowIfCancellationRequested();
                    string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);

                    result          = new SecretResponseMessageWithRawJsonContent();
                    result.Response = responseContent;

                    result.StatusCode = statusCode;

                    if (shouldTrace)
                    {
                        TracingAdapter.Exit(invocationId, result);
                    }
                    return(result);
                }
                finally
                {
                    if (httpResponse != null)
                    {
                        httpResponse.Dispose();
                    }
                }
            }
            finally
            {
                if (httpRequest != null)
                {
                    httpRequest.Dispose();
                }
            }
        }