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:
Paul Arnett 2019-06-01 07:22:33 -04:00 committed by Thiago Loureiro
parent ab1988b155
commit b707cd6175

View File

@ -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>());