mirror of
				https://github.com/nsnail/Ocelot.git
				synced 2025-11-04 09:35:27 +08:00 
			
		
		
		
	Updated Consul discovery to resolve hostname (#909)
* Updated Consul discovery to resolve target API location to hostname if known Consul node, to allow SSL API certificate validation * Handling added for null response from Consul client when querying nodes
This commit is contained in:
		
				
					committed by
					
						
						Thiago Loureiro
					
				
			
			
				
	
			
			
			
						parent
						
							ab1988b155
						
					
				
				
					commit
					b707cd6175
				
			@@ -34,7 +34,16 @@
 | 
				
			|||||||
            {
 | 
					            {
 | 
				
			||||||
                if (IsValid(serviceEntry))
 | 
					                if (IsValid(serviceEntry))
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    services.Add(BuildService(serviceEntry));
 | 
					                    var nodes = await _consul.Catalog.Nodes();
 | 
				
			||||||
 | 
					                    if (nodes.Response == null)
 | 
				
			||||||
 | 
					                    {
 | 
				
			||||||
 | 
					                        services.Add(BuildService(serviceEntry, null));
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                    else
 | 
				
			||||||
 | 
					                    {
 | 
				
			||||||
 | 
					                        var serviceNode = nodes.Response.FirstOrDefault(n => n.Address == serviceEntry.Service.Address);
 | 
				
			||||||
 | 
					                        services.Add(BuildService(serviceEntry, serviceNode));
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                else
 | 
					                else
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
@@ -45,11 +54,11 @@
 | 
				
			|||||||
            return services.ToList();
 | 
					            return services.ToList();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        private Service BuildService(ServiceEntry serviceEntry)
 | 
					        private Service BuildService(ServiceEntry serviceEntry, Node serviceNode)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            return new Service(
 | 
					            return new Service(
 | 
				
			||||||
                serviceEntry.Service.Service,
 | 
					                serviceEntry.Service.Service,
 | 
				
			||||||
                new ServiceHostAndPort(serviceEntry.Service.Address, serviceEntry.Service.Port),
 | 
					                new ServiceHostAndPort(serviceNode == null ? serviceEntry.Service.Address : serviceNode.Name, serviceEntry.Service.Port),
 | 
				
			||||||
                serviceEntry.Service.ID,
 | 
					                serviceEntry.Service.ID,
 | 
				
			||||||
                GetVersionFromStrings(serviceEntry.Service.Tags),
 | 
					                GetVersionFromStrings(serviceEntry.Service.Tags),
 | 
				
			||||||
                serviceEntry.Service.Tags ?? Enumerable.Empty<string>());
 | 
					                serviceEntry.Service.Tags ?? Enumerable.Empty<string>());
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user