mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-04-23 00:32:50 +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:
parent
ab1988b155
commit
b707cd6175
@ -34,7 +34,16 @@
|
||||
{
|
||||
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
|
||||
{
|
||||
@ -45,11 +54,11 @@
|
||||
return services.ToList();
|
||||
}
|
||||
|
||||
private Service BuildService(ServiceEntry serviceEntry)
|
||||
private Service BuildService(ServiceEntry serviceEntry, Node serviceNode)
|
||||
{
|
||||
return new 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,
|
||||
GetVersionFromStrings(serviceEntry.Service.Tags),
|
||||
serviceEntry.Service.Tags ?? Enumerable.Empty<string>());
|
||||
|
Loading…
x
Reference in New Issue
Block a user