Ejemplo n.º 1
0
        public override IApplicationGateway UpdateResource(IApplicationGateway resource)
        {
            int rulesCount = resource.RequestRoutingRules.Count;

            resource.Update()
            .WithSize(ApplicationGatewaySkuName.StandardSmall)
            .WithInstanceCount(1)
            .UpdateListener("listener1")
            .WithHostName("www.contoso.com")
            .Parent()
            .UpdateRequestRoutingRule("rule443")
            .FromListener("listener1")
            .Parent()
            .WithoutRequestRoutingRule("rule9000")
            .WithoutProbe("probe1")
            .WithoutDisabledSslProtocols(ApplicationGatewaySslProtocol.TlsV1_0, ApplicationGatewaySslProtocol.TlsV1_1)
            .WithTag("tag1", "value1")
            .WithTag("tag2", "value2")
            .Apply();

            resource.Refresh();

            // Get the resource created so far
            Assert.True(resource.Tags.ContainsKey("tag1"));
            Assert.Equal(resource.Size, ApplicationGatewaySkuName.StandardSmall);
            Assert.Equal(1, resource.InstanceCount);

            // Verify listeners
            IApplicationGatewayListener listener = resource.Listeners["listener1"];

            Assert.Equal("www.contoso.com", listener.HostName);

            // Verify request routing rules
            Assert.Equal(resource.RequestRoutingRules.Count, rulesCount - 1);
            Assert.True(!resource.RequestRoutingRules.ContainsKey("rule9000"));
            IApplicationGatewayRequestRoutingRule rule = resource.RequestRoutingRules["rule443"];

            Assert.NotNull(rule);
            Assert.Equal("listener1", rule.Listener.Name);

            // Verify probes
            Assert.Equal(0, resource.Probes.Count);

            // Verify backend configs
            Assert.Null(resource.BackendHttpConfigurations["config1"].Probe);

            // Verify SSL policy - disabled protocols
            Assert.Equal(0, resource.DisabledSslProtocols.Count);

            return(resource);
        }
Ejemplo n.º 2
0
        ///GENMHASH:691BBD1A543FA3E8C9A27D451AEF177E:9467BB08B825C61781DD6029C8047DFB
        public IReadOnlyDictionary <string, IApplicationGatewayRequestRoutingRule> RequestRoutingRules()
        {
            Dictionary <string, IApplicationGatewayRequestRoutingRule> rules = new Dictionary <string, IApplicationGatewayRequestRoutingRule>();

            if (null != Inner.RequestRoutingRules)
            {
                foreach (var ruleRef in Inner.RequestRoutingRules)
                {
                    string ruleName = ResourceUtils.NameFromResourceId(ruleRef.Id);
                    IApplicationGatewayRequestRoutingRule rule = null;
                    if (Parent.RequestRoutingRules().TryGetValue(ruleName, out rule))
                    {
                        rules[ruleName] = rule;
                    }
                }
            }
            return(rules);
        }
Ejemplo n.º 3
0
        public override IApplicationGateway UpdateResource(IApplicationGateway resource)
        {
            int portCount     = resource.FrontendPorts.Count;
            int frontendCount = resource.Frontends.Count;
            int listenerCount = resource.Listeners.Count;
            int ruleCount     = resource.RequestRoutingRules.Count;
            int backendCount  = resource.Backends.Count;
            int configCount   = resource.BackendHttpConfigurations.Count;
            int sslCertCount  = resource.SslCertificates.Count;
            int authCertCount = resource.AuthenticationCertificates.Count;
            var authCert1     = resource.BackendHttpConfigurations["config1"].AuthenticationCertificates.Values.FirstOrDefault();

            Assert.NotNull(authCert1);

            var pip         = resource.Manager.PublicIPAddresses.GetByResourceGroup(applicationGatewayHelper.GroupName, applicationGatewayHelper.PipNames[0]);
            var listener443 = resource.RequestRoutingRules["rule443"].Listener;

            Assert.NotNull(listener443);
            var listenerRedirect = resource.RequestRoutingRules["ruleRedirect"].Listener;

            Assert.NotNull(listenerRedirect);

            resource.Update()
            .WithSize(ApplicationGatewaySkuName.StandardSmall)
            .WithInstanceCount(1)
            .WithoutFrontendPort(9000)
            .WithoutListener("listener1")
            .WithoutBackendIPAddress("11.1.1.4")
            .WithoutBackendHttpConfiguration("config2")
            .WithoutBackend("backend2")
            .WithoutRequestRoutingRule("rule9000")
            .WithoutSslCertificate("cert1")
            .WithoutAuthenticationCertificate(authCert1.Name)

            .UpdateListener(listener443.Name)
            .WithHostName("foobar")
            .Parent()
            .UpdateListener(listenerRedirect.Name)
            .WithHttp()
            .Parent()

            .UpdateBackendHttpConfiguration("config1")
            .WithPort(8082)
            .WithCookieBasedAffinity()
            .WithRequestTimeout(20)
            .WithAuthenticationCertificate("auth2")
            .Parent()

            .UpdateBackend("backend1")
            .WithoutIPAddress("11.1.1.3")
            .WithIPAddress("11.1.1.5")
            .Parent()

            .UpdateRequestRoutingRule("rule80")
            .ToBackend("backend1")
            .ToBackendHttpConfiguration("config1")
            .Parent()
            .UpdateRequestRoutingRule("rule443")
            .WithoutRedirectConfiguration()
            .Parent()

            .UpdateRedirectConfiguration("redirect1")
            .WithTargetUrl("http://azure.com")
            .WithType(ApplicationGatewayRedirectType.Found)
            .WithQueryStringIncluded()
            .WithoutPathIncluded()
            .Parent()
            .WithoutRedirectConfiguration("redirect2")

            .WithExistingPublicIPAddress(testPips[0])     // Associate with a public IP as well
            .WithTag("tag1", "value1")
            .WithTag("tag2", "value2")
            .Apply();

            resource.Refresh();

            // Get the resource created so far
            Assert.True(resource.Tags.ContainsKey("tag1"));
            Assert.True(resource.Tags.ContainsKey("tag2"));
            Assert.Equal(ApplicationGatewaySkuName.StandardSmall, resource.Size);
            Assert.Equal(1, resource.InstanceCount);

            // Verify redirect configurations
            Assert.Single(resource.RedirectConfigurations);
            var redirect = resource.RedirectConfigurations["redirect1"];

            Assert.NotNull(redirect);
            Assert.Equal(ApplicationGatewayRedirectType.Found, redirect.Type);
            Assert.Null(redirect.TargetListener);
            Assert.NotNull(redirect.TargetUrl);
            Assert.Equal("http://azure.com", redirect.TargetUrl);

            // Verify frontend ports
            Assert.Equal(portCount - 1, resource.FrontendPorts.Count);
            Assert.Null(resource.FrontendPortNameFromNumber(9000));

            // Verify frontends
            Assert.Equal(frontendCount + 1, resource.Frontends.Count);
            Assert.Single(resource.PublicFrontends);
            Assert.Equal(pip.Id, resource.PublicFrontends.Values.FirstOrDefault().PublicIPAddressId, true);
            Assert.Single(resource.PrivateFrontends);
            IApplicationGatewayFrontend frontend = resource.PrivateFrontends.Values.FirstOrDefault();

            Assert.NotNull(frontend);
            Assert.False(frontend.IsPublic);
            Assert.True(frontend.IsPrivate);

            // Verify listeners
            Assert.Equal(listenerCount - 1, resource.Listeners.Count);
            Assert.DoesNotContain("listener1", resource.Listeners.Keys);

            // Verify backends
            Assert.Equal(backendCount - 1, resource.Backends.Count);
            Assert.DoesNotContain("backend2", resource.Backends.Keys);
            IApplicationGatewayBackend backend = resource.Backends["backend1"];

            Assert.NotNull(backend);
            Assert.Equal(1, backend.Addresses.Count);
            Assert.True(backend.ContainsIPAddress("11.1.1.5"));
            Assert.False(backend.ContainsIPAddress("11.1.1.3"));
            Assert.False(backend.ContainsIPAddress("11.1.1.4"));

            // Verify HTTP configs
            Assert.Equal(configCount - 1, resource.BackendHttpConfigurations.Count);
            Assert.False(resource.BackendHttpConfigurations.ContainsKey("config2"));
            IApplicationGatewayBackendHttpConfiguration config = resource.BackendHttpConfigurations["config1"];

            Assert.Equal(8082, config.Port);
            Assert.Equal(20, config.RequestTimeout);
            Assert.True(config.CookieBasedAffinity);
            Assert.Single(config.AuthenticationCertificates);
            Assert.DoesNotContain(authCert1.Name, config.AuthenticationCertificates.Keys);
            Assert.Contains("auth2", config.AuthenticationCertificates.Keys);

            // Verify rules
            Assert.Equal(ruleCount - 1, resource.RequestRoutingRules.Count);
            Assert.False(resource.RequestRoutingRules.ContainsKey("rule9000"));

            IApplicationGatewayRequestRoutingRule rule = resource.RequestRoutingRules["rule80"];

            Assert.NotNull(rule);
            Assert.NotNull(rule.Backend);
            Assert.Equal("backend1", rule.Backend.Name);
            Assert.NotNull(rule.BackendHttpConfiguration);
            Assert.Equal("config1", rule.BackendHttpConfiguration.Name, true);

            rule = resource.RequestRoutingRules["rule443"];
            Assert.NotNull(rule);
            Assert.NotNull(rule.Listener);
            Assert.Equal("foobar", rule.Listener.HostName);
            Assert.Null(rule.RedirectConfiguration);

            // Verify SSL certificates
            Assert.Equal(sslCertCount - 1, resource.SslCertificates.Count);
            Assert.False(resource.SslCertificates.ContainsKey("cert1"));

            // Verify authentication certificates
            Assert.Equal(authCertCount - 1, resource.AuthenticationCertificates.Count);
            Assert.DoesNotContain("auth1", resource.AuthenticationCertificates.Keys);

            return(resource);
        }
Ejemplo n.º 4
0
        public override IApplicationGateway UpdateResource(IApplicationGateway resource)
        {
            int rulesCount = resource.RequestRoutingRules.Count;

            Assert.Contains("rule80", resource.RequestRoutingRules.Keys);
            var rule80          = resource.RequestRoutingRules["rule80"];
            var backendConfig80 = rule80.BackendHttpConfiguration;

            Assert.NotNull(backendConfig80);

            resource.Update()
            .WithSize(ApplicationGatewaySkuName.StandardSmall)
            .WithInstanceCount(1)
            .UpdateListener("listener1")
            .WithHostName("www.contoso.com")
            .Parent()
            .UpdateRequestRoutingRule("rule443")
            .FromListener("listener1")
            .Parent()
            .UpdateBackendHttpConfiguration("config1")
            .WithoutHostHeader()
            .WithoutConnectionDraining()
            .WithAffinityCookieName(null)
            .WithPath(null)
            .Parent()
            .UpdateBackendHttpConfiguration(backendConfig80.Name)
            .WithHostHeaderFromBackend()
            .Parent()
            .WithoutRequestRoutingRule("rule9000")
            .WithoutProbe("probe1")
            .UpdateProbe("probe2")
            .WithoutHealthyHttpResponseStatusCodeRanges()
            .WithHealthyHttpResponseBodyContents(null)
            .Parent()
            .WithoutDisabledSslProtocols(ApplicationGatewaySslProtocol.TlsV1_0, ApplicationGatewaySslProtocol.TlsV1_1)
            .WithTag("tag1", "value1")
            .WithTag("tag2", "value2")
            .Apply();

            resource.Refresh();

            // Get the resource created so far
            Assert.True(resource.Tags.ContainsKey("tag1"));
            Assert.Equal(resource.Size, ApplicationGatewaySkuName.StandardSmall);
            Assert.Equal(1, resource.InstanceCount);

            // Verify listeners
            IApplicationGatewayListener listener = resource.Listeners["listener1"];

            Assert.Equal("www.contoso.com", listener.HostName, true);

            // Verify request routing rules
            Assert.Equal(resource.RequestRoutingRules.Count, rulesCount - 1);
            Assert.DoesNotContain("rule9000", resource.RequestRoutingRules.Keys);
            IApplicationGatewayRequestRoutingRule rule = resource.RequestRoutingRules["rule443"];

            Assert.NotNull(rule);
            Assert.Equal("listener1", rule.Listener.Name, true);

            // Verify probes
            Assert.Single(resource.Probes);
            var probe = resource.Probes["probe2"];

            Assert.NotNull(probe);
            Assert.Empty(probe.HealthyHttpResponseStatusCodeRanges);
            Assert.Null(probe.HealthyHttpResponseBodyContents);

            // Verify backend configs
            var backendConfig = resource.BackendHttpConfigurations["config1"];

            Assert.NotNull(backendConfig);
            Assert.Null(backendConfig.Probe);
            Assert.False(backendConfig.IsHostHeaderFromBackend);
            Assert.Null(backendConfig.HostHeader);
            Assert.Equal(0, backendConfig.ConnectionDrainingTimeoutInSeconds);
            Assert.Null(backendConfig.AffinityCookieName);
            Assert.Null(backendConfig.Path);

            rule80 = resource.RequestRoutingRules["rule80"];
            Assert.NotNull(rule80);
            backendConfig80 = rule80.BackendHttpConfiguration;
            Assert.NotNull(backendConfig80);
            Assert.True(backendConfig80.IsHostHeaderFromBackend);
            Assert.Null(backendConfig80.HostHeader);

            // Verify SSL policy - disabled protocols
            Assert.Equal(0, resource.DisabledSslProtocols.Count);

            return(resource);
        }
        public override IApplicationGateway UpdateResource(IApplicationGateway resource)
        {
            resource.Update()
            .WithInstanceCount(2)
            .WithSize(ApplicationGatewaySkuName.StandardMedium)
            .WithFrontendPort(81, "port81")             // Add a new port
            .WithoutBackendIPAddress("11.1.1.1")        // Remove from all existing backends
            .DefineSslCertificate("testSSL")
            .WithPfxFromFile(new FileInfo(Path.Combine("Assets", "myTest._pfx")))
            .WithPfxPassword("Abc123")
            .Attach()
            .DefineListener("listener2")
            .WithPrivateFrontend()
            .WithFrontendPort(81)
            .WithHttps()
            .WithSslCertificate("testSSL")
            .Attach()
            .DefineBackend("backend2")
            .WithIPAddress("11.1.1.3")
            .Attach()
            .DefineBackendHttpConfiguration("config2")
            .WithCookieBasedAffinity()
            .WithPort(8081)
            .WithRequestTimeout(33)
            .Attach()
            .DefineRequestRoutingRule("rule2")
            .FromListener("listener2")
            .ToBackendHttpConfiguration("config2")
            .ToBackend("backend2")
            .Attach()
            .WithTag("tag1", "value1")
            .WithTag("tag2", "value2")
            .Apply();

            resource.Refresh();

            Assert.True(resource.Tags.ContainsKey("tag1"));
            Assert.True(resource.Tags.ContainsKey("tag2"));
            Assert.Equal(ApplicationGatewaySkuName.StandardMedium, resource.Size);
            Assert.Equal(2, resource.InstanceCount);

            // Verify frontend ports
            Assert.Equal(2, resource.FrontendPorts.Count);
            Assert.True(resource.FrontendPorts.ContainsKey("port81"));
            Assert.Equal("port81", resource.FrontendPortNameFromNumber(81));

            // Verify listeners
            Assert.Equal(2, resource.Listeners.Count);
            IApplicationGatewayListener listener = resource.Listeners["listener2"];

            Assert.NotNull(listener);
            Assert.True(listener.Frontend.IsPrivate);
            Assert.True(!listener.Frontend.IsPublic);
            Assert.Equal("port81", listener.FrontendPortName);
            Assert.Equal(ApplicationGatewayProtocol.Https, listener.Protocol);
            Assert.NotNull(listener.SslCertificate);

            // Verify backends
            Assert.Equal(2, resource.Backends.Count);
            IApplicationGatewayBackend backend = resource.Backends["backend2"];

            Assert.NotNull(backend);
            Assert.Single(backend.Addresses);
            Assert.True(backend.ContainsIPAddress("11.1.1.3"));

            // Verify HTTP configs
            Assert.Equal(2, resource.BackendHttpConfigurations.Count);
            IApplicationGatewayBackendHttpConfiguration config = resource.BackendHttpConfigurations["config2"];

            Assert.NotNull(config);
            Assert.True(config.CookieBasedAffinity);
            Assert.Equal(8081, config.Port);
            Assert.Equal(33, config.RequestTimeout);

            // Verify request routing rules
            Assert.Equal(2, resource.RequestRoutingRules.Count);
            IApplicationGatewayRequestRoutingRule rule = resource.RequestRoutingRules["rule2"];

            Assert.NotNull(rule);
            Assert.NotNull(rule.Listener);
            Assert.Equal("listener2", rule.Listener.Name);
            Assert.NotNull(rule.BackendHttpConfiguration);
            Assert.Equal("config2", rule.BackendHttpConfiguration.Name);
            Assert.NotNull(rule.Backend);
            Assert.Equal("backend2", rule.Backend.Name);

            return(resource);
        }
        public override IApplicationGateway UpdateResource(IApplicationGateway resource)
        {
            int portCount     = resource.FrontendPorts.Count;
            int frontendCount = resource.Frontends.Count;
            int listenerCount = resource.Listeners.Count;
            int ruleCount     = resource.RequestRoutingRules.Count;
            int backendCount  = resource.Backends.Count;
            int configCount   = resource.BackendHttpConfigurations.Count;
            int certCount     = resource.SslCertificates.Count;

            resource.Update()
            .WithSize(ApplicationGatewaySkuName.StandardSmall)
            .WithInstanceCount(1)
            .WithoutFrontendPort(9000)
            .WithoutListener("listener1")
            .WithoutBackendIPAddress("11.1.1.4")
            .WithoutBackendHttpConfiguration("config2")
            .WithoutBackend("backend2")
            .WithoutRequestRoutingRule("rule9000")
            .WithoutCertificate("cert1")
            .UpdateListener(resource.RequestRoutingRules["rule443"].Listener.Name)
            .WithHostName("foobar")
            .Parent()
            .UpdateBackendHttpConfiguration("config1")
            .WithPort(8082)
            .WithCookieBasedAffinity()
            .WithRequestTimeout(20)
            .Parent()
            .UpdateBackend("backend1")
            .WithoutIPAddress("11.1.1.3")
            .WithIPAddress("11.1.1.5")
            .Parent()
            .UpdateRequestRoutingRule("rule80")
            .ToBackend("backend1")
            .ToBackendHttpConfiguration("config1")
            .Parent()
            .WithExistingPublicIPAddress(testPips[0])     // Associate with a public IP as well
            .WithTag("tag1", "value1")
            .WithTag("tag2", "value2")
            .Apply();

            resource.Refresh();

            // Get the resource created so far
            Assert.True(resource.Tags.ContainsKey("tag1"));
            Assert.True(resource.Tags.ContainsKey("tag2"));
            Assert.Equal(ApplicationGatewaySkuName.StandardSmall, resource.Size);
            Assert.Equal(resource.InstanceCount, 1);

            // Verify frontend ports
            Assert.Equal(resource.FrontendPorts.Count, portCount - 1);
            Assert.Null(resource.FrontendPortNameFromNumber(9000));

            // Verify frontends
            Assert.Equal(resource.Frontends.Count, frontendCount + 1);
            Assert.Equal(resource.PublicFrontends.Count, 1);
            Assert.Equal(resource.PrivateFrontends.Count, 1);
            IApplicationGatewayFrontend frontend = resource.PrivateFrontends.Values.First();

            Assert.True(!frontend.IsPublic);
            Assert.True(frontend.IsPrivate);

            // Verify listeners
            Assert.Equal(resource.Listeners.Count, listenerCount - 1);
            Assert.True(!resource.Listeners.ContainsKey("listener1"));

            // Verify backends
            Assert.Equal(resource.Backends.Count, backendCount - 1);
            Assert.True(!resource.Backends.ContainsKey("backend2"));
            IApplicationGatewayBackend backend = resource.Backends["backend1"];

            Assert.NotNull(backend);
            Assert.Equal(backend.Addresses.Count, 1);
            Assert.True(backend.ContainsIPAddress("11.1.1.5"));
            Assert.True(!backend.ContainsIPAddress("11.1.1.3"));
            Assert.True(!backend.ContainsIPAddress("11.1.1.4"));

            // Verify HTTP configs
            Assert.Equal(resource.BackendHttpConfigurations.Count, configCount - 1);
            Assert.True(!resource.BackendHttpConfigurations.ContainsKey("config2"));
            IApplicationGatewayBackendHttpConfiguration config = resource.BackendHttpConfigurations["config1"];

            Assert.Equal(config.Port, 8082);
            Assert.Equal(config.RequestTimeout, 20);
            Assert.True(config.CookieBasedAffinity);

            // Verify rules
            Assert.Equal(resource.RequestRoutingRules.Count, ruleCount - 1);
            Assert.True(!resource.RequestRoutingRules.ContainsKey("rule9000"));

            IApplicationGatewayRequestRoutingRule rule = resource.RequestRoutingRules["rule80"];

            Assert.NotNull(rule);
            Assert.NotNull(rule.Backend);
            Assert.Equal("backend1", rule.Backend.Name);
            Assert.NotNull(rule.BackendHttpConfiguration);
            Assert.Equal("config1", rule.BackendHttpConfiguration.Name);

            rule = resource.RequestRoutingRules["rule443"];
            Assert.NotNull(rule);
            Assert.NotNull(rule.Listener);
            Assert.Equal("foobar", rule.Listener.HostName);

            // Verify certificates
            Assert.Equal(resource.SslCertificates.Count, certCount - 1);
            Assert.True(!resource.SslCertificates.ContainsKey("cert1"));

            // Test stop/start
            resource.Stop();
            Assert.Equal(ApplicationGatewayOperationalState.Stopped, resource.OperationalState);
            resource.Start();
            Assert.Equal(ApplicationGatewayOperationalState.Running, resource.OperationalState);
            return(resource);
        }