/// <summary>
 /// Serializes the object to JSON.
 /// </summary>
 /// <param name="writer">The <see cref="T: Newtonsoft.Json.JsonWriter" /> to write to.</param>
 /// <param name="obj">The object to serialize to JSON.</param>
 internal static void Serialize(JsonWriter writer, SecretResourceDescription obj)
 {
     // Required properties are always serialized, optional properties are serialized when not null.
     writer.WriteStartObject();
     writer.WriteProperty(obj.Properties, "properties", SecretResourcePropertiesConverter.Serialize);
     writer.WriteProperty(obj.Name, "name", JsonWriterExtensions.WriteStringValue);
     writer.WriteEndObject();
 }
示例#2
0
        /// <summary>
        /// Overloaded ToString function for formatting the output on the console.
        /// </summary>
        /// <param name="secretResourceDescription"> Object of type SecretResourceDescription </param>
        /// <returns>
        /// Returns formatted string.
        /// </returns>
        public static string ToString(SecretResourceDescription secretResourceDescription)
        {
            var strBuilder = new StringBuilder();

            strBuilder.Append(string.Format(CultureInfo.CurrentCulture, "{0} : {1}", "Name", secretResourceDescription.Name));
            strBuilder.Append(Environment.NewLine);
            strBuilder.Append(string.Format(CultureInfo.CurrentCulture, "{0} : {1}", "Description", secretResourceDescription.Properties.Description));
            strBuilder.Append(Environment.NewLine);
            strBuilder.Append(string.Format(CultureInfo.CurrentCulture, "{0} : {1}", "Status", secretResourceDescription.Properties.Status));
            strBuilder.Append(Environment.NewLine);
            strBuilder.Append(string.Format(CultureInfo.CurrentCulture, "{0} : {1}", "ContentType", secretResourceDescription.Properties.ContentType));
            strBuilder.Append(Environment.NewLine);

            return(strBuilder.ToString());
        }
        /// <inheritdoc />
        public Task <SecretResourceDescription> CreateOrUpdateAsync(
            string secretResourceName,
            SecretResourceDescription secretResourceDescription,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            secretResourceName.ThrowIfNull(nameof(secretResourceName));
            secretResourceDescription.ThrowIfNull(nameof(secretResourceDescription));
            var requestId = Guid.NewGuid().ToString();
            var url       = "Resources/Secrets/{secretResourceName}";

            url = url.Replace("{secretResourceName}", secretResourceName);
            var queryParams = new List <string>();

            // Append to queryParams if not null.
            queryParams.Add("api-version=6.4-preview");
            url += "?" + string.Join("&", queryParams);

            string content;

            using (var sw = new StringWriter())
            {
                SecretResourceDescriptionConverter.Serialize(new JsonTextWriter(sw), secretResourceDescription);
                content = sw.ToString();
            }

            HttpRequestMessage RequestFunc()
            {
                var request = new HttpRequestMessage()
                {
                    Method  = HttpMethod.Put,
                    Content = new StringContent(content, Encoding.UTF8),
                };

                request.Content.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
                return(request);
            }

            return(this.httpClient.SendAsyncGetResponse(RequestFunc, url, SecretResourceDescriptionConverter.Deserialize, requestId, cancellationToken));
        }
 /// <summary>
 /// Creates or updates a secret resource.
 /// </summary>
 /// <remarks>
 /// Creates a secret resource with the specified name, description and
 /// properties. If a secret resource with the same name exists, then it is
 /// updated with the specified description and properties.
 /// </remarks>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Azure resource group name
 /// </param>
 /// <param name='secretResourceName'>
 /// The name of the secret resource.
 /// </param>
 /// <param name='secretResourceDescription'>
 /// Description for creating a secret resource.
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <SecretResourceDescription> CreateAsync(this ISecretOperations operations, string resourceGroupName, string secretResourceName, SecretResourceDescription secretResourceDescription, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.CreateWithHttpMessagesAsync(resourceGroupName, secretResourceName, secretResourceDescription, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
 /// <summary>
 /// Creates or updates a secret resource.
 /// </summary>
 /// <remarks>
 /// Creates a secret resource with the specified name, description and
 /// properties. If a secret resource with the same name exists, then it is
 /// updated with the specified description and properties.
 /// </remarks>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Azure resource group name
 /// </param>
 /// <param name='secretResourceName'>
 /// The name of the secret resource.
 /// </param>
 /// <param name='secretResourceDescription'>
 /// Description for creating a secret resource.
 /// </param>
 public static SecretResourceDescription Create(this ISecretOperations operations, string resourceGroupName, string secretResourceName, SecretResourceDescription secretResourceDescription)
 {
     return(operations.CreateAsync(resourceGroupName, secretResourceName, secretResourceDescription).GetAwaiter().GetResult());
 }