| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | // <auto-generated/> |
| | 5 | |
|
| | 6 | | #nullable disable |
| | 7 | |
|
| | 8 | | using System.Collections.Generic; |
| | 9 | | using System.Text.Json; |
| | 10 | | using Azure.Core; |
| | 11 | |
|
| | 12 | | namespace Azure.ResourceManager.Network.Models |
| | 13 | | { |
| | 14 | | public partial class NetworkRuleCondition : IUtf8JsonSerializable |
| | 15 | | { |
| | 16 | | void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) |
| | 17 | | { |
| 0 | 18 | | writer.WriteStartObject(); |
| 0 | 19 | | if (IpProtocols != null) |
| | 20 | | { |
| 0 | 21 | | writer.WritePropertyName("ipProtocols"); |
| 0 | 22 | | writer.WriteStartArray(); |
| 0 | 23 | | foreach (var item in IpProtocols) |
| | 24 | | { |
| 0 | 25 | | writer.WriteStringValue(item.ToString()); |
| | 26 | | } |
| 0 | 27 | | writer.WriteEndArray(); |
| | 28 | | } |
| 0 | 29 | | if (SourceAddresses != null) |
| | 30 | | { |
| 0 | 31 | | writer.WritePropertyName("sourceAddresses"); |
| 0 | 32 | | writer.WriteStartArray(); |
| 0 | 33 | | foreach (var item in SourceAddresses) |
| | 34 | | { |
| 0 | 35 | | writer.WriteStringValue(item); |
| | 36 | | } |
| 0 | 37 | | writer.WriteEndArray(); |
| | 38 | | } |
| 0 | 39 | | if (DestinationAddresses != null) |
| | 40 | | { |
| 0 | 41 | | writer.WritePropertyName("destinationAddresses"); |
| 0 | 42 | | writer.WriteStartArray(); |
| 0 | 43 | | foreach (var item in DestinationAddresses) |
| | 44 | | { |
| 0 | 45 | | writer.WriteStringValue(item); |
| | 46 | | } |
| 0 | 47 | | writer.WriteEndArray(); |
| | 48 | | } |
| 0 | 49 | | if (DestinationPorts != null) |
| | 50 | | { |
| 0 | 51 | | writer.WritePropertyName("destinationPorts"); |
| 0 | 52 | | writer.WriteStartArray(); |
| 0 | 53 | | foreach (var item in DestinationPorts) |
| | 54 | | { |
| 0 | 55 | | writer.WriteStringValue(item); |
| | 56 | | } |
| 0 | 57 | | writer.WriteEndArray(); |
| | 58 | | } |
| 0 | 59 | | if (SourceIpGroups != null) |
| | 60 | | { |
| 0 | 61 | | writer.WritePropertyName("sourceIpGroups"); |
| 0 | 62 | | writer.WriteStartArray(); |
| 0 | 63 | | foreach (var item in SourceIpGroups) |
| | 64 | | { |
| 0 | 65 | | writer.WriteStringValue(item); |
| | 66 | | } |
| 0 | 67 | | writer.WriteEndArray(); |
| | 68 | | } |
| 0 | 69 | | if (DestinationIpGroups != null) |
| | 70 | | { |
| 0 | 71 | | writer.WritePropertyName("destinationIpGroups"); |
| 0 | 72 | | writer.WriteStartArray(); |
| 0 | 73 | | foreach (var item in DestinationIpGroups) |
| | 74 | | { |
| 0 | 75 | | writer.WriteStringValue(item); |
| | 76 | | } |
| 0 | 77 | | writer.WriteEndArray(); |
| | 78 | | } |
| 0 | 79 | | if (Name != null) |
| | 80 | | { |
| 0 | 81 | | writer.WritePropertyName("name"); |
| 0 | 82 | | writer.WriteStringValue(Name); |
| | 83 | | } |
| 0 | 84 | | if (Description != null) |
| | 85 | | { |
| 0 | 86 | | writer.WritePropertyName("description"); |
| 0 | 87 | | writer.WriteStringValue(Description); |
| | 88 | | } |
| 0 | 89 | | writer.WritePropertyName("ruleConditionType"); |
| 0 | 90 | | writer.WriteStringValue(RuleConditionType.ToString()); |
| 0 | 91 | | writer.WriteEndObject(); |
| 0 | 92 | | } |
| | 93 | |
|
| | 94 | | internal static NetworkRuleCondition DeserializeNetworkRuleCondition(JsonElement element) |
| | 95 | | { |
| 0 | 96 | | IList<FirewallPolicyRuleConditionNetworkProtocol> ipProtocols = default; |
| 0 | 97 | | IList<string> sourceAddresses = default; |
| 0 | 98 | | IList<string> destinationAddresses = default; |
| 0 | 99 | | IList<string> destinationPorts = default; |
| 0 | 100 | | IList<string> sourceIpGroups = default; |
| 0 | 101 | | IList<string> destinationIpGroups = default; |
| 0 | 102 | | string name = default; |
| 0 | 103 | | string description = default; |
| 0 | 104 | | FirewallPolicyRuleConditionType ruleConditionType = default; |
| 0 | 105 | | foreach (var property in element.EnumerateObject()) |
| | 106 | | { |
| 0 | 107 | | if (property.NameEquals("ipProtocols")) |
| | 108 | | { |
| 0 | 109 | | if (property.Value.ValueKind == JsonValueKind.Null) |
| | 110 | | { |
| | 111 | | continue; |
| | 112 | | } |
| 0 | 113 | | List<FirewallPolicyRuleConditionNetworkProtocol> array = new List<FirewallPolicyRuleConditionNetwork |
| 0 | 114 | | foreach (var item in property.Value.EnumerateArray()) |
| | 115 | | { |
| 0 | 116 | | array.Add(new FirewallPolicyRuleConditionNetworkProtocol(item.GetString())); |
| | 117 | | } |
| 0 | 118 | | ipProtocols = array; |
| 0 | 119 | | continue; |
| | 120 | | } |
| 0 | 121 | | if (property.NameEquals("sourceAddresses")) |
| | 122 | | { |
| 0 | 123 | | if (property.Value.ValueKind == JsonValueKind.Null) |
| | 124 | | { |
| | 125 | | continue; |
| | 126 | | } |
| 0 | 127 | | List<string> array = new List<string>(); |
| 0 | 128 | | foreach (var item in property.Value.EnumerateArray()) |
| | 129 | | { |
| 0 | 130 | | if (item.ValueKind == JsonValueKind.Null) |
| | 131 | | { |
| 0 | 132 | | array.Add(null); |
| | 133 | | } |
| | 134 | | else |
| | 135 | | { |
| 0 | 136 | | array.Add(item.GetString()); |
| | 137 | | } |
| | 138 | | } |
| 0 | 139 | | sourceAddresses = array; |
| 0 | 140 | | continue; |
| | 141 | | } |
| 0 | 142 | | if (property.NameEquals("destinationAddresses")) |
| | 143 | | { |
| 0 | 144 | | if (property.Value.ValueKind == JsonValueKind.Null) |
| | 145 | | { |
| | 146 | | continue; |
| | 147 | | } |
| 0 | 148 | | List<string> array = new List<string>(); |
| 0 | 149 | | foreach (var item in property.Value.EnumerateArray()) |
| | 150 | | { |
| 0 | 151 | | if (item.ValueKind == JsonValueKind.Null) |
| | 152 | | { |
| 0 | 153 | | array.Add(null); |
| | 154 | | } |
| | 155 | | else |
| | 156 | | { |
| 0 | 157 | | array.Add(item.GetString()); |
| | 158 | | } |
| | 159 | | } |
| 0 | 160 | | destinationAddresses = array; |
| 0 | 161 | | continue; |
| | 162 | | } |
| 0 | 163 | | if (property.NameEquals("destinationPorts")) |
| | 164 | | { |
| 0 | 165 | | if (property.Value.ValueKind == JsonValueKind.Null) |
| | 166 | | { |
| | 167 | | continue; |
| | 168 | | } |
| 0 | 169 | | List<string> array = new List<string>(); |
| 0 | 170 | | foreach (var item in property.Value.EnumerateArray()) |
| | 171 | | { |
| 0 | 172 | | if (item.ValueKind == JsonValueKind.Null) |
| | 173 | | { |
| 0 | 174 | | array.Add(null); |
| | 175 | | } |
| | 176 | | else |
| | 177 | | { |
| 0 | 178 | | array.Add(item.GetString()); |
| | 179 | | } |
| | 180 | | } |
| 0 | 181 | | destinationPorts = array; |
| 0 | 182 | | continue; |
| | 183 | | } |
| 0 | 184 | | if (property.NameEquals("sourceIpGroups")) |
| | 185 | | { |
| 0 | 186 | | if (property.Value.ValueKind == JsonValueKind.Null) |
| | 187 | | { |
| | 188 | | continue; |
| | 189 | | } |
| 0 | 190 | | List<string> array = new List<string>(); |
| 0 | 191 | | foreach (var item in property.Value.EnumerateArray()) |
| | 192 | | { |
| 0 | 193 | | if (item.ValueKind == JsonValueKind.Null) |
| | 194 | | { |
| 0 | 195 | | array.Add(null); |
| | 196 | | } |
| | 197 | | else |
| | 198 | | { |
| 0 | 199 | | array.Add(item.GetString()); |
| | 200 | | } |
| | 201 | | } |
| 0 | 202 | | sourceIpGroups = array; |
| 0 | 203 | | continue; |
| | 204 | | } |
| 0 | 205 | | if (property.NameEquals("destinationIpGroups")) |
| | 206 | | { |
| 0 | 207 | | if (property.Value.ValueKind == JsonValueKind.Null) |
| | 208 | | { |
| | 209 | | continue; |
| | 210 | | } |
| 0 | 211 | | List<string> array = new List<string>(); |
| 0 | 212 | | foreach (var item in property.Value.EnumerateArray()) |
| | 213 | | { |
| 0 | 214 | | if (item.ValueKind == JsonValueKind.Null) |
| | 215 | | { |
| 0 | 216 | | array.Add(null); |
| | 217 | | } |
| | 218 | | else |
| | 219 | | { |
| 0 | 220 | | array.Add(item.GetString()); |
| | 221 | | } |
| | 222 | | } |
| 0 | 223 | | destinationIpGroups = array; |
| 0 | 224 | | continue; |
| | 225 | | } |
| 0 | 226 | | if (property.NameEquals("name")) |
| | 227 | | { |
| 0 | 228 | | if (property.Value.ValueKind == JsonValueKind.Null) |
| | 229 | | { |
| | 230 | | continue; |
| | 231 | | } |
| 0 | 232 | | name = property.Value.GetString(); |
| 0 | 233 | | continue; |
| | 234 | | } |
| 0 | 235 | | if (property.NameEquals("description")) |
| | 236 | | { |
| 0 | 237 | | if (property.Value.ValueKind == JsonValueKind.Null) |
| | 238 | | { |
| | 239 | | continue; |
| | 240 | | } |
| 0 | 241 | | description = property.Value.GetString(); |
| 0 | 242 | | continue; |
| | 243 | | } |
| 0 | 244 | | if (property.NameEquals("ruleConditionType")) |
| | 245 | | { |
| 0 | 246 | | ruleConditionType = new FirewallPolicyRuleConditionType(property.Value.GetString()); |
| | 247 | | continue; |
| | 248 | | } |
| | 249 | | } |
| 0 | 250 | | return new NetworkRuleCondition(name, description, ruleConditionType, ipProtocols, sourceAddresses, destinat |
| | 251 | | } |
| | 252 | | } |
| | 253 | | } |