private void UpdateDownstreamHostAndPorts(OcelotRouteDto input, OcelotRoute route)
        {
            if (input.DownstreamHostAndPorts == null)
            {
                route.RemoveAllDownstreamHostAndPorts();
                return;
            }

            foreach (var host in input.DownstreamHostAndPorts)
            {
                var existing = route.FindDownstreamHostAndPort(host.Host, host.Port.Value);
                if (existing == null)
                {
                    route.AddDownstreamHostAndPort(host.Host, host.Port.Value);
                }
            }

            //TODO Copied with ToList to avoid modification of the collection in the for loop
            foreach (var host in route.DownstreamHostAndPorts.ToList())
            {
                if (!input.DownstreamHostAndPorts.Any(c => host.Equals(route.GlobalConfigurationId, route.Name, c.Host, c.Port.Value)))
                {
                    route.RemoveDownstreamHostAndPort(host.Host, host.Port);
                }
            }
        }
        private void UpdateUpstreamHttpMethods(OcelotRouteDto input, OcelotRoute route)
        {
            if (input.UpstreamHttpMethods == null)
            {
                route.RemoveAllUpstreamHttpMethods();
                return;
            }

            foreach (var method in input.UpstreamHttpMethods)
            {
                var existing = route.FindUpstreamHttpMethod(method);
                if (existing == null)
                {
                    route.AddUpstreamHttpMethod(method);
                }
            }

            //TODO Copied with ToList to avoid modification of the collection in the for loop
            foreach (var method in route.UpstreamHttpMethods.ToList())
            {
                if (!input.UpstreamHttpMethods.Any(c => method.Equals(route.GlobalConfigurationId, route.Name, c)))
                {
                    route.RemoveUpstreamHttpMethod(method.Method);
                }
            }
        }
        private void UpdateDelegatingHandlers(OcelotRouteDto input, OcelotRoute route)
        {
            if (input.DelegatingHandlers == null)
            {
                input.DelegatingHandlers = null;
                return;
            }

            foreach (var delegating in input.DelegatingHandlers)
            {
                var existing = route.FindDelegatingHandler(delegating);
                if (existing == null)
                {
                    route.AddDelegatingHandler(delegating);
                }
            }

            //TODO Copied with ToList to avoid modification of the collection in the for loop
            foreach (var delegating in route.DelegatingHandlers.ToList())
            {
                if (!input.DelegatingHandlers.Any(c => delegating.Equals(route.GlobalConfigurationId, route.Name, c)))
                {
                    route.RemoveDelegatingHandlers(delegating.Delegating);
                }
            }
        }
Esempio n. 4
0
        public List <string> Resolve(OcelotRoute source, OcelotRouteDto destination, List <string> destMember, ResolutionContext context)
        {
            if (source == null || source.DelegatingHandlers == null)
            {
                return(null);
            }

            return(source.DelegatingHandlers.Select(c => c.Delegating).ToList());
        }
Esempio n. 5
0
        public List <string> Resolve(OcelotRoute source, OcelotRouteDto destination, List <string> destMember, ResolutionContext context)
        {
            if (source == null || source.UpstreamHttpMethods == null)
            {
                return(null);
            }

            return(source.UpstreamHttpMethods.Select(c => c.Method).ToList());
        }
Esempio n. 6
0
        public List <RouteDelegatingHandler> Resolve(OcelotRouteDto source, OcelotRoute destination, List <RouteDelegatingHandler> destMember, ResolutionContext context)
        {
            if (source == null || source.DelegatingHandlers == null)
            {
                return(null);
            }
            foreach (var item in source.DelegatingHandlers)
            {
                destination.AddDelegatingHandler(item);
            }

            return(destination.DelegatingHandlers);
        }
Esempio n. 7
0
        public List <RouteDownstreamHostAndPort> Resolve(OcelotRouteDto source, OcelotRoute destination, List <RouteDownstreamHostAndPort> destMember, ResolutionContext context)
        {
            if (source == null || source.DownstreamHostAndPorts == null)
            {
                return(null);
            }

            foreach (var item in source.DownstreamHostAndPorts)
            {
                destination.AddDownstreamHostAndPort(item.Host, item.Port.Value);
            }

            return(destination.DownstreamHostAndPorts);
        }
Esempio n. 8
0
        public List <RouteUpstreamHttpMethod> Resolve(OcelotRouteDto source, OcelotRoute destination, List <RouteUpstreamHttpMethod> destMember, ResolutionContext context)
        {
            if (source == null || source.UpstreamHttpMethods == null)
            {
                return(null);
            }

            foreach (var item in source.UpstreamHttpMethods)
            {
                destination.AddUpstreamHttpMethod(item);
            }

            return(destination.UpstreamHttpMethods);
        }
        private void UpdateSecurityOption(OcelotRouteDto input, OcelotRoute route)
        {
            if (input.SecurityOption == null)
            {
                route.SecurityOption = null;
                return;
            }

            if (route.SecurityOption == null)
            {
                route.SecurityOption = new RouteSecurityOption(route.GlobalConfigurationId, route.Name);
            }

            UpdateSecurityOptionIPBlocked(input.SecurityOption, route.SecurityOption);
            UpdateSecurityOptionIPAllowed(input.SecurityOption, route.SecurityOption);
        }
Esempio n. 10
0
        public List <RouteDownstreamHostAndPortDto> Resolve(OcelotRoute source, OcelotRouteDto destination, List <RouteDownstreamHostAndPortDto> destMember, ResolutionContext context)
        {
            if (source == null || source.DownstreamHostAndPorts == null)
            {
                return(null);
            }

            List <RouteDownstreamHostAndPortDto> dto = new List <RouteDownstreamHostAndPortDto>();

            foreach (var item in source.DownstreamHostAndPorts)
            {
                dto.Add(new RouteDownstreamHostAndPortDto {
                    Host = item.Host, Port = item.Port
                });
            }

            return(dto);
        }