| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | using System.Collections.Generic; |
| | 5 | | using System.Text.Json; |
| | 6 | |
|
| | 7 | | namespace Azure.Security.KeyVault.Certificates |
| | 8 | | { |
| | 9 | | internal class CertificateCreateParameters : IJsonSerializable |
| | 10 | | { |
| | 11 | | private const string PolicyPropertyName = "policy"; |
| | 12 | | private const string AttributesPropertyName = "attributes"; |
| | 13 | | private const string EnabledPropertyName = "enabled"; |
| | 14 | | private const string TagsPropertyName = "tags"; |
| | 15 | |
|
| 2 | 16 | | private static readonly JsonEncodedText s_policyPropertyNameBytes = JsonEncodedText.Encode(PolicyPropertyName); |
| 2 | 17 | | private static readonly JsonEncodedText s_attributesPropertyNameBytes = JsonEncodedText.Encode(AttributesPropert |
| 2 | 18 | | private static readonly JsonEncodedText s_enabledPropertyNameBytes = JsonEncodedText.Encode(EnabledPropertyName) |
| 2 | 19 | | private static readonly JsonEncodedText s_tagsPropertyNameBytes = JsonEncodedText.Encode(TagsPropertyName); |
| | 20 | |
|
| 60 | 21 | | public CertificateCreateParameters(CertificatePolicy policy, bool? enabled, IDictionary<string, string> tags) |
| | 22 | | { |
| 60 | 23 | | Policy = policy; |
| 60 | 24 | | Enabled = enabled; |
| 60 | 25 | | Tags = tags; |
| 60 | 26 | | } |
| | 27 | |
|
| 120 | 28 | | public CertificatePolicy Policy { get; } |
| | 29 | |
|
| 60 | 30 | | public bool? Enabled { get; } |
| | 31 | |
|
| 60 | 32 | | public IDictionary<string, string> Tags { get; } |
| | 33 | |
|
| | 34 | | void IJsonSerializable.WriteProperties(Utf8JsonWriter json) |
| | 35 | | { |
| 60 | 36 | | if (Policy != null) |
| | 37 | | { |
| 60 | 38 | | json.WriteStartObject(s_policyPropertyNameBytes); |
| | 39 | |
|
| 60 | 40 | | ((IJsonSerializable)Policy).WriteProperties(json); |
| | 41 | |
|
| 60 | 42 | | json.WriteEndObject(); |
| | 43 | | } |
| | 44 | |
|
| 60 | 45 | | if (Enabled.HasValue) |
| | 46 | | { |
| 0 | 47 | | json.WriteStartObject(s_attributesPropertyNameBytes); |
| | 48 | |
|
| 0 | 49 | | json.WriteBoolean(s_enabledPropertyNameBytes, Enabled.Value); |
| | 50 | |
|
| 0 | 51 | | json.WriteEndObject(); |
| | 52 | | } |
| | 53 | |
|
| 60 | 54 | | if (!Tags.IsNullOrEmpty()) |
| | 55 | | { |
| 0 | 56 | | json.WriteStartObject(s_tagsPropertyNameBytes); |
| | 57 | |
|
| 0 | 58 | | foreach (KeyValuePair<string, string> kvp in Tags) |
| | 59 | | { |
| 0 | 60 | | json.WriteString(kvp.Key, kvp.Value); |
| | 61 | | } |
| | 62 | |
|
| 0 | 63 | | json.WriteEndObject(); |
| | 64 | | } |
| 60 | 65 | | } |
| | 66 | | } |
| | 67 | | } |