private ApplicationGatewaySslCertificate CreateSslCertificate(string sslCertName, string password) { X509Certificate2 cert = new X509Certificate2("ApplicationGatewayCertificate\\GW5000.pfx", password, X509KeyStorageFlags.Exportable); ApplicationGatewaySslCertificate sslCert = new ApplicationGatewaySslCertificate() { Name = sslCertName, Data = Convert.ToBase64String(cert.Export(X509ContentType.Pfx, password)), Password = password }; return(sslCert); }
internal static ApplicationGatewayData DeserializeApplicationGatewayData(JsonElement element) { Optional <string> etag = default; Optional <IList <string> > zones = default; Optional <ResourceIdentity> identity = default; Optional <string> id = default; Optional <string> name = default; Optional <string> type = default; Optional <string> location = default; Optional <IDictionary <string, string> > tags = default; Optional <ApplicationGatewaySku> sku = default; Optional <ApplicationGatewaySslPolicy> sslPolicy = default; Optional <ApplicationGatewayOperationalState> operationalState = default; Optional <IList <ApplicationGatewayIPConfiguration> > gatewayIPConfigurations = default; Optional <IList <ApplicationGatewayAuthenticationCertificate> > authenticationCertificates = default; Optional <IList <ApplicationGatewayTrustedRootCertificate> > trustedRootCertificates = default; Optional <IList <ApplicationGatewayTrustedClientCertificate> > trustedClientCertificates = default; Optional <IList <ApplicationGatewaySslCertificate> > sslCertificates = default; Optional <IList <ApplicationGatewayFrontendIPConfiguration> > frontendIPConfigurations = default; Optional <IList <ApplicationGatewayFrontendPort> > frontendPorts = default; Optional <IList <ApplicationGatewayProbe> > probes = default; Optional <IList <ApplicationGatewayBackendAddressPool> > backendAddressPools = default; Optional <IList <ApplicationGatewayBackendHttpSettings> > backendHttpSettingsCollection = default; Optional <IList <ApplicationGatewayHttpListener> > httpListeners = default; Optional <IList <ApplicationGatewaySslProfile> > sslProfiles = default; Optional <IList <ApplicationGatewayUrlPathMap> > urlPathMaps = default; Optional <IList <ApplicationGatewayRequestRoutingRule> > requestRoutingRules = default; Optional <IList <ApplicationGatewayRewriteRuleSet> > rewriteRuleSets = default; Optional <IList <ApplicationGatewayRedirectConfiguration> > redirectConfigurations = default; Optional <ApplicationGatewayWebApplicationFirewallConfiguration> webApplicationFirewallConfiguration = default; Optional <WritableSubResource> firewallPolicy = default; Optional <bool> enableHttp2 = default; Optional <bool> enableFips = default; Optional <ApplicationGatewayAutoscaleConfiguration> autoscaleConfiguration = default; Optional <IList <ApplicationGatewayPrivateLinkConfiguration> > privateLinkConfigurations = default; Optional <IReadOnlyList <ApplicationGatewayPrivateEndpointConnectionData> > privateEndpointConnections = default; Optional <string> resourceGuid = default; Optional <ProvisioningState> provisioningState = default; Optional <IList <ApplicationGatewayCustomError> > customErrorConfigurations = default; Optional <bool> forceFirewallPolicyAssociation = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("etag")) { etag = property.Value.GetString(); continue; } if (property.NameEquals("zones")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } List <string> array = new List <string>(); foreach (var item in property.Value.EnumerateArray()) { array.Add(item.GetString()); } zones = array; continue; } if (property.NameEquals("identity")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } identity = JsonSerializer.Deserialize <ResourceIdentity>(property.Value.ToString()); continue; } if (property.NameEquals("id")) { id = property.Value.GetString(); continue; } if (property.NameEquals("name")) { name = property.Value.GetString(); continue; } if (property.NameEquals("type")) { type = property.Value.GetString(); continue; } if (property.NameEquals("location")) { location = property.Value.GetString(); continue; } if (property.NameEquals("tags")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } Dictionary <string, string> dictionary = new Dictionary <string, string>(); foreach (var property0 in property.Value.EnumerateObject()) { dictionary.Add(property0.Name, property0.Value.GetString()); } tags = dictionary; continue; } if (property.NameEquals("properties")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } foreach (var property0 in property.Value.EnumerateObject()) { if (property0.NameEquals("sku")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } sku = ApplicationGatewaySku.DeserializeApplicationGatewaySku(property0.Value); continue; } if (property0.NameEquals("sslPolicy")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } sslPolicy = ApplicationGatewaySslPolicy.DeserializeApplicationGatewaySslPolicy(property0.Value); continue; } if (property0.NameEquals("operationalState")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } operationalState = new ApplicationGatewayOperationalState(property0.Value.GetString()); continue; } if (property0.NameEquals("gatewayIPConfigurations")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } List <ApplicationGatewayIPConfiguration> array = new List <ApplicationGatewayIPConfiguration>(); foreach (var item in property0.Value.EnumerateArray()) { array.Add(ApplicationGatewayIPConfiguration.DeserializeApplicationGatewayIPConfiguration(item)); } gatewayIPConfigurations = array; continue; } if (property0.NameEquals("authenticationCertificates")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } List <ApplicationGatewayAuthenticationCertificate> array = new List <ApplicationGatewayAuthenticationCertificate>(); foreach (var item in property0.Value.EnumerateArray()) { array.Add(ApplicationGatewayAuthenticationCertificate.DeserializeApplicationGatewayAuthenticationCertificate(item)); } authenticationCertificates = array; continue; } if (property0.NameEquals("trustedRootCertificates")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } List <ApplicationGatewayTrustedRootCertificate> array = new List <ApplicationGatewayTrustedRootCertificate>(); foreach (var item in property0.Value.EnumerateArray()) { array.Add(ApplicationGatewayTrustedRootCertificate.DeserializeApplicationGatewayTrustedRootCertificate(item)); } trustedRootCertificates = array; continue; } if (property0.NameEquals("trustedClientCertificates")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } List <ApplicationGatewayTrustedClientCertificate> array = new List <ApplicationGatewayTrustedClientCertificate>(); foreach (var item in property0.Value.EnumerateArray()) { array.Add(ApplicationGatewayTrustedClientCertificate.DeserializeApplicationGatewayTrustedClientCertificate(item)); } trustedClientCertificates = array; continue; } if (property0.NameEquals("sslCertificates")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } List <ApplicationGatewaySslCertificate> array = new List <ApplicationGatewaySslCertificate>(); foreach (var item in property0.Value.EnumerateArray()) { array.Add(ApplicationGatewaySslCertificate.DeserializeApplicationGatewaySslCertificate(item)); } sslCertificates = array; continue; } if (property0.NameEquals("frontendIPConfigurations")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } List <ApplicationGatewayFrontendIPConfiguration> array = new List <ApplicationGatewayFrontendIPConfiguration>(); foreach (var item in property0.Value.EnumerateArray()) { array.Add(ApplicationGatewayFrontendIPConfiguration.DeserializeApplicationGatewayFrontendIPConfiguration(item)); } frontendIPConfigurations = array; continue; } if (property0.NameEquals("frontendPorts")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } List <ApplicationGatewayFrontendPort> array = new List <ApplicationGatewayFrontendPort>(); foreach (var item in property0.Value.EnumerateArray()) { array.Add(ApplicationGatewayFrontendPort.DeserializeApplicationGatewayFrontendPort(item)); } frontendPorts = array; continue; } if (property0.NameEquals("probes")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } List <ApplicationGatewayProbe> array = new List <ApplicationGatewayProbe>(); foreach (var item in property0.Value.EnumerateArray()) { array.Add(ApplicationGatewayProbe.DeserializeApplicationGatewayProbe(item)); } probes = array; continue; } if (property0.NameEquals("backendAddressPools")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } List <ApplicationGatewayBackendAddressPool> array = new List <ApplicationGatewayBackendAddressPool>(); foreach (var item in property0.Value.EnumerateArray()) { array.Add(ApplicationGatewayBackendAddressPool.DeserializeApplicationGatewayBackendAddressPool(item)); } backendAddressPools = array; continue; } if (property0.NameEquals("backendHttpSettingsCollection")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } List <ApplicationGatewayBackendHttpSettings> array = new List <ApplicationGatewayBackendHttpSettings>(); foreach (var item in property0.Value.EnumerateArray()) { array.Add(ApplicationGatewayBackendHttpSettings.DeserializeApplicationGatewayBackendHttpSettings(item)); } backendHttpSettingsCollection = array; continue; } if (property0.NameEquals("httpListeners")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } List <ApplicationGatewayHttpListener> array = new List <ApplicationGatewayHttpListener>(); foreach (var item in property0.Value.EnumerateArray()) { array.Add(ApplicationGatewayHttpListener.DeserializeApplicationGatewayHttpListener(item)); } httpListeners = array; continue; } if (property0.NameEquals("sslProfiles")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } List <ApplicationGatewaySslProfile> array = new List <ApplicationGatewaySslProfile>(); foreach (var item in property0.Value.EnumerateArray()) { array.Add(ApplicationGatewaySslProfile.DeserializeApplicationGatewaySslProfile(item)); } sslProfiles = array; continue; } if (property0.NameEquals("urlPathMaps")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } List <ApplicationGatewayUrlPathMap> array = new List <ApplicationGatewayUrlPathMap>(); foreach (var item in property0.Value.EnumerateArray()) { array.Add(ApplicationGatewayUrlPathMap.DeserializeApplicationGatewayUrlPathMap(item)); } urlPathMaps = array; continue; } if (property0.NameEquals("requestRoutingRules")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } List <ApplicationGatewayRequestRoutingRule> array = new List <ApplicationGatewayRequestRoutingRule>(); foreach (var item in property0.Value.EnumerateArray()) { array.Add(ApplicationGatewayRequestRoutingRule.DeserializeApplicationGatewayRequestRoutingRule(item)); } requestRoutingRules = array; continue; } if (property0.NameEquals("rewriteRuleSets")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } List <ApplicationGatewayRewriteRuleSet> array = new List <ApplicationGatewayRewriteRuleSet>(); foreach (var item in property0.Value.EnumerateArray()) { array.Add(ApplicationGatewayRewriteRuleSet.DeserializeApplicationGatewayRewriteRuleSet(item)); } rewriteRuleSets = array; continue; } if (property0.NameEquals("redirectConfigurations")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } List <ApplicationGatewayRedirectConfiguration> array = new List <ApplicationGatewayRedirectConfiguration>(); foreach (var item in property0.Value.EnumerateArray()) { array.Add(ApplicationGatewayRedirectConfiguration.DeserializeApplicationGatewayRedirectConfiguration(item)); } redirectConfigurations = array; continue; } if (property0.NameEquals("webApplicationFirewallConfiguration")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } webApplicationFirewallConfiguration = ApplicationGatewayWebApplicationFirewallConfiguration.DeserializeApplicationGatewayWebApplicationFirewallConfiguration(property0.Value); continue; } if (property0.NameEquals("firewallPolicy")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } firewallPolicy = JsonSerializer.Deserialize <WritableSubResource>(property0.Value.ToString()); continue; } if (property0.NameEquals("enableHttp2")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } enableHttp2 = property0.Value.GetBoolean(); continue; } if (property0.NameEquals("enableFips")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } enableFips = property0.Value.GetBoolean(); continue; } if (property0.NameEquals("autoscaleConfiguration")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } autoscaleConfiguration = ApplicationGatewayAutoscaleConfiguration.DeserializeApplicationGatewayAutoscaleConfiguration(property0.Value); continue; } if (property0.NameEquals("privateLinkConfigurations")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } List <ApplicationGatewayPrivateLinkConfiguration> array = new List <ApplicationGatewayPrivateLinkConfiguration>(); foreach (var item in property0.Value.EnumerateArray()) { array.Add(ApplicationGatewayPrivateLinkConfiguration.DeserializeApplicationGatewayPrivateLinkConfiguration(item)); } privateLinkConfigurations = array; continue; } if (property0.NameEquals("privateEndpointConnections")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } List <ApplicationGatewayPrivateEndpointConnectionData> array = new List <ApplicationGatewayPrivateEndpointConnectionData>(); foreach (var item in property0.Value.EnumerateArray()) { array.Add(ApplicationGatewayPrivateEndpointConnectionData.DeserializeApplicationGatewayPrivateEndpointConnectionData(item)); } privateEndpointConnections = array; continue; } if (property0.NameEquals("resourceGuid")) { resourceGuid = property0.Value.GetString(); continue; } if (property0.NameEquals("provisioningState")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } provisioningState = new ProvisioningState(property0.Value.GetString()); continue; } if (property0.NameEquals("customErrorConfigurations")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } List <ApplicationGatewayCustomError> array = new List <ApplicationGatewayCustomError>(); foreach (var item in property0.Value.EnumerateArray()) { array.Add(ApplicationGatewayCustomError.DeserializeApplicationGatewayCustomError(item)); } customErrorConfigurations = array; continue; } if (property0.NameEquals("forceFirewallPolicyAssociation")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } forceFirewallPolicyAssociation = property0.Value.GetBoolean(); continue; } } continue; } } return(new ApplicationGatewayData(id.Value, name.Value, type.Value, location.Value, Optional.ToDictionary(tags), etag.Value, Optional.ToList(zones), identity, sku.Value, sslPolicy.Value, Optional.ToNullable(operationalState), Optional.ToList(gatewayIPConfigurations), Optional.ToList(authenticationCertificates), Optional.ToList(trustedRootCertificates), Optional.ToList(trustedClientCertificates), Optional.ToList(sslCertificates), Optional.ToList(frontendIPConfigurations), Optional.ToList(frontendPorts), Optional.ToList(probes), Optional.ToList(backendAddressPools), Optional.ToList(backendHttpSettingsCollection), Optional.ToList(httpListeners), Optional.ToList(sslProfiles), Optional.ToList(urlPathMaps), Optional.ToList(requestRoutingRules), Optional.ToList(rewriteRuleSets), Optional.ToList(redirectConfigurations), webApplicationFirewallConfiguration.Value, firewallPolicy, Optional.ToNullable(enableHttp2), Optional.ToNullable(enableFips), autoscaleConfiguration.Value, Optional.ToList(privateLinkConfigurations), Optional.ToList(privateEndpointConnections), resourceGuid.Value, Optional.ToNullable(provisioningState), Optional.ToList(customErrorConfigurations), Optional.ToNullable(forceFirewallPolicyAssociation))); }
private ApplicationGateway CreateApplicationGatewayWithSsl(string location, Subnet subnet, string resourceGroupName, string subscriptionId) { var appGwName = TestUtilities.GenerateName(); var gatewayIPConfigName = TestUtilities.GenerateName(); var frontendIPConfigName = TestUtilities.GenerateName(); var frontendPortName = TestUtilities.GenerateName(); var backendAddressPoolName = TestUtilities.GenerateName(); var backendHttpSettingsName = TestUtilities.GenerateName(); var requestRoutingRuleName = TestUtilities.GenerateName(); var sslCertName = TestUtilities.GenerateName(); var httpListenerName = TestUtilities.GenerateName(); var password = "******"; ApplicationGatewaySslCertificate sslCert = CreateSslCertificate(sslCertName, password); var appGw = new ApplicationGateway() { Location = location, Name = appGwName, Sku = new ApplicationGatewaySku() { Name = ApplicationGatewaySkuName.StandardLarge, Tier = ApplicationGatewayTier.Standard, Capacity = 2 }, GatewayIPConfigurations = new List <ApplicationGatewayIPConfiguration>() { new ApplicationGatewayIPConfiguration() { Name = gatewayIPConfigName, Subnet = new ResourceId() { Id = subnet.Id } } }, SslCertificates = new List <ApplicationGatewaySslCertificate>() { sslCert }, FrontendIPConfigurations = new List <ApplicationGatewayFrontendIPConfiguration>() { new ApplicationGatewayFrontendIPConfiguration() { Name = frontendIPConfigName, PrivateIPAllocationMethod = IpAllocationMethod.Dynamic, Subnet = new ResourceId() { Id = subnet.Id } } }, FrontendPorts = new List <ApplicationGatewayFrontendPort> { new ApplicationGatewayFrontendPort() { Name = frontendPortName, Port = 443 } }, BackendAddressPools = new List <ApplicationGatewayBackendAddressPool> { new ApplicationGatewayBackendAddressPool() { Name = backendAddressPoolName, BackendAddresses = new List <ApplicationGatewayBackendAddress>() { new ApplicationGatewayBackendAddress() { IpAddress = "10.2.0.1" }, new ApplicationGatewayBackendAddress() { IpAddress = "10.2.0.2" } } } }, BackendHttpSettingsCollection = new List <ApplicationGatewayBackendHttpSettings> { new ApplicationGatewayBackendHttpSettings() { Name = backendHttpSettingsName, Port = 80, Protocol = ApplicationGatewayProtocol.Http, CookieBasedAffinity = ApplicationGatewayCookieBasedAffinity.Enabled } }, HttpListeners = new List <ApplicationGatewayHttpListener> { new ApplicationGatewayHttpListener() { Name = httpListenerName, FrontendPort = new ResourceId() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "frontendPorts", frontendPortName) }, FrontendIPConfiguration = new ResourceId() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "frontendIPConfigurations", frontendIPConfigName) }, SslCertificate = new ResourceId() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "sslCertificates", sslCertName) }, Protocol = ApplicationGatewayProtocol.Https } }, RequestRoutingRules = new List <ApplicationGatewayRequestRoutingRule>() { new ApplicationGatewayRequestRoutingRule() { Name = requestRoutingRuleName, RuleType = ApplicationGatewayRequestRoutingRuleType.Basic, HttpListener = new ResourceId() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "httpListeners", httpListenerName) }, BackendAddressPool = new ResourceId() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "backendAddressPools", backendAddressPoolName) }, BackendHttpSettings = new ResourceId() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "backendHttpSettingsCollection", backendHttpSettingsName) } } } }; return(appGw); }